When creating a Todo via the XML REST API, the status code returned is now 201, and the Todo is reloaded before it is rendered as XML, so that the ID is included.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@624 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-10-23 06:46:58 +00:00
parent 474404619a
commit e32fb1057e
2 changed files with 16 additions and 4 deletions

View file

@ -94,7 +94,10 @@ class TodosController < ApplicationController
determine_down_count if @saved
render :action => 'create'
end
format.xml { render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ) }
format.xml do
@todo.reload
render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ), :status => 201
end
end
end

View file

@ -74,10 +74,19 @@ class TodosControllerTest < Test::Rails::TestCase
end
def test_create_todo
original_todo_count = Todo.count
assert_difference Todo, :count do
login_as(:admin_user)
put :create, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
end
end
def test_create_todo_via_xml
login_as(:admin_user)
put :create, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
assert_equal original_todo_count + 1, Todo.count
put :create, :format => "xml", "request" => { "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" }
assert_response 201
assert_xml_select "todo" do
assert_xml_select "id", /\d+/
end
end
def test_create_deferred_todo