Permalink
Browse files

collection input that uses automatic collection translation properly …

…sets checked values

closes #971
  • Loading branch information...
1 parent 6ce9a15 commit 03396dbb0735b043bf343018588639a46e25f9b2 @nashby nashby committed Dec 31, 2013
Showing with 17 additions and 1 deletion.
  1. +2 −0 CHANGELOG.md
  2. +1 −1 lib/simple_form/inputs/collection_input.rb
  3. +14 −0 test/inputs/collection_check_boxes_input_test.rb
View
@@ -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
@@ -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
@@ -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

0 comments on commit 03396db

Please sign in to comment.