diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-31 11:59:05 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-31 11:59:05 +0200 |
commit | 5b7e81efec649b424037c68a93bddad1bc4e0c23 (patch) | |
tree | 54e83961bbbe4690070e9037a0ba623270bb7288 /actionpack/test/controller | |
parent | 7a4a679dbada2e1fcfc28db8c47dd32e03afc1af (diff) | |
download | rails-5b7e81efec649b424037c68a93bddad1bc4e0c23.tar.gz rails-5b7e81efec649b424037c68a93bddad1bc4e0c23.tar.bz2 rails-5b7e81efec649b424037c68a93bddad1bc4e0c23.zip |
Allow respond_with to deal with http verb accordingly.
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 117f4ea4f0..1db951fdfe 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -474,6 +474,14 @@ end class RespondResource undef_method :to_json + def self.model_name + @_model_name ||= ActiveModel::Name.new(name) + end + + def to_param + 13 + end + def to_xml "XML" end @@ -481,6 +489,10 @@ class RespondResource def to_js "JS" end + + def errors + [] + end end class RespondWithController < ActionController::Base @@ -520,6 +532,10 @@ protected self.content_type ||= Mime::JS self.response_body = js.respond_to?(:to_js) ? js.to_js : js end + + def respond_resource_url(id) + request.host + "/respond/resource/#{id.to_param}" + end end class InheritedRespondWithController < RespondWithController @@ -593,6 +609,51 @@ class RespondWithControllerTest < ActionController::TestCase end end + def test_using_resource_for_post + @request.accept = "application/xml" + + post :using_resource + assert_equal "application/xml", @response.content_type + assert_equal 201, @response.status + assert_equal "XML", @response.body + assert_equal "www.example.com/respond/resource/13", @response.location + + errors = { :name => :invalid } + RespondResource.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 + + def test_using_resource_for_put + @request.accept = "application/xml" + + put :using_resource + assert_equal "application/xml", @response.content_type + assert_equal 200, @response.status + assert_equal " ", @response.body + assert_nil @response.location + + errors = { :name => :invalid } + RespondResource.any_instance.stubs(:errors).returns(errors) + put :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 + + def test_using_resource_for_delete + @request.accept = "application/xml" + delete :using_resource + assert_equal "application/xml", @response.content_type + assert_equal 200, @response.status + assert_equal " ", @response.body + assert_nil @response.location + end + def test_using_resource_with_options @request.accept = "application/xml" get :using_resource_with_options @@ -648,8 +709,6 @@ class RespondWithControllerTest < ActionController::TestCase end class AbstractPostController < ActionController::Base - respond_to :html, :iphone - self.view_paths = File.dirname(__FILE__) + "/../fixtures/post_test/" end @@ -658,7 +717,7 @@ class PostController < AbstractPostController around_filter :with_iphone def index - respond_to # It will use formats declared above + respond_to(:html, :iphone) end protected |