diff options
Diffstat (limited to 'actionpack/test/controller/mime_responds_test.rb')
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index c617cb2e84..fb2519563d 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -107,7 +107,7 @@ class RespondToController < ActionController::Base type.any(:js, :xml) { render :text => "Either JS or XML" } end end - + def handle_any_any respond_to do |type| type.html { render :text => 'HTML' } @@ -120,12 +120,12 @@ class RespondToController < ActionController::Base type.html type.js end - end - - def iphone_with_html_response_type + end + + 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" } @@ -138,7 +138,7 @@ class RespondToController < ActionController::Base 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" } @@ -162,7 +162,7 @@ class RespondToController < ActionController::Base end end -RespondToController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +RespondToController.view_paths = [FIXTURE_LOAD_PATH] class MimeControllerTest < Test::Unit::TestCase def setup @@ -247,7 +247,7 @@ class MimeControllerTest < Test::Unit::TestCase get :just_xml assert_equal 'XML', @response.body end - + def test_using_defaults @request.env["HTTP_ACCEPT"] = "*/*" get :using_defaults @@ -347,12 +347,12 @@ class MimeControllerTest < Test::Unit::TestCase get :handle_any_any assert_equal 'HTML', @response.body end - + def test_handle_any_any_parameter_format get :handle_any_any, {:format=>'html'} assert_equal 'HTML', @response.body end - + def test_handle_any_any_explicit_html @request.env["HTTP_ACCEPT"] = "text/html" get :handle_any_any @@ -364,7 +364,7 @@ class MimeControllerTest < Test::Unit::TestCase get :handle_any_any assert_equal 'Whatever you ask for, I got it', @response.body end - + def test_handle_any_any_xml @request.env["HTTP_ACCEPT"] = "text/xml" get :handle_any_any @@ -445,31 +445,31 @@ class MimeControllerTest < Test::Unit::TestCase get :using_defaults, :format => "xml" assert_equal "using_defaults - xml", @response.body - end - + end + def test_format_with_custom_response_type get :iphone_with_html_response_type - assert_equal '<html><div id="html">Hello future from Firefox!</div></html>', @response.body - + assert_equal '<html><div id="html">Hello future from Firefox!</div></html>', @response.body + get :iphone_with_html_response_type, :format => "iphone" assert_equal "text/html", @response.content_type assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body - end - + end + def test_format_with_custom_response_type_and_request_headers @request.env["HTTP_ACCEPT"] = "text/iphone" get :iphone_with_html_response_type assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body assert_equal "text/html", @response.content_type - end + end def test_format_with_custom_response_type_and_request_headers_with_only_one_layout_present get :iphone_with_html_response_type_without_layout - assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body + assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body @request.env["HTTP_ACCEPT"] = "text/iphone" assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout } - end + end end class AbstractPostController < ActionController::Base @@ -497,7 +497,7 @@ class PostController < AbstractPostController end end -class SuperPostController < PostController +class SuperPostController < PostController def index respond_to do |type| type.html @@ -514,25 +514,24 @@ class MimeControllerLayoutsTest < Test::Unit::TestCase @controller = PostController.new @request.host = "www.example.com" end - + def test_missing_layout_renders_properly get :index - assert_equal '<html><div id="html">Hello Firefox</div></html>', @response.body + assert_equal '<html><div id="html">Hello Firefox</div></html>', @response.body @request.env["HTTP_ACCEPT"] = "text/iphone" get :index assert_equal 'Hello iPhone', @response.body end - + def test_format_with_inherited_layouts @controller = SuperPostController.new - + get :index assert_equal 'Super Firefox', @response.body - + @request.env["HTTP_ACCEPT"] = "text/iphone" get :index assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body end end - |