aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2012-02-04 07:00:49 -0800
committerJosé Valim <jose.valim@plataformatec.com.br>2012-02-04 07:00:49 -0800
commit44b9992c1179558fb9cd9b4c3524f3ab6d52daf9 (patch)
tree1583ec7b1e491c4519759bc75abe4825c24883b9 /actionpack/test/controller
parent9cb0e12e46e0385b132dbe8716097225b7ef0863 (diff)
parent567ac65b423c30c24aa6c0c0522858e3c240eb26 (diff)
downloadrails-44b9992c1179558fb9cd9b4c3524f3ab6d52daf9.tar.gz
rails-44b9992c1179558fb9cd9b4c3524f3ab6d52daf9.tar.bz2
rails-44b9992c1179558fb9cd9b4c3524f3ab6d52daf9.zip
Merge pull request #4870 from sikachu/3-2-stable-responder-fix
Fix override API response bug in respond_with
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/mime_responds_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 76a8c89e60..7c4fb59c15 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -597,6 +597,19 @@ class RenderJsonRespondWithController < RespondWithController
format.json { render :json => RenderJsonTestException.new('boom') }
end
end
+
+ def create
+ resource = ValidatedCustomer.new(params[:name], 1)
+ respond_with(resource) do |format|
+ format.json do
+ if resource.errors.empty?
+ render :json => { :valid => true }
+ else
+ render :json => { :valid => false }
+ end
+ end
+ end
+ end
end
class EmptyRespondWithController < ActionController::Base
@@ -968,6 +981,18 @@ class RespondWithControllerTest < ActionController::TestCase
assert_match(/"error":"RenderJsonTestException"/, @response.body)
end
+ def test_api_response_with_valid_resource_respect_override_block
+ @controller = RenderJsonRespondWithController.new
+ post :create, :name => "sikachu", :format => :json
+ assert_equal '{"valid":true}', @response.body
+ end
+
+ def test_api_response_with_invalid_resource_respect_override_block
+ @controller = RenderJsonRespondWithController.new
+ post :create, :name => "david", :format => :json
+ assert_equal '{"valid":false}', @response.body
+ end
+
def test_no_double_render_is_raised
@request.accept = "text/html"
assert_raise ActionView::MissingTemplate do