aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2019-05-28 08:20:21 -0700
committerGitHub <noreply@github.com>2019-05-28 08:20:21 -0700
commit350ae29635c7e1e7a66a75e2d070259042ede3ea (patch)
tree679a84c90af608966784e7576c1540f206a8c85a /actionview
parentfc530d866809403ed9259028336db8103b00ac62 (diff)
parenta4229a534ff237443b445de9aec0310c0f388b56 (diff)
downloadrails-350ae29635c7e1e7a66a75e2d070259042ede3ea.tar.gz
rails-350ae29635c7e1e7a66a75e2d070259042ede3ea.tar.bz2
rails-350ae29635c7e1e7a66a75e2d070259042ede3ea.zip
Merge pull request #36324 from yoones/fix-unexpected-select-tag-delete-behavior
Fix unexpected select_tag delete behavior when include_blank is present
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md3
-rw-r--r--actionview/lib/action_view/helpers/form_tag_helper.rb3
-rw-r--r--actionview/test/template/form_tag_helper_test.rb7
3 files changed, 12 insertions, 1 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index dcd3e33c46..a1e94384bd 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,6 @@
+* Fix `select_tag` so that it doesn't change `options` when `include_blank` is present.
+
+ *Younes SERRAJ*
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/actionview/CHANGELOG.md) for previous changes.
diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb
index 5d4ff36425..c93ead9653 100644
--- a/actionview/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/form_tag_helper.rb
@@ -137,7 +137,8 @@ module ActionView
html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name
if options.include?(:include_blank)
- include_blank = options.delete(:include_blank)
+ include_blank = options[:include_blank]
+ options = options.except(:include_blank)
options_for_blank_options_tag = { value: "" }
if include_blank == true
diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb
index 9ece9f3ad1..70c5ae6771 100644
--- a/actionview/test/template/form_tag_helper_test.rb
+++ b/actionview/test/template/form_tag_helper_test.rb
@@ -301,6 +301,13 @@ class FormTagHelperTest < ActionView::TestCase
assert_dom_equal expected, actual
end
+ def test_select_tag_with_include_blank_doesnt_change_options
+ options = { include_blank: true, prompt: "string" }
+ expected_options = options.dup
+ select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), options
+ expected_options.each { |k, v| assert_equal v, options[k] }
+ end
+
def test_select_tag_with_include_blank_false
actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), include_blank: false
expected = %(<select id="places" name="places"><option>Home</option><option>Work</option><option>Pub</option></select>)