From d611036c7709d7c30cbab3110e20e248283af364 Mon Sep 17 00:00:00 2001 From: Frank Groeneveld Date: Fri, 17 Oct 2014 08:21:56 +0200 Subject: Use include_blank value as option label Update select_tag to reflect documentation and behave the same as form builder select. If the value of include_blank is not boolean true, use that value as the option label. --- actionview/lib/action_view/helpers/form_tag_helper.rb | 10 ++++++++-- actionview/test/template/form_tag_helper_test.rb | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 7d1cdc5a68..cf1e20cf55 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -133,8 +133,14 @@ module ActionView option_tags ||= "" html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name - if options.delete(:include_blank) - option_tags = content_tag(:option, '', :value => '').safe_concat(option_tags) + + if options.include?(:include_blank) + include_blank = options.delete(:include_blank) + if include_blank == true + include_blank = '' + end + + option_tags = content_tag(:option, include_blank, :value => '').safe_concat(option_tags) end if prompt = options.delete(:prompt) diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 771e3fefc3..5b9c1948db 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -224,6 +224,12 @@ class FormTagHelperTest < ActionView::TestCase expected = %() assert_dom_equal expected, actual end + + def test_select_tag_with_include_blank_string + actual = select_tag "places", "".html_safe, :include_blank => 'Choose' + expected = %() + assert_dom_equal expected, actual + end def test_select_tag_with_prompt actual = select_tag "places", "".html_safe, :prompt => "string" -- cgit v1.2.3 From 95acea5498f1e9ac43cf87b55578e0a8d576680b Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 25 Oct 2014 23:19:27 +0530 Subject: Clarify comments about sanitized_allowed_tags - Clarify that arguments are expected in array format. - Extension of https://github.com/rails/rails/pull/17390. - https://github.com/rails/rails/pull/17390 was targeted against 4-1-stable branch. This commit updates master. - [ci skip] --- actionview/lib/action_view/helpers/sanitize_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/sanitize_helper.rb b/actionview/lib/action_view/helpers/sanitize_helper.rb index 4f2db0a0c4..7cb55cc214 100644 --- a/actionview/lib/action_view/helpers/sanitize_helper.rb +++ b/actionview/lib/action_view/helpers/sanitize_helper.rb @@ -57,7 +57,7 @@ module ActionView # Add table tags to the default allowed tags # # class Application < Rails::Application - # config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td' + # config.action_view.sanitized_allowed_tags = ['table', 'tr', 'td'] # end # # Remove tags to the default allowed tags @@ -176,7 +176,7 @@ module ActionView # Replaces the allowed tags for the +sanitize+ helper. # # class Application < Rails::Application - # config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td' + # config.action_view.sanitized_allowed_tags = ['table', 'tr', 'td'] # end # -- cgit v1.2.3 From f28340a5ef3dafd3f96e7032b6b21352ebd11f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 25 Oct 2014 16:13:58 -0700 Subject: :scissors: --- actionview/lib/action_view/helpers/form_tag_helper.rb | 3 +-- actionview/test/template/form_tag_helper_test.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 74cfec962e..5aeb138f7a 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -133,13 +133,12 @@ module ActionView option_tags ||= "" html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name - if options.include?(:include_blank) include_blank = options.delete(:include_blank) if include_blank == true include_blank = '' end - + option_tags = content_tag(:option, include_blank, :value => '').safe_concat(option_tags) end diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 4844398c13..e8170d43e1 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -231,7 +231,7 @@ class FormTagHelperTest < ActionView::TestCase expected = %() assert_dom_equal expected, actual end - + def test_select_tag_with_include_blank_string actual = select_tag "places", "".html_safe, :include_blank => 'Choose' expected = %() -- cgit v1.2.3 From b2278aa1a0c02f8793587f625900504b447b4517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 25 Oct 2014 16:14:28 -0700 Subject: Use new hash syntax --- actionview/lib/action_view/helpers/form_tag_helper.rb | 5 +++-- actionview/test/template/form_tag_helper_test.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 5aeb138f7a..c0218fd55d 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -135,15 +135,16 @@ module ActionView if options.include?(:include_blank) include_blank = options.delete(:include_blank) + if include_blank == true include_blank = '' end - option_tags = content_tag(:option, include_blank, :value => '').safe_concat(option_tags) + option_tags = content_tag(:option, include_blank, value: '').safe_concat(option_tags) end if prompt = options.delete(:prompt) - option_tags = content_tag(:option, prompt, :value => '').safe_concat(option_tags) + option_tags = content_tag(:option, prompt, value: '').safe_concat(option_tags) end content_tag :select, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys) diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index e8170d43e1..f8fd642809 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -233,7 +233,7 @@ class FormTagHelperTest < ActionView::TestCase end def test_select_tag_with_include_blank_string - actual = select_tag "places", "".html_safe, :include_blank => 'Choose' + actual = select_tag "places", "".html_safe, include_blank: 'Choose' expected = %() assert_dom_equal expected, actual end -- cgit v1.2.3 From 450743cf56125d153b64c3509e75b0e4f86851d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 25 Oct 2014 16:20:44 -0700 Subject: Add CHANGELOG entry for #17064 --- actionview/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionview') diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 8ac74dc938..e388e6ecd3 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,9 @@ +* Update `select_tag` to work correctly with `:include_blank` option passing a string. + + Fixes #16483. + + *Frank Groeneveld* + * Changed the meaning of `render "foo/bar"`. Previously, calling `render "foo/bar"` in a controller action is equivalent -- cgit v1.2.3 From 44260581bec06e4ce05f3dd838c8b4736fc7eb1d Mon Sep 17 00:00:00 2001 From: Ryunosuke SATO Date: Wed, 29 Oct 2014 00:32:43 +0900 Subject: Fix doc markup for `NumberHelper` [ci skip] The character "*" is unnecessary in option candidates. This incorrect markup was injected in e8c9aeca . --- actionview/lib/action_view/helpers/number_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/number_helper.rb b/actionview/lib/action_view/helpers/number_helper.rb index 7220bded3c..f66dbfe7d3 100644 --- a/actionview/lib/action_view/helpers/number_helper.rb +++ b/actionview/lib/action_view/helpers/number_helper.rb @@ -306,12 +306,12 @@ module ActionView # string containing an i18n scope where to find this hash. It # might have the following keys: # * *integers*: :unit, :ten, - # *:hundred, :thousand, :million, - # *:billion, :trillion, - # *:quadrillion + # :hundred, :thousand, :million, + # :billion, :trillion, + # :quadrillion # * *fractionals*: :deci, :centi, - # *:mili, :micro, :nano, - # *:pico, :femto + # :mili, :micro, :nano, + # :pico, :femto # * :format - Sets the format of the output string # (defaults to "%n %u"). The field types are: # * %u - The quantifier (ex.: 'thousand') -- cgit v1.2.3 From b3bfa361c503e107aff4dee5edf79bd7fd3d3725 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 28 Oct 2014 16:17:33 -0700 Subject: let's warn with heredocs The current style for warning messages without newlines uses concatenation of string literals with manual trailing spaces where needed. Heredocs have better readability, and with `squish` we can still produce a single line. This is a similar use case to the one that motivated defining `strip_heredoc`, heredocs are super clean. --- actionview/lib/action_view/template/resolver.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index d77421d5f5..b65507f4a2 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -1,6 +1,7 @@ require "pathname" require "active_support/core_ext/class" require "active_support/core_ext/module/attribute_accessors" +require 'active_support/core_ext/string/filters' require "action_view/template" require "thread" require "thread_safe" @@ -251,9 +252,10 @@ module ActionView extension = pieces.pop unless extension - message = "The file #{path} did not specify a template handler. The default is currently ERB, " \ - "but will change to RAW in the future." - ActiveSupport::Deprecation.warn message + ActiveSupport::Deprecation.warn(<<-MSG.squish) + The file #{path} did not specify a template handler. The default is + currently ERB, but will change to RAW in the future. + MSG end handler = Template.handler_for_extension(extension) -- cgit v1.2.3 From e595d91ac2c07371b441f8b04781e7c03ac44135 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 28 Oct 2014 17:33:36 -0700 Subject: edit pass over all warnings This patch uniformizes warning messages. I used the most common style already present in the code base: * Capitalize the first word. * End the message with a full stop. * "Rails 5" instead of "Rails 5.0". * Backticks for method names and inline code. Also, converted a few long strings into the new heredoc convention. --- actionview/lib/action_view/view_paths.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/view_paths.rb b/actionview/lib/action_view/view_paths.rb index 80a41f2418..2e203a7590 100644 --- a/actionview/lib/action_view/view_paths.rb +++ b/actionview/lib/action_view/view_paths.rb @@ -38,7 +38,11 @@ module ActionView def handle_deprecated_parent_prefixes # TODO: remove in 4.3/5.0. return unless respond_to?(:parent_prefixes) - ActiveSupport::Deprecation.warn "Overriding ActionController::Base::parent_prefixes is deprecated, override .local_prefixes instead." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Overriding `ActionController::Base::parent_prefixes` is deprecated, + override `.local_prefixes` instead. + MSG + local_prefixes + parent_prefixes end end -- cgit v1.2.3 From 724db9eb6236eb21051d85438b62e452765ee291 Mon Sep 17 00:00:00 2001 From: Pablo Herrero Date: Wed, 29 Oct 2014 20:51:32 -0300 Subject: Fix typo at form_helper docs [ci skip] --- actionview/lib/action_view/helpers/form_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 038f9e384b..03f80ff360 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1231,8 +1231,8 @@ module ActionView # end # # The above code creates a new method +div_radio_button+ which wraps a div - # around the a new radio button. Note that when options are passed in, you - # must called +objectify_options+ in order for the model object to get + # around the new radio button. Note that when options are passed in, you + # must call +objectify_options+ in order for the model object to get # correctly passed to the method. If +objectify_options+ is not called, # then the newly created helper will not be linked back to the model. # -- cgit v1.2.3 From 4daebedcc41e35079c47d5f130f5c7ad12db8bbb Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Thu, 30 Oct 2014 14:09:21 -0700 Subject: Prepare for 4.2.0.beta4 release --- actionview/lib/action_view/gem_version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/gem_version.rb b/actionview/lib/action_view/gem_version.rb index 076b8ec30b..752eafee3c 100644 --- a/actionview/lib/action_view/gem_version.rb +++ b/actionview/lib/action_view/gem_version.rb @@ -8,7 +8,7 @@ module ActionView MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end -- cgit v1.2.3 From f0570a3d3fa85ba0153d61c90bad6db648144256 Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Mon, 24 Feb 2014 17:05:42 +0100 Subject: Honor public/private in ActionView::Helpers::Tags::Base#value * use public_send instead of send to avoid calling private methods in form helpers --- actionview/lib/action_view/helpers/tags/base.rb | 2 +- actionview/test/template/form_helper_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/tags/base.rb b/actionview/lib/action_view/helpers/tags/base.rb index 8607da301c..f8abb19698 100644 --- a/actionview/lib/action_view/helpers/tags/base.rb +++ b/actionview/lib/action_view/helpers/tags/base.rb @@ -25,7 +25,7 @@ module ActionView private def value(object) - object.send @method_name if object + object.public_send @method_name if object end def value_before_type_cast(object) diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index f2238d1443..36e3e64688 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -158,6 +158,12 @@ class FormHelperTest < ActionView::TestCase assert_raise(NotImplementedError) { FooTag.new.render } end + def test_tags_base_value_honors_public_private + test_object = Class.new { private def my_method ; end }.new + tag = ActionView::Helpers::Tags::Base.new 'test_object', :my_method, nil + assert_raise(NoMethodError) { tag.send :value, test_object } + end + def test_label assert_dom_equal('', label("post", "title")) assert_dom_equal( -- cgit v1.2.3 From 1ff67d82861c11cba7896e39536565ce93d0fc08 Mon Sep 17 00:00:00 2001 From: agius Date: Fri, 31 Oct 2014 10:45:45 -0700 Subject: Use public_send for form tags --- actionview/test/template/form_helper_test.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'actionview') diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 36e3e64688..4169408cf9 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -154,6 +154,18 @@ class FormHelperTest < ActionView::TestCase def initialize; end end + class FooObject + + def method_missing(*args) + nil + end + + private + def private_property + raise "This method should not be called." + end + end + def test_tags_base_child_without_render_method assert_raise(NotImplementedError) { FooTag.new.render } end @@ -1791,6 +1803,21 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_tags_do_not_call_private_properties_on_form_object + obj = FooObject.new + form_for(obj, as: "other_name", url: '/', html: { id: "edit-other-name" }) do |f| + concat f.hidden_field(:private_property) + concat f.submit('Create Foo') + end + + expected = whole_form("/", "edit-other-name", "new_other_name", method: "post") do + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + def test_form_for_with_method_as_part_of_html_options form_for(@post, url: '/', html: { id: 'create-post', method: :delete }) do |f| concat f.text_field(:title) -- cgit v1.2.3 From 0d6a56d63525c708e398eb99bb56eea18444d751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 31 Oct 2014 16:41:51 -0200 Subject: Improve test of private properties of objects in form tags --- actionview/test/template/form_helper_test.rb | 37 +++++++--------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'actionview') diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 4169408cf9..4bbbdf4fb1 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -154,28 +154,10 @@ class FormHelperTest < ActionView::TestCase def initialize; end end - class FooObject - - def method_missing(*args) - nil - end - - private - def private_property - raise "This method should not be called." - end - end - def test_tags_base_child_without_render_method assert_raise(NotImplementedError) { FooTag.new.render } end - def test_tags_base_value_honors_public_private - test_object = Class.new { private def my_method ; end }.new - tag = ActionView::Helpers::Tags::Base.new 'test_object', :my_method, nil - assert_raise(NoMethodError) { tag.send :value, test_object } - end - def test_label assert_dom_equal('', label("post", "title")) assert_dom_equal( @@ -1804,18 +1786,17 @@ class FormHelperTest < ActionView::TestCase end def test_form_tags_do_not_call_private_properties_on_form_object - obj = FooObject.new - form_for(obj, as: "other_name", url: '/', html: { id: "edit-other-name" }) do |f| - concat f.hidden_field(:private_property) - concat f.submit('Create Foo') - end + obj = Class.new do + private - expected = whole_form("/", "edit-other-name", "new_other_name", method: "post") do - "" + - "" - end + def private_property + raise "This method should not be called." + end + end.new - assert_dom_equal expected, output_buffer + form_for(obj, as: "other_name", url: '/', html: { id: "edit-other-name" }) do |f| + assert_raise(NoMethodError) { f.hidden_field(:private_property) } + end end def test_form_for_with_method_as_part_of_html_options -- cgit v1.2.3 From 861b70e92f4a1fc0e465ffcf2ee62680519c8f6f Mon Sep 17 00:00:00 2001 From: Pablo Herrero Date: Sat, 1 Nov 2014 20:16:03 -0300 Subject: Call gsub with a Regexp instead of a String for better performance --- actionview/lib/action_view/helpers/tag_helper.rb | 2 +- actionview/lib/action_view/template/handlers/raw.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb index 385d57a7a5..b2038576a2 100644 --- a/actionview/lib/action_view/helpers/tag_helper.rb +++ b/actionview/lib/action_view/helpers/tag_helper.rb @@ -123,7 +123,7 @@ module ActionView # cdata_section("hello]]>world") # # => world]]> def cdata_section(content) - splitted = content.to_s.gsub(']]>', ']]]]>') + splitted = content.to_s.gsub(/\]\]\>/, ']]]]>') "".html_safe end diff --git a/actionview/lib/action_view/template/handlers/raw.rb b/actionview/lib/action_view/template/handlers/raw.rb index 0c0d1fffcb..397c86014a 100644 --- a/actionview/lib/action_view/template/handlers/raw.rb +++ b/actionview/lib/action_view/template/handlers/raw.rb @@ -2,7 +2,7 @@ module ActionView module Template::Handlers class Raw def call(template) - escaped = template.source.gsub(':', '\:') + escaped = template.source.gsub(/:/, '\:') '%q:' + escaped + ':;' end -- cgit v1.2.3