mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fixed options_for_select on selected line issue #624 [Florian Weber]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@911 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Fixed options_for_select on selected line issue #624 [Florian Weber]
|
||||
|
||||
* Added CaptureHelper with CaptureHelper#capture and CaptureHelper#content_for. See documentation in helper #837 [Tobias Luetke]
|
||||
|
||||
* Fixed :anchor use in url_for #821 [Nicholas Seckar]
|
||||
|
||||
@@ -83,6 +83,7 @@ module ActionView
|
||||
options_for_select = container.inject([]) do |options, element|
|
||||
if element.respond_to?(:first) && element.respond_to?(:last)
|
||||
is_selected = ( (selected.respond_to?(:include?) ? selected.include?(element.last) : element.last == selected) )
|
||||
is_selected = ( (selected.respond_to?(:include?) && !selected.is_a?(String) ? selected.include?(element.last) : element.last == selected) )
|
||||
if is_selected
|
||||
options << "<option value=\"#{html_escape(element.last.to_s)}\" selected=\"selected\">#{html_escape(element.first.to_s)}</option>"
|
||||
else
|
||||
@@ -90,6 +91,7 @@ module ActionView
|
||||
end
|
||||
else
|
||||
is_selected = ( (selected.respond_to?(:include?) ? selected.include?(element) : element == selected) )
|
||||
is_selected = ( (selected.respond_to?(:include?) && !selected.is_a?(String) ? selected.include?(element) : element == selected) )
|
||||
options << ((is_selected) ? "<option selected=\"selected\">#{html_escape(element.to_s)}</option>" : "<option>#{html_escape(element.to_s)}</option>")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -94,6 +94,17 @@ class FormOptionsHelperTest < Test::Unit::TestCase
|
||||
)
|
||||
end
|
||||
|
||||
def test_array_options_for_string_include_in_other_string_bug_fix
|
||||
assert_equal(
|
||||
"<option>ruby</option>\n<option selected=\"selected\">rubyonrails</option>",
|
||||
options_for_select([ "ruby", "rubyonrails" ], "rubyonrails")
|
||||
)
|
||||
assert_equal(
|
||||
"<option selected=\"selected\">ruby</option>\n<option>rubyonrails</option>",
|
||||
options_for_select([ "ruby", "rubyonrails" ], "ruby")
|
||||
)
|
||||
end
|
||||
|
||||
def test_hash_options_for_select
|
||||
assert_equal(
|
||||
"<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\">$</option>",
|
||||
|
||||
Reference in New Issue
Block a user