Skip to content

Commit

Permalink
collection input that uses automatic collection translation properly …
Browse files Browse the repository at this point in the history
…sets checked values

closes #971
  • Loading branch information
nashby committed Dec 31, 2013
1 parent 6ce9a15 commit 03396db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit 03396db

Please sign in to comment.