Skip to content

Commit

Permalink
Implement update action for projects API
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Aug 13, 2012
1 parent 836573d commit ce1d6a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/api/v1/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Api::V1::ProjectsController < Api::V1::BaseController
before_filter :find_project, :only => [:show]
before_filter :find_project, :only => [:show, :update]

def index
respond_with(Project.for(current_user).all)
Expand All @@ -18,6 +18,11 @@ def show
respond_with(@project, :methods => "last_ticket")
end

def update
@project.update_attributes(params[:project])
respond_with(@project)
end

private

def find_project
Expand Down
31 changes: 31 additions & 0 deletions spec/api/v1/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,35 @@
ticket_title.should_not be_blank
end
end

context "updating a project" do
before do
user.admin = true
user.save
end

let(:url) { "/api/v1/projects/#{project.id}" }
it "successful JSON" do
put "#{url}.json", :token => token,
:project => {
:name => "Not Ticketee"
}

last_response.status.should eql(204)
last_response.body.should eql("")

project.reload
project.name.should eql("Not Ticketee")
end

it "unsuccessful JSON" do
put "#{url}.json", :token => token,
:project => {
:name => ""
}
last_response.status.should eql(422)
errors = { :errors => { :name => ["can't be blank"] } }
last_response.body.should eql(errors.to_json)
end
end
end

0 comments on commit ce1d6a7

Please sign in to comment.