Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collection input that uses automatic collection translation properly sets checked values #972

Merged
merged 1 commit into from
Jan 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
when the `:html5` is set to `true` [@volmer](https://github.com/volmer)

### bug fix
* Collection input that uses automatic collection translation properly sets checked values.
Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)

## 3.0.1
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_form/inputs/collection_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def collection_includes_basic_objects?(collection_classes)
def translate_collection
if translated_collection = translate(:options)
@collection = collection.map do |key|
[translated_collection[key] || key, key]
[translated_collection[key] || key, key.to_s]
end
true
end
Expand Down
14 changes: 14 additions & 0 deletions test/inputs/collection_check_boxes_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
end
end

test 'input that uses automatic collection translation for check_boxes should properly set checked values' do
store_translations(:en, simple_form: { options: { defaults: {
gender: { male: 'Male', female: 'Female'}
} } } ) do
@user.gender = 'male'

with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
assert_select 'input[type=checkbox][value=male][checked=checked]'
assert_select 'input[type=checkbox][value=female]'
assert_select 'label.collection_check_boxes', 'Male'
assert_select 'label.collection_check_boxes', 'Female'
end
end

test 'input check boxes does not wrap the collection by default' do
with_input_for @user, :active, :check_boxes

Expand Down