aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/mime_responds_test.rb
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-08-14 22:32:40 -0700
committerYehuda Katz <wycats@gmail.com>2009-08-15 12:32:02 -0700
commit1310231c15742bf7d99e2f143d88b383c32782d3 (patch)
tree7f32ae8257410a19e1b9d4b189cc65803879c8e3 /actionpack/test/controller/mime_responds_test.rb
parent9b552fb300c4606fe517eadaa30708e9d75498a6 (diff)
downloadrails-1310231c15742bf7d99e2f143d88b383c32782d3.tar.gz
rails-1310231c15742bf7d99e2f143d88b383c32782d3.tar.bz2
rails-1310231c15742bf7d99e2f143d88b383c32782d3.zip
Got tests to pass with some more changes.
* request.formats is much simpler now * For XHRs or Accept headers with a single item, we use the Accept header * For other requests, we use params[:format] or fallback to HTML * This is primarily to work around the fact that browsers provide completely broken Accept headers, so we have to whitelist the few cases we can specifically isolate and treat other requests as coming from the browser * For APIs, we can support single-item Accept headers, which disambiguates from the browsers * Requests to an action that only has an XML template from the browser will no longer find the template. This worked previously because most browsers provide a catch-all */*, but this was mostly accidental behavior. If you want to serve XML, either use the :xml format in links, or explicitly specify the XML template: render "template.xml".
Diffstat (limited to 'actionpack/test/controller/mime_responds_test.rb')
-rw-r--r--actionpack/test/controller/mime_responds_test.rb51
1 files changed, 17 insertions, 34 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 2e2dba5aae..3f00b9ba2f 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -79,29 +79,20 @@ class RespondToController < ActionController::Base
end
end
- def custom_constant_handling
- Mime::Type.register("text/x-mobile", :mobile)
+ Mime::Type.register("text/x-mobile", :mobile)
+ def custom_constant_handling
respond_to do |type|
type.html { render :text => "HTML" }
type.mobile { render :text => "Mobile" }
end
- ensure
- Mime::SET.delete(:mobile)
- Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
end
def custom_constant_handling_without_block
- Mime::Type.register("text/x-mobile", :mobile)
-
respond_to do |type|
type.html { render :text => "HTML" }
type.mobile
end
-
- ensure
- Mime::SET.delete(:mobile)
- Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
end
def handle_any
@@ -125,32 +116,24 @@ class RespondToController < ActionController::Base
end
end
+ Mime::Type.register_alias("text/html", :iphone)
+
def iphone_with_html_response_type
- Mime::Type.register_alias("text/html", :iphone)
request.format = :iphone if request.env["HTTP_ACCEPT"] == "text/iphone"
respond_to do |type|
type.html { @type = "Firefox" }
type.iphone { @type = "iPhone" }
end
-
- ensure
- Mime::SET.delete(:iphone)
- Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
end
def iphone_with_html_response_type_without_layout
- Mime::Type.register_alias("text/html", :iphone)
request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
respond_to do |type|
type.html { @type = "Firefox"; render :action => "iphone_with_html_response_type" }
type.iphone { @type = "iPhone" ; render :action => "iphone_with_html_response_type" }
end
-
- ensure
- Mime::SET.delete(:iphone)
- Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
end
def rescue_action(e)
@@ -213,18 +196,20 @@ class RespondToControllerTest < ActionController::TestCase
def test_js_or_html
@request.accept = "text/javascript, text/html"
- get :js_or_html
+ xhr :get, :js_or_html
assert_equal 'JS', @response.body
- get :html_or_xml
+ @request.accept = "text/javascript, text/html"
+ xhr :get, :html_or_xml
assert_equal 'HTML', @response.body
- get :just_xml
+ @request.accept = "text/javascript, text/html"
+ xhr :get, :just_xml
assert_response 406
end
def test_json_or_yaml
- get :json_or_yaml
+ xhr :get, :json_or_yaml
assert_equal 'JSON', @response.body
get :json_or_yaml, :format => 'json'
@@ -246,13 +231,13 @@ class RespondToControllerTest < ActionController::TestCase
def test_js_or_anything
@request.accept = "text/javascript, */*"
- get :js_or_html
+ xhr :get, :js_or_html
assert_equal 'JS', @response.body
- get :html_or_xml
+ xhr :get, :html_or_xml
assert_equal 'HTML', @response.body
- get :just_xml
+ xhr :get, :just_xml
assert_equal 'XML', @response.body
end
@@ -291,14 +276,16 @@ class RespondToControllerTest < ActionController::TestCase
end
def test_with_atom_content_type
+ @request.accept = ""
@request.env["CONTENT_TYPE"] = "application/atom+xml"
- get :made_for_content_type
+ xhr :get, :made_for_content_type
assert_equal "ATOM", @response.body
end
def test_with_rss_content_type
+ @request.accept = ""
@request.env["CONTENT_TYPE"] = "application/rss+xml"
- get :made_for_content_type
+ xhr :get, :made_for_content_type
assert_equal "RSS", @response.body
end
@@ -795,12 +782,8 @@ class PostController < AbstractPostController
protected
def with_iphone
- Mime::Type.register_alias("text/html", :iphone)
request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
yield
- ensure
- Mime::SET.delete(:iphone)
- Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
end
end