Do not override attribute value selection in collection select. Closes #325

Conflicts:

	test/inputs_test.rb
This commit is contained in:
Carlos Antonio da Silva 2011-09-15 20:17:23 -03:00
parent 183e687777
commit 42307c1f3f
3 changed files with 15 additions and 2 deletions

View File

@ -6,6 +6,7 @@
* bug fix
* Fallback to default label when block is provided (github.com/pivotal-casebook)
* Do not override default selection through attribute value in collection select when label/value methods are lambdas
== 1.5.0

View File

@ -178,8 +178,11 @@ class ActionView::Helpers::FormBuilder
[value, text, selected, disabled]
end
options[:disabled] = collection.map(&:pop).compact
options[:selected] = collection.map(&:pop).compact
[:disabled, :selected].each do |option|
option_value = collection.map(&:pop).compact
options[option] = option_value if option_value.present?
end
value_method, text_method = :first, :last
end

View File

@ -298,4 +298,13 @@ class CollectionInputTest < ActionView::TestCase
assert_select 'select option[value=Antonio]', 'ANTONIO'
assert_no_select 'select option[value=Antonio][selected]'
end
test 'input should not override default selection through attribute value with label method as lambda for collection select' do
@user.name = "Carlos"
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
:label_method => lambda { |x| x.upcase }
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
assert_select 'select option[value=Antonio]', 'ANTONIO'
assert_no_select 'select option[value=Antonio][selected]'
end
end