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 Jan 4, 2014
1 parent c94c1da commit 321f849
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,8 @@
* Add `include_default_input_wrapper_class` config [@luizcosta](https://github.com/luizcosta)

### 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)
* Use the given name in `input_html` for the hidden field in `collection_check_boxes` [@angelic](https://github.com/angelic)
* Add "checkbox" class to the label of boolean input when there is no `:label`
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_form/inputs/collection_input.rb
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
Expand Up @@ -47,6 +47,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 321f849

Please sign in to comment.