Skip to content

Commit

Permalink
Adding the ability to delete cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjeanson committed Aug 3, 2011
1 parent aaf4fb4 commit 1fa5695
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/cards_controller.rb
Expand Up @@ -26,4 +26,11 @@ def update
item = {card: card} if card.update_attributes(params[:card])
render_json(item, :error_code => :bad_request)
end

def destroy
project = Project.find(params[:project_id])
card = project.cards.find(params[:id])
item = {} if card.destroy
render_json(item, :error_code => :bad_request)
end
end
13 changes: 13 additions & 0 deletions features/cards.feature
Expand Up @@ -51,3 +51,16 @@ Feature: Cards API
| 1 | Find a Deputy | Get a Deputy for the Sheriff |
| 2 | Kill the Sheriff | Make the town kill the Sheriff |
| 3 | Take the town | Make everybody sell their houses |

Scenario: Deleting a card
Given I have the cards for project "1":
| id | title | description |
| 1 | Find a Sheriff | Get a Sheriff everybody will hate |
| 2 | Kill the Sheriff | Make the town kill the Sheriff |
| 3 | Take the town | Make everybody sell their houses |
When I delete card "3" for project "1"
And I call API "/projects/1/cards"
Then the response should be a collection of "cards" with:
| id | title | description |
| 1 | Find a Sheriff | Get a Sheriff everybody will hate |
| 2 | Kill the Sheriff | Make the town kill the Sheriff |
5 changes: 5 additions & 0 deletions features/step_definitions/card_steps.rb
Expand Up @@ -14,3 +14,8 @@
project = Project.create!(id: project_id, name: "Blazing Saddles", description: "Good movie")
put_resource "/projects/#{project_id}/cards/#{card_id}", 'card', table.hashes
end

When /^I delete card "([^"]*)" for project "([^"]*)"$/ do |card_id, project_id|
project = Project.create!(id: project_id, name: "Blazing Saddles", description: "Good movie")
delete_resource "/projects/#{project_id}/cards/#{card_id}"
end
4 changes: 4 additions & 0 deletions features/support/helpers.rb
Expand Up @@ -9,3 +9,7 @@ def put_resource(put_path, resource, hashes)
put put_path, :format => :json, resource => attributes
end
end

def delete_resource(delete_path)
delete delete_path, :format => :json
end
33 changes: 33 additions & 0 deletions spec/controllers/cards_controller_spec.rb
Expand Up @@ -118,4 +118,37 @@
end
end

describe '.delete' do
before do
Project.stub(:find).with(@project.id).and_return(@project)
@card = @cards.first
@project.stub_chain(:cards, :find).with(@card.id).and_return(@card)
end

context "card is deleted successfully" do
before do
@card.should_receive(:destroy).and_return(true)
delete :destroy, :format => :json, :project_id => @project.id, :id => 1
end

it { should respond_with(:success) }
it { should respond_with_content_type(:json) }
it { response.body.should be_json_eql({}) }
end

context "card is not deleted" do
before do
@card.should_receive(:destroy).and_return(false)
delete :destroy, :format => :json, :project_id => @project.id, :id => 1
end

it { should respond_with(:bad_request) }
it { should respond_with_content_type(:json) }
it { response.body.should be_json_eql(nil) }
end
end

describe 'when the project cannot be found' do
pending
end
end

0 comments on commit 1fa5695

Please sign in to comment.