Methods
R
S
T
Instance Public methods
render(params={})
# File actionpack/test/controller/mime_responds_test.rb, line 931
def render(params={})
  self.response_body = "#{params[:action]} - #{formats}"
end
setup()
# File actionpack/test/controller/mime_responds_test.rb, line 623
def setup
  super
  @request.host = "www.example.com"
  Mime::Type.register_alias('text/html', :iphone)
  Mime::Type.register('text/x-mobile', :mobile)
end
teardown()
# File actionpack/test/controller/mime_responds_test.rb, line 630
def teardown
  super
  Mime::Type.unregister(:iphone)
  Mime::Type.unregister(:mobile)
end
test_api_response_with_invalid_resource_respect_override_block()
# File actionpack/test/controller/mime_responds_test.rb, line 989
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
test_api_response_with_valid_resource_respect_override_block()
# File actionpack/test/controller/mime_responds_test.rb, line 983
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
test_block_inside_respond_with_is_rendered()
# File actionpack/test/controller/mime_responds_test.rb, line 968
def test_block_inside_respond_with_is_rendered
  @controller = InheritedRespondWithController.new
  @request.accept = "application/json"
  get :index
  assert_equal "JSON", @response.body
end
test_clear_respond_to()
# File actionpack/test/controller/mime_responds_test.rb, line 953
def test_clear_respond_to
  @controller = InheritedRespondWithController.new
  @request.accept = "text/html"
  get :index
  assert_equal 406, @response.status
end
test_error_is_raised_if_no_respond_to_is_declared_and_respond_with_is_called()
# File actionpack/test/controller/mime_responds_test.rb, line 1074
def test_error_is_raised_if_no_respond_to_is_declared_and_respond_with_is_called
  @controller = EmptyRespondWithController.new
  @request.accept = "*/*"
  assert_raise RuntimeError do
    get :index
  end
end
test_first_in_respond_to_has_higher_priority()
# File actionpack/test/controller/mime_responds_test.rb, line 960
def test_first_in_respond_to_has_higher_priority
  @controller = InheritedRespondWithController.new
  @request.accept = "*/*"
  get :index
  assert_equal "application/xml", @response.content_type
  assert_equal "<name>david</name>", @response.body
end
test_no_double_render_is_raised()
# File actionpack/test/controller/mime_responds_test.rb, line 995
def test_no_double_render_is_raised
  @request.accept = "text/html"
  assert_raise ActionView::MissingTemplate do
    get :using_resource
  end
end
test_not_acceptable()
# File actionpack/test/controller/mime_responds_test.rb, line 706
def test_not_acceptable
  @request.accept = "application/xml"
  get :using_resource_with_block
  assert_equal 406, @response.status

  @request.accept = "text/javascript"
  get :using_resource_with_overwrite_block
  assert_equal 406, @response.status
end
test_render_json_object_responds_to_str_still_produce_json()
# File actionpack/test/controller/mime_responds_test.rb, line 975
def test_render_json_object_responds_to_str_still_produce_json
  @controller = RenderJsonRespondWithController.new
  @request.accept = "application/json"
  get :index, :format => :json
  assert_match(/"message":"boom"/, @response.body)
  assert_match(/"error":"RenderJsonTestException"/, @response.body)
end
test_respond_as_responder_entry_point()
# File actionpack/test/controller/mime_responds_test.rb, line 943
def test_respond_as_responder_entry_point
  @request.accept = "text/html"
  get :using_responder_with_respond
  assert_equal "respond html", @response.body

  @request.accept = "application/xml"
  get :using_responder_with_respond
  assert_equal "respond xml", @response.body
end
test_using_hash_resource()
# File actionpack/test/controller/mime_responds_test.rb, line 662
def test_using_hash_resource
  @request.accept = "application/xml"
  get :using_hash_resource
  assert_equal "application/xml", @response.content_type
  assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n  <name>david</name>\n</hash>\n", @response.body

  @request.accept = "application/json"
  get :using_hash_resource
  assert_equal "application/json", @response.content_type
  assert @response.body.include?("result")
  assert @response.body.include?('"name":"david"')
  assert @response.body.include?('"id":13')
end
test_using_hash_resource_with_js_raises_an_error_if_template_cant_be_found()
# File actionpack/test/controller/mime_responds_test.rb, line 655
def test_using_hash_resource_with_js_raises_an_error_if_template_cant_be_found
  @request.accept = "text/javascript"
  assert_raise ActionView::MissingTemplate do
    get :using_hash_resource
  end
end
test_using_hash_resource_with_post()
# File actionpack/test/controller/mime_responds_test.rb, line 676
def test_using_hash_resource_with_post
  @request.accept = "application/json"
  assert_raise ArgumentError, "Nil location provided. Can't build URI." do
    post :using_hash_resource
  end
end
test_using_invalid_resource_with_template()
# File actionpack/test/controller/mime_responds_test.rb, line 1030
def test_using_invalid_resource_with_template
  errors = { :name => :invalid }
  Customer.any_instance.stubs(:errors).returns(errors)

  @request.accept = "text/xml"

  post :using_invalid_resource_with_template
  assert_equal errors.to_xml, @response.body
  assert_equal 422, @response.status
  assert_equal nil, @response.location

  put :using_invalid_resource_with_template
  assert_equal errors.to_xml, @response.body
  assert_equal 422, @response.status
  assert_equal nil, @response.location
end
test_using_options_with_template()
# File actionpack/test/controller/mime_responds_test.rb, line 1047
def test_using_options_with_template
  @request.accept = "text/xml"

  post :using_options_with_template
  assert_equal "<customer-name>david</customer-name>", @response.body
  assert_equal 123, @response.status
  assert_equal "http://test.host/", @response.location

  put :using_options_with_template
  assert_equal "<customer-name>david</customer-name>", @response.body
  assert_equal 123, @response.status
  assert_equal "http://test.host/", @response.location
end
test_using_resource()
# File actionpack/test/controller/mime_responds_test.rb, line 636
def test_using_resource
  @request.accept = "application/xml"
  get :using_resource
  assert_equal "application/xml", @response.content_type
  assert_equal "<name>david</name>", @response.body

  @request.accept = "application/json"
  assert_raise ActionView::MissingTemplate do
    get :using_resource
  end
end
test_using_resource_for_delete_with_html_redirects_on_failure()
# File actionpack/test/controller/mime_responds_test.rb, line 880
def test_using_resource_for_delete_with_html_redirects_on_failure
  with_test_route_set do
    errors = { :name => :invalid }
    Customer.any_instance.stubs(:errors).returns(errors)
    Customer.any_instance.stubs(:destroyed?).returns(false)
    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
test_using_resource_for_delete_with_html_redirects_on_success()
# File actionpack/test/controller/mime_responds_test.rb, line 851
def test_using_resource_for_delete_with_html_redirects_on_success
  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
test_using_resource_for_delete_with_json_yields_no_content_on_success()
# File actionpack/test/controller/mime_responds_test.rb, line 870
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
  assert_equal "application/json", @response.content_type
  assert_equal 204, @response.status
  assert_equal " ", @response.body
end
test_using_resource_for_delete_with_xml_yields_no_content_on_success()
# File actionpack/test/controller/mime_responds_test.rb, line 861
def test_using_resource_for_delete_with_xml_yields_no_content_on_success
  Customer.any_instance.stubs(:destroyed?).returns(true)
  @request.accept = "application/xml"
  delete :using_resource
  assert_equal "application/xml", @response.content_type
  assert_equal 204, @response.status
  assert_equal " ", @response.body
end
test_using_resource_for_post_with_html_redirects_on_success()
# File actionpack/test/controller/mime_responds_test.rb, line 716
def test_using_resource_for_post_with_html_redirects_on_success
  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?
  end
end
test_using_resource_for_post_with_html_rerender_on_failure()
# File actionpack/test/controller/mime_responds_test.rb, line 726
def test_using_resource_for_post_with_html_rerender_on_failure
  with_test_route_set do
    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
test_using_resource_for_post_with_json_yields_unprocessable_entity_on_failure()
# File actionpack/test/controller/mime_responds_test.rb, line 762
def test_using_resource_for_post_with_json_yields_unprocessable_entity_on_failure
  with_test_route_set do
    @request.accept = "application/json"
    errors = { :name => :invalid }
    Customer.any_instance.stubs(:errors).returns(errors)
    post :using_resource
    assert_equal "application/json", @response.content_type
    assert_equal 422, @response.status
    errors = {:errors => errors}
    assert_equal errors.to_json, @response.body
    assert_nil @response.location
  end
end
test_using_resource_for_post_with_xml_yields_created_on_success()
# File actionpack/test/controller/mime_responds_test.rb, line 738
def test_using_resource_for_post_with_xml_yields_created_on_success
  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
  end
end
test_using_resource_for_post_with_xml_yields_unprocessable_entity_on_failure()
# File actionpack/test/controller/mime_responds_test.rb, line 749
def test_using_resource_for_post_with_xml_yields_unprocessable_entity_on_failure
  with_test_route_set do
    @request.accept = "application/xml"
    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
test_using_resource_for_put_with_html_redirects_on_success()
# File actionpack/test/controller/mime_responds_test.rb, line 776
def test_using_resource_for_put_with_html_redirects_on_success
  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?
  end
end
test_using_resource_for_put_with_html_rerender_on_failure()
# File actionpack/test/controller/mime_responds_test.rb, line 786
def test_using_resource_for_put_with_html_rerender_on_failure
  with_test_route_set do
    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
test_using_resource_for_put_with_html_rerender_on_failure_even_on_method_override()
# File actionpack/test/controller/mime_responds_test.rb, line 798
def test_using_resource_for_put_with_html_rerender_on_failure_even_on_method_override
  with_test_route_set do
    errors = { :name => :invalid }
    Customer.any_instance.stubs(:errors).returns(errors)
    @request.env["rack.methodoverride.original_method"] = "POST"
    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
test_using_resource_for_put_with_json_yields_no_content_on_success()
# File actionpack/test/controller/mime_responds_test.rb, line 819
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
  assert_equal "application/json", @response.content_type
  assert_equal 204, @response.status
  assert_equal " ", @response.body
end
test_using_resource_for_put_with_json_yields_unprocessable_entity_on_failure()
# File actionpack/test/controller/mime_responds_test.rb, line 839
def test_using_resource_for_put_with_json_yields_unprocessable_entity_on_failure
  @request.accept = "application/json"
  errors = { :name => :invalid }
  Customer.any_instance.stubs(:errors).returns(errors)
  put :using_resource
  assert_equal "application/json", @response.content_type
  assert_equal 422, @response.status
  errors = {:errors => errors}
  assert_equal errors.to_json, @response.body
  assert_nil @response.location
end
test_using_resource_for_put_with_xml_yields_no_content_on_success()
# File actionpack/test/controller/mime_responds_test.rb, line 811
def test_using_resource_for_put_with_xml_yields_no_content_on_success
  @request.accept = "application/xml"
  put :using_resource
  assert_equal "application/xml", @response.content_type
  assert_equal 204, @response.status
  assert_equal " ", @response.body
end
test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure()
# File actionpack/test/controller/mime_responds_test.rb, line 828
def test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure
  @request.accept = "application/xml"
  errors = { :name => :invalid }
  Customer.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
test_using_resource_with_action()
# File actionpack/test/controller/mime_responds_test.rb, line 929
def test_using_resource_with_action
  @controller.instance_eval do
    def render(params={})
      self.response_body = "#{params[:action]} - #{formats}"
    end
  end

  errors = { :name => :invalid }
  Customer.any_instance.stubs(:errors).returns(errors)

  post :using_resource_with_action
  assert_equal "foo - #{[:html].to_s}", @controller.response.body
end
test_using_resource_with_block()
# File actionpack/test/controller/mime_responds_test.rb, line 683
def test_using_resource_with_block
  @request.accept = "*/*"
  get :using_resource_with_block
  assert_equal "text/html", @response.content_type
  assert_equal 'Hello world!', @response.body

  @request.accept = "text/csv"
  get :using_resource_with_block
  assert_equal "text/csv", @response.content_type
  assert_equal "CSV", @response.body

  @request.accept = "application/xml"
  get :using_resource
  assert_equal "application/xml", @response.content_type
  assert_equal "<name>david</name>", @response.body
end
test_using_resource_with_collection()
# File actionpack/test/controller/mime_responds_test.rb, line 920
def test_using_resource_with_collection
  @request.accept = "application/xml"
  get :using_resource_with_collection
  assert_equal "application/xml", @response.content_type
  assert_equal 200, @response.status
  assert_match(/<name>david<\/name>/, @response.body)
  assert_match(/<name>jamis<\/name>/, @response.body)
end
test_using_resource_with_js_simply_tries_to_render_the_template()
# File actionpack/test/controller/mime_responds_test.rb, line 648
def test_using_resource_with_js_simply_tries_to_render_the_template
  @request.accept = "text/javascript"
  get :using_resource
  assert_equal "text/javascript", @response.content_type
  assert_equal "alert(\"Hi\");", @response.body
end
test_using_resource_with_overwrite_block()
# File actionpack/test/controller/mime_responds_test.rb, line 700
def test_using_resource_with_overwrite_block
  get :using_resource_with_overwrite_block
  assert_equal "text/html", @response.content_type
  assert_equal "HTML", @response.body
end
test_using_resource_with_parent_for_get()
# File actionpack/test/controller/mime_responds_test.rb, line 892
def test_using_resource_with_parent_for_get
  @request.accept = "application/xml"
  get :using_resource_with_parent
  assert_equal "application/xml", @response.content_type
  assert_equal 200, @response.status
  assert_equal "<name>david</name>", @response.body
end
test_using_resource_with_parent_for_post()
# File actionpack/test/controller/mime_responds_test.rb, line 900
def test_using_resource_with_parent_for_post
  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
test_using_resource_with_responder()
# File actionpack/test/controller/mime_responds_test.rb, line 1061
def test_using_resource_with_responder
  get :using_resource_with_responder
  assert_equal "Resource name is david", @response.body
end
test_using_resource_with_set_responder()
# File actionpack/test/controller/mime_responds_test.rb, line 1066
def test_using_resource_with_set_responder
  RespondWithController.responder = proc { |c, r, o| c.render :text => "Resource name is #{r.first.name}" }
  get :using_resource
  assert_equal "Resource name is david", @response.body
ensure
  RespondWithController.responder = ActionController::Responder
end
test_using_resource_with_status_and_location()
# File actionpack/test/controller/mime_responds_test.rb, line 1002
def test_using_resource_with_status_and_location
  @request.accept = "text/html"
  post :using_resource_with_status_and_location
  assert @response.redirect?
  assert_equal "http://test.host/", @response.location

  @request.accept = "application/xml"
  get :using_resource_with_status_and_location
  assert_equal 201, @response.status
end
test_using_resource_with_status_and_location_with_invalid_resource()
# File actionpack/test/controller/mime_responds_test.rb, line 1013
def test_using_resource_with_status_and_location_with_invalid_resource
  errors = { :name => :invalid }
  Customer.any_instance.stubs(:errors).returns(errors)

  @request.accept = "text/xml"

  post :using_resource_with_status_and_location
  assert_equal errors.to_xml, @response.body
  assert_equal 422, @response.status
  assert_equal nil, @response.location

  put :using_resource_with_status_and_location
  assert_equal errors.to_xml, @response.body
  assert_equal 422, @response.status
  assert_equal nil, @response.location
end