diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2013-12-03 15:14:49 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2013-12-03 15:14:49 -0800 |
commit | 501acab943cdc3a5ac389cfd9b39dc34d3ca86fb (patch) | |
tree | d20232cd9ea12691bb126e48855ed8ced15c6371 /actionpack/test/controller/mime/respond_to_test.rb | |
parent | 4d648819c5662f375b8ca431a14511ae6a97a29c (diff) | |
parent | eb0402d512a1fb4e65a4d8d3dab3684e9f136b34 (diff) | |
download | rails-501acab943cdc3a5ac389cfd9b39dc34d3ca86fb.tar.gz rails-501acab943cdc3a5ac389cfd9b39dc34d3ca86fb.tar.bz2 rails-501acab943cdc3a5ac389cfd9b39dc34d3ca86fb.zip |
Merge pull request #12977 from strzalek/action-pack-variants
Action Pack Variants
Diffstat (limited to 'actionpack/test/controller/mime/respond_to_test.rb')
-rw-r--r-- | actionpack/test/controller/mime/respond_to_test.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/actionpack/test/controller/mime/respond_to_test.rb b/actionpack/test/controller/mime/respond_to_test.rb index 774dabe105..2b6c8739af 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -146,6 +146,26 @@ class RespondToController < ActionController::Base end end + def variant_with_implicit_rendering + end + + def variant_with_format_and_custom_render + request.variant = :mobile + + respond_to do |type| + type.html { render text: "mobile" } + end + end + + def multiple_variants_for_format + respond_to do |type| + type.html do |html| + html.tablet { render text: "tablet" } + html.phone { render text: "phone" } + end + end + end + protected def set_layout case action_name @@ -490,4 +510,38 @@ class RespondToControllerTest < ActionController::TestCase get :using_defaults, :format => "invalidformat" end end + + def test_invalid_variant + @request.variant = :invalid + assert_raises(ActionView::MissingTemplate) do + get :variant_with_implicit_rendering + end + end + + def test_variant_not_set_regular_template_missing + assert_raises(ActionView::MissingTemplate) do + get :variant_with_implicit_rendering + end + end + + def test_variant_with_implicit_rendering + @request.variant = :mobile + get :variant_with_implicit_rendering + assert_equal "text/html", @response.content_type + assert_equal "mobile", @response.body + end + + def test_variant_with_format_and_custom_render + @request.variant = :phone + get :variant_with_format_and_custom_render + assert_equal "text/html", @response.content_type + assert_equal "mobile", @response.body + end + + def test_multiple_variants_for_format + @request.variant = :tablet + get :multiple_variants_for_format + assert_equal "text/html", @response.content_type + assert_equal "tablet", @response.body + end end |