mirror of
https://github.com/github/rails.git
synced 2026-01-10 15:17:57 -05:00
Added tests for respond_to class method.
Signed-off-by: Yehuda Katz <wycats@gmail.com>
This commit is contained in:
@@ -151,7 +151,7 @@ module ActionController #:nodoc:
|
||||
block.call(responder) if block_given?
|
||||
|
||||
mimes = collect_mimes_from_class_level if mimes.empty?
|
||||
mimes.each { |mime| responder.custom(mime) }
|
||||
mimes.each { |mime| responder.send(mime) }
|
||||
|
||||
if format = request.negotiate_mime(responder.order)
|
||||
# TODO It should be just: self.formats = [ :foo ]
|
||||
|
||||
@@ -166,7 +166,7 @@ class RespondToController < ActionController::Base
|
||||
end
|
||||
end
|
||||
|
||||
class MimeControllerTest < ActionController::TestCase
|
||||
class RespondToControllerTest < ActionController::TestCase
|
||||
tests RespondToController
|
||||
|
||||
def setup
|
||||
@@ -471,8 +471,74 @@ class MimeControllerTest < ActionController::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
class ClassRespondToController < ActionController::Base
|
||||
class RespondWithController < ActionController::Base
|
||||
respond_to :html
|
||||
respond_to :xml, :except => :using_defaults
|
||||
respond_to :js, :only => :using_defaults
|
||||
|
||||
def using_defaults
|
||||
respond_to do |format|
|
||||
format.csv { render :text => "CSV" }
|
||||
end
|
||||
end
|
||||
|
||||
def using_defaults_with_type_list
|
||||
respond_to(:js, :xml)
|
||||
end
|
||||
end
|
||||
|
||||
class RespondWithControllerTest < ActionController::TestCase
|
||||
tests RespondWithController
|
||||
|
||||
def setup
|
||||
super
|
||||
ActionController::Base.use_accept_header = true
|
||||
@request.host = "www.example.com"
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
ActionController::Base.use_accept_header = false
|
||||
end
|
||||
|
||||
def test_using_defaults
|
||||
@request.accept = "*/*"
|
||||
get :using_defaults
|
||||
assert_equal "text/html", @response.content_type
|
||||
assert_equal 'Hello world!', @response.body
|
||||
|
||||
@request.accept = "text/csv"
|
||||
get :using_defaults
|
||||
assert_equal "text/csv", @response.content_type
|
||||
assert_equal "CSV", @response.body
|
||||
|
||||
@request.accept = "text/javascript"
|
||||
get :using_defaults
|
||||
assert_equal "text/javascript", @response.content_type
|
||||
assert_equal '$("body").visualEffect("highlight");', @response.body
|
||||
end
|
||||
|
||||
def test_using_defaults_with_type_list
|
||||
@request.accept = "*/*"
|
||||
get :using_defaults_with_type_list
|
||||
assert_equal "text/javascript", @response.content_type
|
||||
assert_equal '$("body").visualEffect("highlight");', @response.body
|
||||
|
||||
@request.accept = "application/xml"
|
||||
get :using_defaults_with_type_list
|
||||
assert_equal "application/xml", @response.content_type
|
||||
assert_equal "<p>Hello world!</p>\n", @response.body
|
||||
end
|
||||
|
||||
def test_not_acceptable
|
||||
@request.accept = "application/xml"
|
||||
get :using_defaults
|
||||
assert_equal 406, @response.status
|
||||
|
||||
@request.accept = "text/html"
|
||||
get :using_defaults_with_type_list
|
||||
assert_equal 406, @response.status
|
||||
end
|
||||
end
|
||||
|
||||
class AbstractPostController < ActionController::Base
|
||||
|
||||
1
actionpack/test/fixtures/respond_with/using_defaults.html.erb
vendored
Normal file
1
actionpack/test/fixtures/respond_with/using_defaults.html.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Hello world!
|
||||
1
actionpack/test/fixtures/respond_with/using_defaults.js.rjs
vendored
Normal file
1
actionpack/test/fixtures/respond_with/using_defaults.js.rjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
page[:body].visual_effect :highlight
|
||||
1
actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
vendored
Normal file
1
actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
page[:body].visual_effect :highlight
|
||||
1
actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
vendored
Normal file
1
actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
vendored
Normal file
@@ -0,0 +1 @@
|
||||
xml.p "Hello world!"
|
||||
Reference in New Issue
Block a user