From e32fb1057eef7430128c3e383457e9316ca1a4a1 Mon Sep 17 00:00:00 2001 From: lukemelia Date: Tue, 23 Oct 2007 06:46:58 +0000 Subject: [PATCH] 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 --- tracks/app/controllers/todos_controller.rb | 5 ++++- tracks/test/functional/todos_controller_test.rb | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb index b7183e99..958622f3 100644 --- a/tracks/app/controllers/todos_controller.rb +++ b/tracks/app/controllers/todos_controller.rb @@ -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 diff --git a/tracks/test/functional/todos_controller_test.rb b/tracks/test/functional/todos_controller_test.rb index 418153da..d308d35b 100644 --- a/tracks/test/functional/todos_controller_test.rb +++ b/tracks/test/functional/todos_controller_test.rb @@ -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