1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Scaffolded validation errors set the appropriate HTTP status for XML responses. Closes #8622.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6990 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-06-10 23:04:19 +00:00
parent fde3d9d8e4
commit 5179b351c7
3 changed files with 34 additions and 30 deletions

View file

@ -1,5 +1,7 @@
*SVN* *SVN*
* Scaffolded validation errors set the appropriate HTTP status for XML responses. #8622 [mmmultiworks]
* Sexy migrations for the session_migration generator. #8561 [Vladislav] * Sexy migrations for the session_migration generator. #8561 [Vladislav]
* Console reload! runs to_prepare callbacks also. #8393 [f.svehla] * Console reload! runs to_prepare callbacks also. #8393 [f.svehla]

View file

@ -49,7 +49,7 @@ class <%= controller_class_name %>Controller < ApplicationController
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> } format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
else else
format.html { render :action => "new" } format.html { render :action => "new" }
format.xml { render :xml => @<%= file_name %>.errors } format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
end end
end end
end end
@ -66,7 +66,7 @@ class <%= controller_class_name %>Controller < ApplicationController
format.xml { head :ok } format.xml { head :ok }
else else
format.html { render :action => "edit" } format.html { render :action => "edit" }
format.xml { render :xml => @<%= file_name %>.errors } format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
end end
end end
end end

View file

@ -98,19 +98,20 @@ class RailsScaffoldGeneratorTest < Test::Unit::TestCase
assert_generated_controller_for :products do |f| assert_generated_controller_for :products do |f|
assert_has_method f,:index do |name,m| assert_has_method f,:index do |name,m|
assert m=~/@products = Product\.find\(:all\)/,"#{name} should query products table" assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table"
end end
assert_has_method f,:show,:edit,:update,:destroy do |name,m| assert_has_method f,:show,:edit,:update,:destroy do |name,m|
assert m=~/@product = Product\.find\(params\[:id\]\)/,"#{name.to_s} should query products table" assert_match /@product = Product\.find\(params\[:id\]\)/, m, "#{name.to_s} should query products table"
end end
assert_has_method f,:new do |name,m| assert_has_method f,:new do |name,m|
assert m=~/@product = Product\.new/,"#{name.to_s} should instantiate a product" assert_match /@product = Product\.new/, m, "#{name.to_s} should instantiate a product"
end end
assert_has_method f,:create do |name,m| assert_has_method f,:create do |name,m|
assert m=~/@product = Product\.new\(params\[:product\]\)/,"#{name.to_s} should instantiate a product" assert_match /@product = Product\.new\(params\[:product\]\)/, m, "#{name.to_s} should instantiate a product"
assert_match /format.xml \{ render :xml => @product.errors, :status => :unprocessable_entity \}/, m, "#{name.to_s} should set status to :unprocessable_entity code for xml"
end end
end end
@ -132,19 +133,20 @@ class RailsScaffoldGeneratorTest < Test::Unit::TestCase
assert_generated_controller_for :products do |f| assert_generated_controller_for :products do |f|
assert_has_method f,:index do |name,m| assert_has_method f,:index do |name,m|
assert m=~/@products = Product\.find\(:all\)/,"#{name} should query products table" assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table"
end end
assert_has_method f,:show,:edit,:update,:destroy do |name,m| assert_has_method f,:show,:edit,:update,:destroy do |name,m|
assert m=~/@product = Product\.find\(params\[:id\]\)/,"#{name.to_s} should query products table" assert_match /@product = Product\.find\(params\[:id\]\)/, m, "#{name.to_s} should query products table"
end end
assert_has_method f,:new do |name,m| assert_has_method f,:new do |name,m|
assert m=~/@product = Product\.new/,"#{name.to_s} should instantiate a product" assert_match /@product = Product\.new/, m, "#{name.to_s} should instantiate a product"
end end
assert_has_method f,:create do |name,m| assert_has_method f,:create do |name,m|
assert m=~/@product = Product\.new\(params\[:product\]\)/,"#{name.to_s} should instantiate a product" assert_match /@product = Product\.new\(params\[:product\]\)/, m, "#{name.to_s} should instantiate a product"
assert_match /format.xml \{ render :xml => @product.errors, :status => :unprocessable_entity \}/, m, "#{name.to_s} should set status to :unprocessable_entity code for xml"
end end
end end