Skip to content

Commit

Permalink
Add using_resouce_with_json to controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
zuhao committed May 20, 2014
1 parent a0eec57 commit f044020
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions actionpack/test/controller/mime/respond_with_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
require 'controller/fake_models'

class RespondWithController < ActionController::Base
class CustomerWithJson < Customer
def to_json; super; end
end

respond_to :html, :json, :touch
respond_to :xml, :except => :using_resource_with_block
respond_to :js, :only => [ :using_resource_with_block, :using_resource, 'using_hash_resource' ]
Expand Down Expand Up @@ -38,6 +42,10 @@ def using_resource_with_status_and_location
respond_with(resource, :location => "http://test.host/", :status => :created)
end

def using_resource_with_json
respond_with(CustomerWithJson.new("david", request.delete? ? nil : 13))
end

def using_invalid_resource_with_template
respond_with(resource)
end
Expand Down Expand Up @@ -380,9 +388,8 @@ def test_using_resource_for_put_with_xml_yields_no_content_on_success
end

def test_using_resource_for_put_with_json_yields_no_content_on_success
Customer.any_instance.stubs(:to_json).returns('{"name": "David"}')
@request.accept = "application/json"
put :using_resource
put :using_resource_with_json
assert_equal "application/json", @response.content_type
assert_equal 204, @response.status
assert_equal "", @response.body
Expand Down Expand Up @@ -431,10 +438,9 @@ def test_using_resource_for_delete_with_xml_yields_no_content_on_success
end

def test_using_resource_for_delete_with_json_yields_no_content_on_success
Customer.any_instance.stubs(:to_json).returns('{"name": "David"}')
Customer.any_instance.stubs(:destroyed?).returns(true)
@request.accept = "application/json"
delete :using_resource
delete :using_resource_with_json
assert_equal "application/json", @response.content_type
assert_equal 204, @response.status
assert_equal "", @response.body
Expand Down

0 comments on commit f044020

Please sign in to comment.