From 43962d6ec50f918c9970bd3cd4b6ee5c7f7426ed Mon Sep 17 00:00:00 2001 From: Angelo capilleri Date: Fri, 29 Nov 2013 12:26:12 +0100 Subject: Fix header Content-Type: # in localized template This PR fixes #13064 regression bug introduced by the #8085 Now in _process_format when the format is a Mime::NullType nothing is written in self.content_type. In this way the method Response#assign_default_content_type_and_charset can write the the default mime_type. --- actionpack/test/controller/localized_templates_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/localized_templates_test.rb b/actionpack/test/controller/localized_templates_test.rb index 6b02eedaed..c95ef8a0c7 100644 --- a/actionpack/test/controller/localized_templates_test.rb +++ b/actionpack/test/controller/localized_templates_test.rb @@ -34,4 +34,15 @@ class LocalizedTemplatesTest < ActionController::TestCase get :hello_world assert_equal "Gutten Tag", @response.body end + + def test_localized_template_has_correct_header_with_no_format_in_template_name + old_locale = I18n.locale + I18n.locale = :it + + get :hello_world + assert_equal "Ciao Mondo", @response.body + assert_equal "text/html", @response.content_type + ensure + I18n.locale = old_locale + end end -- cgit v1.2.3 From b1b9a0aeca879b1c1bc2c8a74f2c9cabd143b9bb Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Tue, 3 Dec 2013 12:04:25 -0200 Subject: Typos. return -> returns. [ci skip] --- actionpack/test/controller/http_digest_authentication_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb index 9f1c168209..52a0bc9aa3 100644 --- a/actionpack/test/controller/http_digest_authentication_test.rb +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -21,7 +21,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase def authenticate authenticate_or_request_with_http_digest("SuperSecret") do |username| - # Return the password + # Returns the password USERS[username] end end -- cgit v1.2.3 From 2d3a6a0cb8df0360dd588a4d2fb260dd07cc9bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Tue, 3 Dec 2013 11:17:01 +0100 Subject: Action Pack Variants By default, variants in the templates will be picked up if a variant is set and there's a match. The format will be: app/views/projects/show.html.erb app/views/projects/show.html+tablet.erb app/views/projects/show.html+phone.erb If request.variant = :tablet is set, we'll automatically be rendering the html+tablet template. In the controller, we can also tailer to the variants with this syntax: class ProjectsController < ActionController::Base def show respond_to do |format| format.html do |html| @stars = @project.stars html.tablet { @notifications = @project.notifications } html.phone { @chat_heads = @project.chat_heads } end format.js format.atom end end end The variant itself is nil by default, but can be set in before filters, like so: class ApplicationController < ActionController::Base before_action do if request.user_agent =~ /iPad/ request.variant = :tablet end end end This is modeled loosely on custom mime types, but it's specifically not intended to be used together. If you're going to make a custom mime type, you don't need a variant. Variants are for variations on a single mime types. --- actionpack/test/controller/mime/respond_to_test.rb | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) (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 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 -- cgit v1.2.3 From d6eda3ef3c59e377670442cd7f36460dbdf389f5 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 4 Dec 2013 23:13:04 -0200 Subject: Remove missing integration points of AV extraction --- actionpack/test/controller/render_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index f41287381a..26806fb03f 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -529,4 +529,4 @@ class HeadRenderTest < ActionController::TestCase assert_equal "something", @response.headers["X-Custom-Header"] assert_response :forbidden end -end \ No newline at end of file +end -- cgit v1.2.3 From a16fa9abfd0b34026b04f4ceeb0b75e63609a74a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 7 Dec 2013 15:00:35 -0800 Subject: Allow code execution in case no variant has been set with variant.none --- actionpack/test/controller/mime/respond_to_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (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 2b6c8739af..cd93043360 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -166,6 +166,15 @@ class RespondToController < ActionController::Base end end + def variant_plus_none_for_format + respond_to do |format| + format.html do |variant| + variant.phone { render text: "phone" } + variant.none { render text: "none" } + end + end + end + protected def set_layout case action_name @@ -544,4 +553,11 @@ class RespondToControllerTest < ActionController::TestCase assert_equal "text/html", @response.content_type 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 end -- cgit v1.2.3 From 99975e742eb2636cd814f2c9de21f4bd3c3dbbc7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 7 Dec 2013 16:32:38 -0800 Subject: Variants can be declared without a block to signify their presence in the controller --- actionpack/test/controller/mime/respond_to_test.rb | 2 +- 1 file changed, 1 insertion(+), 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 cd93043360..c258bbec06 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -170,7 +170,7 @@ class RespondToController < ActionController::Base respond_to do |format| format.html do |variant| variant.phone { render text: "phone" } - variant.none { render text: "none" } + variant.none end end end -- cgit v1.2.3 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 From 4aae538d9ffff3a00a81f3da52fa70f7fd79ac74 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 8 Dec 2013 14:04:04 -0800 Subject: Revert "Merge pull request #13235 from strzalek/variants-inline" -- needs a little more work! This reverts commit 186161148a189839a1e0924043f068a8d155ce69, reversing changes made to cad9eb178ea5eec0e27d74e93518f4ed34e2f997. --- actionpack/test/controller/mime/respond_to_test.rb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (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 0bac86977a..c258bbec06 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -175,12 +175,6 @@ 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 @@ -560,16 +554,10 @@ 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 From edacdbfaf93ac1a81ec8654da4df03b80488e85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Tue, 10 Dec 2013 00:36:18 +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 situations: 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 | 39 +++++++++++++++++++++- 1 file changed, 38 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..d84eb5790d 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -175,6 +175,22 @@ class RespondToController < ActionController::Base end end + def variant_inline_syntax + respond_to do |format| + format.js { render text: "js" } + format.html.none { render text: "none" } + format.html.phone { render text: "phone" } + end + end + + def variant_inline_syntax_without_block + respond_to do |format| + format.js + format.html.none + format.html.phone + end + end + protected def set_layout case action_name @@ -554,10 +570,31 @@ 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 + get :variant_inline_syntax, format: :js + assert_equal "text/javascript", @response.content_type + assert_equal "js", @response.body + + get :variant_inline_syntax + assert_equal "text/html", @response.content_type + assert_equal "none", @response.body + + @request.variant = :phone + get :variant_inline_syntax + assert_equal "text/html", @response.content_type + assert_equal "phone", @response.body + end + + def test_variant_inline_syntax_without_block + @request.variant = :phone + get :variant_inline_syntax_without_block + assert_equal "text/html", @response.content_type + assert_equal "phone", @response.body + end end -- cgit v1.2.3 From 1650bb3d56897cfef4c7e6b86a36eed4f1a41df5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 12 Dec 2013 20:41:14 -0700 Subject: CSRF protection from cross-origin