mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added tests for nested resources.
This commit is contained in:
parent
5b7e81efec
commit
b2d24baf79
1 changed files with 48 additions and 12 deletions
|
@ -475,7 +475,7 @@ class RespondResource
|
|||
undef_method :to_json
|
||||
|
||||
def self.model_name
|
||||
@_model_name ||= ActiveModel::Name.new(name)
|
||||
@_model_name ||= ActiveModel::Name.new("resource")
|
||||
end
|
||||
|
||||
def to_param
|
||||
|
@ -495,6 +495,16 @@ class RespondResource
|
|||
end
|
||||
end
|
||||
|
||||
class ParentResource
|
||||
def self.model_name
|
||||
@_model_name ||= ActiveModel::Name.new("parent")
|
||||
end
|
||||
|
||||
def to_param
|
||||
11
|
||||
end
|
||||
end
|
||||
|
||||
class RespondWithController < ActionController::Base
|
||||
respond_to :html, :json
|
||||
respond_to :xml, :except => :using_defaults
|
||||
|
@ -510,6 +520,12 @@ class RespondWithController < ActionController::Base
|
|||
respond_to(:js, :xml)
|
||||
end
|
||||
|
||||
def default_overwritten
|
||||
respond_to do |format|
|
||||
format.html { render :text => "HTML" }
|
||||
end
|
||||
end
|
||||
|
||||
def using_resource
|
||||
respond_with(RespondResource.new)
|
||||
end
|
||||
|
@ -520,10 +536,8 @@ class RespondWithController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def default_overwritten
|
||||
respond_to do |format|
|
||||
format.html { render :text => "HTML" }
|
||||
end
|
||||
def using_resource_with_parent
|
||||
respond_with([ParentResource.new, RespondResource.new])
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -533,8 +547,12 @@ protected
|
|||
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}"
|
||||
def resource_url(resource)
|
||||
request.host + "/resource/#{resource.to_param}"
|
||||
end
|
||||
|
||||
def parent_resource_url(parent, resource)
|
||||
request.host + "/parent/#{parent.to_param}/resource/#{resource.to_param}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -592,6 +610,12 @@ class RespondWithControllerTest < ActionController::TestCase
|
|||
assert_equal "<p>Hello world!</p>\n", @response.body
|
||||
end
|
||||
|
||||
def test_default_overwritten
|
||||
get :default_overwritten
|
||||
assert_equal "text/html", @response.content_type
|
||||
assert_equal "HTML", @response.body
|
||||
end
|
||||
|
||||
def test_using_resource
|
||||
@request.accept = "text/html"
|
||||
get :using_resource
|
||||
|
@ -616,7 +640,7 @@ class RespondWithControllerTest < ActionController::TestCase
|
|||
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
|
||||
assert_equal "www.example.com/resource/13", @response.location
|
||||
|
||||
errors = { :name => :invalid }
|
||||
RespondResource.any_instance.stubs(:errors).returns(errors)
|
||||
|
@ -668,10 +692,22 @@ class RespondWithControllerTest < ActionController::TestCase
|
|||
assert_equal "JS", @response.body
|
||||
end
|
||||
|
||||
def test_default_overwritten
|
||||
get :default_overwritten
|
||||
assert_equal "text/html", @response.content_type
|
||||
assert_equal "HTML", @response.body
|
||||
def test_using_resource_with_parent
|
||||
@request.accept = "application/xml"
|
||||
|
||||
post :using_resource_with_parent
|
||||
assert_equal "application/xml", @response.content_type
|
||||
assert_equal 201, @response.status
|
||||
assert_equal "XML", @response.body
|
||||
assert_equal "www.example.com/parent/11/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_clear_respond_to
|
||||
|
|
Loading…
Reference in a new issue