aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-07-29 11:13:08 +0200
committerYehuda Katz <wycats@gmail.com>2009-07-29 12:06:03 -0700
commitbbe86077c2148559f7548520303b2e683ff86119 (patch)
treea7df321737a77f467979df88900dc52b907a49b3
parent67b2d08c0a64ddec3a0c4e1c0b5d96bd418cceef (diff)
downloadrails-bbe86077c2148559f7548520303b2e683ff86119.tar.gz
rails-bbe86077c2148559f7548520303b2e683ff86119.tar.bz2
rails-bbe86077c2148559f7548520303b2e683ff86119.zip
Added tests for respond_to class method.
Signed-off-by: Yehuda Katz <wycats@gmail.com>
-rw-r--r--actionpack/lib/action_controller/base/mime_responds.rb2
-rw-r--r--actionpack/test/controller/mime_responds_test.rb70
-rw-r--r--actionpack/test/fixtures/respond_with/using_defaults.html.erb1
-rw-r--r--actionpack/test/fixtures/respond_with/using_defaults.js.rjs1
-rw-r--r--actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs1
-rw-r--r--actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder1
6 files changed, 73 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/base/mime_responds.rb b/actionpack/lib/action_controller/base/mime_responds.rb
index ece4920a23..0ce6660c98 100644
--- a/actionpack/lib/action_controller/base/mime_responds.rb
+++ b/actionpack/lib/action_controller/base/mime_responds.rb
@@ -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 ]
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index f2c20417f8..48b343272e 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -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
diff --git a/actionpack/test/fixtures/respond_with/using_defaults.html.erb b/actionpack/test/fixtures/respond_with/using_defaults.html.erb
new file mode 100644
index 0000000000..6769dd60bd
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_defaults.html.erb
@@ -0,0 +1 @@
+Hello world! \ No newline at end of file
diff --git a/actionpack/test/fixtures/respond_with/using_defaults.js.rjs b/actionpack/test/fixtures/respond_with/using_defaults.js.rjs
new file mode 100644
index 0000000000..469fcd8e15
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_defaults.js.rjs
@@ -0,0 +1 @@
+page[:body].visual_effect :highlight \ No newline at end of file
diff --git a/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs b/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
new file mode 100644
index 0000000000..469fcd8e15
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
@@ -0,0 +1 @@
+page[:body].visual_effect :highlight \ No newline at end of file
diff --git a/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder b/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
new file mode 100644
index 0000000000..598d62e2fc
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
@@ -0,0 +1 @@
+xml.p "Hello world!" \ No newline at end of file