From 2647d2f656ff203f45eecd7e19182018519d4064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Sun, 8 Dec 2013 22:24:27 +0100 Subject: Inline variants syntax In most cases, when setting variant specific code, you're not sharing any code within format. Inline syntax can vastly simplify defining variants in those sitiations: respond_to do |format| format.js { render "trash" } format.html do |variant| variant.phone { redirect_to progress_path } variant.none { render "trash" } end end ` Becomes: respond_to do |format| format.js { render "trash" } format.html.phone { redirect_to progress_path } format.html.none { render "trash" } end --- actionpack/test/controller/mime/respond_to_test.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/mime/respond_to_test.rb b/actionpack/test/controller/mime/respond_to_test.rb index c258bbec06..0bac86977a 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -175,6 +175,12 @@ class RespondToController < ActionController::Base end end + def variant_inline_syntax + respond_to do |format| + format.html.phone { render text: "phone" } + end + end + protected def set_layout case action_name @@ -554,10 +560,16 @@ class RespondToControllerTest < ActionController::TestCase assert_equal "tablet", @response.body end - def test_no_variant_in_variant_setup get :variant_plus_none_for_format assert_equal "text/html", @response.content_type assert_equal "none", @response.body end + + def test_variant_inline_syntax + @request.variant = :phone + get :variant_inline_syntax + assert_equal "text/html", @response.content_type + assert_equal "phone", @response.body + end end -- cgit v1.2.3