Handled the negative case, when a todo failed to be created via XML API. Respond with 422 and xml-formatted validation errors.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@625 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-10-23 07:05:37 +00:00
parent e32fb1057e
commit 6bec8101af
2 changed files with 15 additions and 2 deletions

View file

@ -95,8 +95,11 @@ class TodosController < ApplicationController
render :action => 'create'
end
format.xml do
@todo.reload
render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ), :status => 201
if @saved
render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ), :status => 201
else
render :xml => @todo.errors.to_xml, :status => 422
end
end
end
end

View file

@ -88,6 +88,16 @@ class TodosControllerTest < Test::Rails::TestCase
assert_xml_select "id", /\d+/
end
end
def test_fail_to_create_todo_via_xml
login_as(:admin_user)
#try to create with no context, which is not valid
put :create, :format => "xml", "request" => { "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 422
assert_xml_select "errors" do
assert_xml_select "error", "Context can't be blank"
end
end
def test_create_deferred_todo
original_todo_count = Todo.count