Skip to content
Browse files

Add ability to destroy projects from the command line

`wally destroy <project_url>`

Closes #1
  • Loading branch information...
1 parent 4a93b0d commit 0ec33f48d946382e5bd164802a18ee086fd0c36d @AndrewVos AndrewVos committed Jul 9, 2012
View
27 README.md
@@ -9,25 +9,28 @@ The product owner or business analyst usually does not want to use an IDE or VCS
## What's wrong with Relish?
Many of the ideas have been borrowed from Matt Wynne's Relish product, but we;
-### Didn't want
+## Didn't want
* To sign-in
-### Wanted to
+## Wanted to
* Use it through mobile devices
-* Easily group features and scenarios by tags
+* Easily group features and scenarios by tags
* Count features and tags
* Include a project progress bar (based on tags)
-### Installation
+## Installation
* Install [mongodb](http://www.mongodb.org/display/DOCS/Quickstart "mongodb") and ensure it is running (e.g. '~ $ ./mongodb-xxxxx-xxxx-x.x.x/bin/mongod')
-* `gem install wally`
-* you might also want mongo_mapper (`gem install mongo_mapper`)
-
-### Usage
-* create a '.wally' file and enter any authentication text you like (`echo myPassword > .wally`)
-* run wally server, in the same dir that you put the .wally file (`wally server`)
-* check [http://localhost:4567/](http://localhost:4567/)
-* import your features (from local dir) `wally push http://localhost:4567/projects/<project-name> <feature-dir>`
+* ```gem install wally```
+* you might also want mongo_mapper (```gem install mongo_mapper```)
+
+## Usage
+* create a '.wally' file and enter any authentication text you like (```echo myPassword > .wally```)
+* run wally server, in the same dir that you put the .wally file (```wally server```)
+* check [http://localhost:4567/](http://localhost:4567/)
+* import your features (from local dir) ```wally push http://localhost:4567/projects/<project-name> <feature-dir>```
+
+## Deleting projects
+```wally destroy http://localhost:4567/projects/<project-name>```
## Wally?
View
3 bin/wally
@@ -20,4 +20,7 @@ elsif ARGV[0] == "push"
features << {:path => feature_path, :gherkin => gherkin}
end
RestClient.put "#{ARGV[1]}/features/?authentication_code=#{File.read(".wally")}", features.to_json, {:content_type => :json, :accept => :json}
+elsif ARGV[0] == "destroy"
+ require "restclient"
+ RestClient.delete ARGV[1]
end
View
14 features/push_features.feature
@@ -18,3 +18,17 @@ Feature: Push Features To Server
When I put data to /my_project_name/features with the authentication code
And I visit "my_project_name" page
Then I see the uploaded feature
+
+ Scenario: Delete projects without authorisation
+ Given I don't have a .wally authorisation file
+ And I create a project called "project1"
+ When I send DELETE to "/projects/project1"
+ Then "project1" should exist
+ And I get a 403 http status
+
+ Scenario: Delete projects with authorisation
+ Given I have a .wally authentication file
+ And I create a project called "project1"
+ When I send DELETE to "/projects/project1"
+ Then "project1" should not exist
+ And I get a 201 http status
View
1 features/step_definitions/projects_steps.rb
@@ -25,3 +25,4 @@
page.current_url.end_with?(project_number).should be_true
end
+
View
17 features/step_definitions/push_features_steps.rb
@@ -26,6 +26,23 @@
page.driver.put "/projects/my_project_name/features?authentication_code=#{@authentication_code}", data
end
+Given /^I create a project called "([^"]*)"$/ do |project_name|
+ project project_name
+ Wally::Project.first(:name => project_name).class.should equal Wally::Project
+end
+
+When /^I send DELETE to "([^"]*)"$/ do |project_path|
+ page.driver.delete "#{project_path}?authentication_code=#{@authentication_code}"
+end
+
+Then /^"([^"]*)" should exist$/ do |project_name|
+ Wally::Project.first(:name => project_name).class.should equal Wally::Project
+end
+
+Then /^"([^"]*)" should not exist$/ do |project_name|
+ Wally::Project.first(:name => project_name).class.should_not equal Wally::Project
+end
+
When /^I visit "([^"]*)" page$/ do |project_name|
visit "/projects/#{project_name}"
end
View
65 lib/wally/application.rb
@@ -62,19 +62,39 @@ def highlighted_search_result_blurb search_result
highlighted
end
-put '/projects/:project/features/?' do
- if File.exist?(".wally") && params[:authentication_code] == File.read(".wally").strip
- current_project.delete if current_project
- project = Wally::Project.create(:name => params[:project])
+def authenticated?
+ File.exist?(".wally") && params[:authentication_code] == File.read(".wally").strip
+end
+
+def get_scenario_url(scenario)
+ url = "/projects/#{current_project.name}/features/#{scenario["id"].gsub(";", "/scenario/")}"
+end
- JSON.parse(request.body.read).each do |json|
- project.features << Wally::Feature.new(:path => json["path"], :gherkin => json["gherkin"])
+def get_sorted_scenarios(feature)
+ scenarios = []
+
+ if feature.gherkin["elements"]
+ feature.gherkin["elements"].each do |element|
+ if element["type"] == "scenario" || element["type"] == "scenario_outline"
+ scenarios << element
+ end
end
- project.save
- halt 201
- else
- error 403
end
+ scenarios.sort! { |a, b| a["name"] <=> b["name"] }
+ scenarios
+end
+
+put '/projects/:project/features/?' do
+ error 403 unless authenticated?
+
+ current_project.delete if current_project
+ project = Wally::Project.create(:name => params[:project])
+
+ JSON.parse(request.body.read).each do |json|
+ project.features << Wally::Feature.new(:path => json["path"], :gherkin => json["gherkin"])
+ end
+ project.save
+ halt 201
end
get '/?' do
@@ -95,6 +115,13 @@ def highlighted_search_result_blurb search_result
haml :project
end
+delete '/projects/:project' do
+ error 403 unless authenticated?
+ project = Wally::Project.first(:name => params[:project])
+ project.destroy
+ halt 201
+end
+
get '/projects/:project/features/:feature/?' do
current_project.features.each do |feature|
@feature = feature if feature.gherkin["id"] == params[:feature]
@@ -129,21 +156,3 @@ def highlighted_search_result_blurb search_result
end
haml :scenario
end
-
-def get_scenario_url(scenario)
- url = "/projects/#{current_project.name}/features/#{scenario["id"].gsub(";", "/scenario/")}"
-end
-
-def get_sorted_scenarios(feature)
- scenarios = []
-
- if feature.gherkin["elements"]
- feature.gherkin["elements"].each do |element|
- if element["type"] == "scenario" || element["type"] == "scenario_outline"
- scenarios << element
- end
- end
- end
- scenarios.sort! { |a, b| a["name"] <=> b["name"] }
- scenarios
-end

0 comments on commit 0ec33f4

Please sign in to comment.
Something went wrong with that request. Please try again.