aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/mime_responds_test.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-10-10 17:15:11 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-10-10 17:15:11 +0100
commit66ee2654ff243f03595a402fa15e1eea1b5b45be (patch)
tree3f1055e03082f0c767719e8cba5155e4207779e0 /actionpack/test/controller/mime_responds_test.rb
parentdd2779e1b83b4d867d47dd286ec0c919f5df12a9 (diff)
parentb9ce8216fa849a47ad0b0f99fa510e226a23c12e (diff)
downloadrails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.gz
rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.bz2
rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack/test/controller/mime_responds_test.rb')
-rw-r--r--actionpack/test/controller/mime_responds_test.rb150
1 files changed, 83 insertions, 67 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 93a815adae..a79648396c 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -527,12 +527,6 @@ class RespondWithControllerTest < ActionController::TestCase
super
ActionController::Base.use_accept_header = true
@request.host = "www.example.com"
-
- ActionController::Routing::Routes.draw do |map|
- map.resources :customers
- map.resources :quiz_stores, :has_many => :customers
- map.connect ":controller/:action/:id"
- end
end
def teardown
@@ -593,53 +587,59 @@ class RespondWithControllerTest < ActionController::TestCase
end
def test_using_resource_for_post_with_html
- post :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 302, @response.status
- assert_equal "http://www.example.com/customers/13", @response.location
- assert @response.redirect?
-
- errors = { :name => :invalid }
- Customer.any_instance.stubs(:errors).returns(errors)
- post :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 200, @response.status
- assert_equal "New world!\n", @response.body
- assert_nil @response.location
+ with_test_route_set do
+ post :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "http://www.example.com/customers/13", @response.location
+ assert @response.redirect?
+
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ post :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 200, @response.status
+ assert_equal "New world!\n", @response.body
+ assert_nil @response.location
+ end
end
def test_using_resource_for_post_with_xml
- @request.accept = "application/xml"
-
- post :using_resource
- assert_equal "application/xml", @response.content_type
- assert_equal 201, @response.status
- assert_equal "<name>david</name>", @response.body
- assert_equal "http://www.example.com/customers/13", @response.location
-
- errors = { :name => :invalid }
- Customer.any_instance.stubs(:errors).returns(errors)
- post :using_resource
- assert_equal "application/xml", @response.content_type
- assert_equal 422, @response.status
- assert_equal errors.to_xml, @response.body
- assert_nil @response.location
+ with_test_route_set do
+ @request.accept = "application/xml"
+
+ post :using_resource
+ assert_equal "application/xml", @response.content_type
+ assert_equal 201, @response.status
+ assert_equal "<name>david</name>", @response.body
+ assert_equal "http://www.example.com/customers/13", @response.location
+
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ post :using_resource
+ assert_equal "application/xml", @response.content_type
+ assert_equal 422, @response.status
+ assert_equal errors.to_xml, @response.body
+ assert_nil @response.location
+ end
end
def test_using_resource_for_put_with_html
- put :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 302, @response.status
- assert_equal "http://www.example.com/customers/13", @response.location
- assert @response.redirect?
-
- errors = { :name => :invalid }
- Customer.any_instance.stubs(:errors).returns(errors)
- put :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 200, @response.status
- assert_equal "Edit world!\n", @response.body
- assert_nil @response.location
+ with_test_route_set do
+ put :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "http://www.example.com/customers/13", @response.location
+ assert @response.redirect?
+
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ put :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 200, @response.status
+ assert_equal "Edit world!\n", @response.body
+ assert_nil @response.location
+ end
end
def test_using_resource_for_put_with_xml
@@ -660,11 +660,13 @@ class RespondWithControllerTest < ActionController::TestCase
end
def test_using_resource_for_delete_with_html
- Customer.any_instance.stubs(:destroyed?).returns(true)
- delete :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 302, @response.status
- assert_equal "http://www.example.com/customers", @response.location
+ with_test_route_set do
+ Customer.any_instance.stubs(:destroyed?).returns(true)
+ delete :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "http://www.example.com/customers", @response.location
+ end
end
def test_using_resource_for_delete_with_xml
@@ -685,21 +687,23 @@ class RespondWithControllerTest < ActionController::TestCase
end
def test_using_resource_with_parent_for_post
- @request.accept = "application/xml"
-
- post :using_resource_with_parent
- assert_equal "application/xml", @response.content_type
- assert_equal 201, @response.status
- assert_equal "<name>david</name>", @response.body
- assert_equal "http://www.example.com/quiz_stores/11/customers/13", @response.location
-
- errors = { :name => :invalid }
- Customer.any_instance.stubs(:errors).returns(errors)
- post :using_resource
- assert_equal "application/xml", @response.content_type
- assert_equal 422, @response.status
- assert_equal errors.to_xml, @response.body
- assert_nil @response.location
+ with_test_route_set do
+ @request.accept = "application/xml"
+
+ post :using_resource_with_parent
+ assert_equal "application/xml", @response.content_type
+ assert_equal 201, @response.status
+ assert_equal "<name>david</name>", @response.body
+ assert_equal "http://www.example.com/quiz_stores/11/customers/13", @response.location
+
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ post :using_resource
+ assert_equal "application/xml", @response.content_type
+ assert_equal 422, @response.status
+ assert_equal errors.to_xml, @response.body
+ assert_nil @response.location
+ end
end
def test_using_resource_with_collection
@@ -773,6 +777,18 @@ class RespondWithControllerTest < ActionController::TestCase
get :default_overwritten
assert_equal 406, @response.status
end
+
+ private
+ def with_test_route_set
+ with_routing do |set|
+ set.draw do |map|
+ map.resources :customers
+ map.resources :quiz_stores, :has_many => :customers
+ map.connect ":controller/:action/:id"
+ end
+ yield
+ end
+ end
end
class AbstractPostController < ActionController::Base