From 03396dbb0735b043bf343018588639a46e25f9b2 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Tue, 31 Dec 2013 22:31:17 +0300 Subject: [PATCH] collection input that uses automatic collection translation properly sets checked values closes #971 --- CHANGELOG.md | 2 ++ lib/simple_form/inputs/collection_input.rb | 2 +- test/inputs/collection_check_boxes_input_test.rb | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00949065..cfc2e005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb index 3fc29850..2b1eae56 100644 --- a/lib/simple_form/inputs/collection_input.rb +++ b/lib/simple_form/inputs/collection_input.rb @@ -90,7 +90,7 @@ module SimpleForm 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 diff --git a/test/inputs/collection_check_boxes_input_test.rb b/test/inputs/collection_check_boxes_input_test.rb index 6254d1a3..41552cf2 100644 --- a/test/inputs/collection_check_boxes_input_test.rb +++ b/test/inputs/collection_check_boxes_input_test.rb @@ -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