From fb1f52dbc5855e3e33bc441ec89c9bd519d416cb Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Wed, 13 Nov 2013 14:44:42 -0200 Subject: [PATCH 01/21] Support to date, datetime and time inputs. I changed `DateTimeInput` to support the new HTML5 form helpers that comes with Rails 4 (`date_input`, `datetime_input` and `time_input`) instead of rendering datetime selects: For example, this input: ```erb <%= f.input :born_on, as: :date %> ``` Will render: ```html ``` Datetime selects are still present, but only when HTML5 compatibility is disabled. It's also possible to render selects even with HTML5 on, by setting the `html5` option to false. If we wanted to use an old date select on the example above, we should do: ```erb <%= f.input :born_on, as: :date, html5: false %> ``` Closes #844. --- lib/simple_form/inputs/date_time_input.rb | 16 ++- test/inputs/datetime_input_test.rb | 137 +++++++++++++++++----- 2 files changed, 124 insertions(+), 29 deletions(-) diff --git a/lib/simple_form/inputs/date_time_input.rb b/lib/simple_form/inputs/date_time_input.rb index 64fd326f..ca40b383 100644 --- a/lib/simple_form/inputs/date_time_input.rb +++ b/lib/simple_form/inputs/date_time_input.rb @@ -1,8 +1,14 @@ module SimpleForm module Inputs class DateTimeInput < Base + enable :html5 + def input - @builder.send(:"#{input_type}_select", attribute_name, input_options, input_html_options) + if use_html5_inputs? + @builder.send(:"#{input_type}_field", attribute_name, input_html_options) + else + @builder.send(:"#{input_type}_select", attribute_name, input_options, input_html_options) + end end private @@ -19,6 +25,14 @@ module SimpleForm position = ActionView::Helpers::DateTimeSelector::POSITION[position] "#{attribute_name}_#{position}i" end + + def use_html5_inputs? + if input_options.key?(:html5) + input_options[:html5] + else + html5? + end + end end end end diff --git a/test/inputs/datetime_input_test.rb b/test/inputs/datetime_input_test.rb index b1a77354..6c388764 100644 --- a/test/inputs/datetime_input_test.rb +++ b/test/inputs/datetime_input_test.rb @@ -1,18 +1,69 @@ # encoding: UTF-8 require 'test_helper' -# Tests for all different kinds of inputs. -class DateTimeInputTest < ActionView::TestCase - # DateTime input - test 'input should generate a datetime select by default for datetime attributes' do +# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper. +class DateTimeInputWithHtml5Test < ActionView::TestCase + test 'input should generate a datetime input for datetime attributes' do with_input_for @user, :created_at, :datetime - 1.upto(5) do |i| - assert_select "form select.datetime#user_created_at_#{i}i" + + assert_select 'input[type="datetime"]' + end + + test 'input should generate a datetime select for datetime attributes if HTML5 compatibility is explicitly disabled' do + with_input_for @user, :created_at, :datetime, html5: false + + assert_select 'select.datetime' + end + + test 'input should generate a date input for date attributes' do + with_input_for @user, :born_at, :date + + assert_select 'input[type="date"]' + end + + test 'input should generate a date select for date attributes if HTML5 compatibility is explicitly disabled' do + with_input_for @user, :born_at, :date, html5: false + + assert_select 'select.date' + end + + test 'input should generate a time input for time attributes' do + with_input_for @user, :delivery_time, :time + + assert_select 'input[type="time"]' + end + + test 'input should generate a time select for time attributes if HTML5 compatibility is explicitly disabled' do + with_input_for @user, :delivery_time, :time, html5: false + + assert_select 'select.time' + end + + test 'input should generate required html attribute' do + with_input_for @user, :delivery_time, :time, required: true + assert_select 'input.required' + assert_select 'input[required]' + end + + test 'input should have an aria-required html attribute' do + with_input_for @user, :delivery_time, :time, required: true + assert_select 'input[aria-required=true]' + end +end + +# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper. +class DateTimeInputWithoutHtml5Test < ActionView::TestCase + test 'input should generate a datetime select by default for datetime attributes' do + swap_wrapper do + with_input_for @user, :created_at, :datetime + 1.upto(5) do |i| + assert_select "form select.datetime#user_created_at_#{i}i" + end end end test 'input should be able to pass options to datetime select' do - with_input_for @user, :created_at, :datetime, + with_input_for @user, :created_at, :datetime, html5: false, disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' } assert_select 'select.datetime[disabled=disabled]' @@ -21,16 +72,26 @@ class DateTimeInputTest < ActionView::TestCase assert_select 'select.datetime option', 'dia' end + test 'input should generate a datetime input for datetime attributes if HTML5 compatibility is explicitly enabled' do + swap_wrapper do + with_input_for @user, :created_at, :datetime, html5: true + + assert_select 'input[type="datetime"]' + end + end + test 'input should generate a date select for date attributes' do - with_input_for @user, :born_at, :date - assert_select 'select.date#user_born_at_1i' - assert_select 'select.date#user_born_at_2i' - assert_select 'select.date#user_born_at_3i' - assert_no_select 'select.date#user_born_at_4i' + swap_wrapper do + with_input_for @user, :born_at, :date + assert_select 'select.date#user_born_at_1i' + assert_select 'select.date#user_born_at_2i' + assert_select 'select.date#user_born_at_3i' + assert_no_select 'select.date#user_born_at_4i' + end end test 'input should be able to pass options to date select' do - with_input_for @user, :born_at, :date, as: :date, + with_input_for @user, :born_at, :date, as: :date, html5: false, disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' } assert_select 'select.date[disabled=disabled]' @@ -40,21 +101,31 @@ class DateTimeInputTest < ActionView::TestCase end test 'input should be able to pass :default to date select' do - with_input_for @user, :born_at, :date, default: Date.today + with_input_for @user, :born_at, :date, default: Date.today, html5: false assert_select "select.date option[value=#{Date.today.year}][selected=selected]" end + test 'input should generate a date input for date attributes if HTML5 compatibility is explicitly enabled' do + swap_wrapper do + with_input_for @user, :born_at, :date, html5: true + + assert_select 'input[type="date"]' + end + end + test 'input should generate a time select for time attributes' do - with_input_for @user, :delivery_time, :time - assert_select 'input[type=hidden]#user_delivery_time_1i' - assert_select 'input[type=hidden]#user_delivery_time_2i' - assert_select 'input[type=hidden]#user_delivery_time_3i' - assert_select 'select.time#user_delivery_time_4i' - assert_select 'select.time#user_delivery_time_5i' + swap_wrapper do + with_input_for @user, :delivery_time, :time + assert_select 'input[type=hidden]#user_delivery_time_1i' + assert_select 'input[type=hidden]#user_delivery_time_2i' + assert_select 'input[type=hidden]#user_delivery_time_3i' + assert_select 'select.time#user_delivery_time_4i' + assert_select 'select.time#user_delivery_time_5i' + end end test 'input should be able to pass options to time select' do - with_input_for @user, :delivery_time, :time, required: true, + with_input_for @user, :delivery_time, :time, required: true, html5: false, disabled: true, prompt: { hour: 'hora', minute: 'minuto' } assert_select 'select.time[disabled=disabled]' @@ -62,43 +133,53 @@ class DateTimeInputTest < ActionView::TestCase assert_select 'select.time option', 'minuto' end + test 'input should generate a time input for time attributes if HTML5 compatibility is explicitly enabled' do + swap_wrapper do + with_input_for @user, :delivery_time, :time, html5: true + + assert_select 'input[type="time"]' + end + end + test 'label should use i18n to get target for date input type' do store_translations(:en, date: { order: ['month', 'day', 'year'] }) do - with_input_for :project, :created_at, :date + with_input_for :project, :created_at, :date, html5: false assert_select 'label[for=project_created_at_2i]' end end test 'label should use i18n to get target for datetime input type' do store_translations(:en, date: { order: ['month', 'day', 'year'] }) do - with_input_for :project, :created_at, :datetime + with_input_for :project, :created_at, :datetime, html5: false assert_select 'label[for=project_created_at_2i]' end end test 'label should use order to get target when date input type' do - with_input_for :project, :created_at, :date, order: ['month', 'year', 'day'] + with_input_for :project, :created_at, :date, order: ['month', 'year', 'day'], html5: false assert_select 'label[for=project_created_at_2i]' end test 'label should use order to get target when datetime input type' do - with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day'] + with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day'], html5: false assert_select 'label[for=project_created_at_2i]' end test 'label should point to first option when time input type' do - with_input_for :project, :created_at, :time + with_input_for :project, :created_at, :time, html5: false assert_select 'label[for=project_created_at_4i]' end test 'date time input should generate required html attribute' do - with_input_for @user, :delivery_time, :time, required: true + skip + with_input_for @user, :delivery_time, :time, required: true, html5: false assert_select 'select.required' assert_select 'select[required]' end test 'date time input has an aria-required html attribute' do - with_input_for @user, :delivery_time, :time, required: true + skip + with_input_for @user, :delivery_time, :time, required: true, html5: false assert_select 'select.required' assert_select 'select[aria-required=true]' end From 2b1dcd16ba8dafeea41f8af779a02619e2b2ed94 Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Wed, 13 Nov 2013 15:30:43 -0200 Subject: [PATCH 02/21] Assert `input` tags instead of `select` for datetime attributes. --- test/form_builder/general_test.rb | 10 +++++----- test/inputs/disabled_test.rb | 4 ++-- test/inputs/general_test.rb | 8 ++++---- test/inputs/readonly_test.rb | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/form_builder/general_test.rb b/test/form_builder/general_test.rb index 223732ac..2f780719 100644 --- a/test/form_builder/general_test.rb +++ b/test/form_builder/general_test.rb @@ -158,22 +158,22 @@ class FormBuilderTest < ActionView::TestCase test 'builder should generate date select for date columns' do with_form_for @user, :born_at - assert_select 'form select#user_born_at_1i.date' + assert_select 'form input#user_born_at.date' end test 'builder should generate time select for time columns' do with_form_for @user, :delivery_time - assert_select 'form select#user_delivery_time_4i.time' + assert_select 'form input#user_delivery_time.time' end test 'builder should generate datetime select for datetime columns' do with_form_for @user, :created_at - assert_select 'form select#user_created_at_1i.datetime' + assert_select 'form input#user_created_at.datetime' end test 'builder should generate datetime select for timestamp columns' do with_form_for @user, :updated_at - assert_select 'form select#user_updated_at_1i.datetime' + assert_select 'form input#user_updated_at.datetime' end test 'builder should generate file for file columns' do @@ -406,7 +406,7 @@ class FormBuilderTest < ActionView::TestCase test 'builder should allow overriding input type when object is not present' do with_form_for :project, :created_at, as: :datetime - assert_select 'form select.datetime#project_created_at_1i' + assert_select 'form input.datetime#project_created_at' with_form_for :project, :budget, as: :decimal assert_select 'form input.decimal#project_budget' end diff --git a/test/inputs/disabled_test.rb b/test/inputs/disabled_test.rb index fef3cd36..9db6424b 100644 --- a/test/inputs/disabled_test.rb +++ b/test/inputs/disabled_test.rb @@ -18,12 +18,12 @@ class DisabledTest < ActionView::TestCase test 'date input should be disabled when disabled option is true' do with_input_for @user, :born_at, :date, disabled: true - assert_select 'select.date.disabled[disabled]' + assert_select 'input.date.disabled[disabled]' end test 'datetime input should be disabled when disabled option is true' do with_input_for @user, :created_at, :datetime, disabled: true - assert_select 'select.datetime.disabled[disabled]' + assert_select 'input.datetime.disabled[disabled]' end test 'string input should not be disabled when disabled option is false' do diff --git a/test/inputs/general_test.rb b/test/inputs/general_test.rb index 5b3e3da8..e21a9e1c 100644 --- a/test/inputs/general_test.rb +++ b/test/inputs/general_test.rb @@ -10,9 +10,9 @@ class InputTest < ActionView::TestCase with_input_for @user, :age, :integer assert_select 'input.integer' with_input_for @user, :born_at, :date - assert_select 'select.date' + assert_select 'input.date' with_input_for @user, :created_at, :datetime - assert_select 'select.datetime' + assert_select 'input.datetime' end test 'string input should generate autofocus attribute when autofocus option is true' do @@ -48,12 +48,12 @@ class InputTest < ActionView::TestCase test 'date input should generate autofocus attribute when autofocus option is true' do with_input_for @user, :born_at, :date, autofocus: true - assert_select 'select.date[autofocus]' + assert_select 'input.date[autofocus]' end test 'datetime input should generate autofocus attribute when autofocus option is true' do with_input_for @user, :created_at, :datetime, autofocus: true - assert_select 'select.datetime[autofocus]' + assert_select 'input.datetime[autofocus]' end test 'string input should generate autofocus attribute when autofocus option is false' do diff --git a/test/inputs/readonly_test.rb b/test/inputs/readonly_test.rb index c6f4070a..c99ecc13 100644 --- a/test/inputs/readonly_test.rb +++ b/test/inputs/readonly_test.rb @@ -18,12 +18,12 @@ class ReadonlyTest < ActionView::TestCase test 'date input should generate readonly elements when readonly option is true' do with_input_for @user, :born_at, :date, readonly: true - assert_select 'select.date.readonly[readonly]' + assert_select 'input.date.readonly[readonly]' end test 'datetime input should generate readonly elements when readonly option is true' do with_input_for @user, :created_at, :datetime, readonly: true - assert_select 'select.datetime.readonly[readonly]' + assert_select 'input.datetime.readonly[readonly]' end test 'string input should generate readonly elements when readonly option is false' do From a7c9575a4e524a4349933cc8ce718b05e83dd91b Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Wed, 13 Nov 2013 16:50:09 -0200 Subject: [PATCH 03/21] Do not assert `required` HTML5 attribute when HTML5 compatibility is disabled. --- test/inputs/datetime_input_test.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/inputs/datetime_input_test.rb b/test/inputs/datetime_input_test.rb index 6c388764..bed96d5a 100644 --- a/test/inputs/datetime_input_test.rb +++ b/test/inputs/datetime_input_test.rb @@ -169,18 +169,4 @@ class DateTimeInputWithoutHtml5Test < ActionView::TestCase with_input_for :project, :created_at, :time, html5: false assert_select 'label[for=project_created_at_4i]' end - - test 'date time input should generate required html attribute' do - skip - with_input_for @user, :delivery_time, :time, required: true, html5: false - assert_select 'select.required' - assert_select 'select[required]' - end - - test 'date time input has an aria-required html attribute' do - skip - with_input_for @user, :delivery_time, :time, required: true, html5: false - assert_select 'select.required' - assert_select 'select[aria-required=true]' - end end From f345328b81392b4feb483eb5a6eb992b8152bfd7 Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Wed, 13 Nov 2013 18:25:41 -0200 Subject: [PATCH 04/21] Add a CHANGELOG entry regarding datetime inputs. --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56620b9b..2788c87a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## master +### enchancements + * Map `datetime`, `date` and `time` input types to their respective HTML5 input tags + when HTML5 compatibility is enabled. To render the classic datetime selects in HTML5 + form wrappers, set the `:html5` option to `false`. [@volmer](https://github.com/volmer) + ### bug fix * Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby) From 5dff6f29ae2b564db3fa9599303d3c2d6f5f2a92 Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Fri, 15 Nov 2013 16:46:43 -0200 Subject: [PATCH 05/21] Remove unecessary `enable` call. --- lib/simple_form/inputs/date_time_input.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/simple_form/inputs/date_time_input.rb b/lib/simple_form/inputs/date_time_input.rb index ca40b383..aa8f14e7 100644 --- a/lib/simple_form/inputs/date_time_input.rb +++ b/lib/simple_form/inputs/date_time_input.rb @@ -1,8 +1,6 @@ module SimpleForm module Inputs class DateTimeInput < Base - enable :html5 - def input if use_html5_inputs? @builder.send(:"#{input_type}_field", attribute_name, input_html_options) From 5590f85ee10e97dc9840c47df8a5577726fe80b8 Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Sat, 16 Nov 2013 02:25:24 -0200 Subject: [PATCH 06/21] Use classic datetime selects unless HTML5 is explicitly enabled. --- lib/simple_form/inputs/date_time_input.rb | 2 +- test/form_builder/general_test.rb | 10 ++++---- test/inputs/datetime_input_test.rb | 28 +++++++++++------------ test/inputs/disabled_test.rb | 4 ++-- test/inputs/general_test.rb | 8 +++---- test/inputs/readonly_test.rb | 4 ++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/simple_form/inputs/date_time_input.rb b/lib/simple_form/inputs/date_time_input.rb index aa8f14e7..6c215c7b 100644 --- a/lib/simple_form/inputs/date_time_input.rb +++ b/lib/simple_form/inputs/date_time_input.rb @@ -28,7 +28,7 @@ module SimpleForm if input_options.key?(:html5) input_options[:html5] else - html5? + false end end end diff --git a/test/form_builder/general_test.rb b/test/form_builder/general_test.rb index 2f780719..223732ac 100644 --- a/test/form_builder/general_test.rb +++ b/test/form_builder/general_test.rb @@ -158,22 +158,22 @@ class FormBuilderTest < ActionView::TestCase test 'builder should generate date select for date columns' do with_form_for @user, :born_at - assert_select 'form input#user_born_at.date' + assert_select 'form select#user_born_at_1i.date' end test 'builder should generate time select for time columns' do with_form_for @user, :delivery_time - assert_select 'form input#user_delivery_time.time' + assert_select 'form select#user_delivery_time_4i.time' end test 'builder should generate datetime select for datetime columns' do with_form_for @user, :created_at - assert_select 'form input#user_created_at.datetime' + assert_select 'form select#user_created_at_1i.datetime' end test 'builder should generate datetime select for timestamp columns' do with_form_for @user, :updated_at - assert_select 'form input#user_updated_at.datetime' + assert_select 'form select#user_updated_at_1i.datetime' end test 'builder should generate file for file columns' do @@ -406,7 +406,7 @@ class FormBuilderTest < ActionView::TestCase test 'builder should allow overriding input type when object is not present' do with_form_for :project, :created_at, as: :datetime - assert_select 'form input.datetime#project_created_at' + assert_select 'form select.datetime#project_created_at_1i' with_form_for :project, :budget, as: :decimal assert_select 'form input.decimal#project_budget' end diff --git a/test/inputs/datetime_input_test.rb b/test/inputs/datetime_input_test.rb index bed96d5a..d0528b1b 100644 --- a/test/inputs/datetime_input_test.rb +++ b/test/inputs/datetime_input_test.rb @@ -3,50 +3,50 @@ require 'test_helper' # Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper. class DateTimeInputWithHtml5Test < ActionView::TestCase - test 'input should generate a datetime input for datetime attributes' do - with_input_for @user, :created_at, :datetime + test 'input should generate a datetime input for datetime attributes if HTML5 compatibility is explicitly enbled' do + with_input_for @user, :created_at, :datetime, html5: true assert_select 'input[type="datetime"]' end - test 'input should generate a datetime select for datetime attributes if HTML5 compatibility is explicitly disabled' do - with_input_for @user, :created_at, :datetime, html5: false + test 'input should generate a datetime select for datetime attributes' do + with_input_for @user, :created_at, :datetime assert_select 'select.datetime' end - test 'input should generate a date input for date attributes' do - with_input_for @user, :born_at, :date + test 'input should generate a date input for date attributes if HTML5 compatibility is explicitly enbled' do + with_input_for @user, :born_at, :date, html5: true assert_select 'input[type="date"]' end - test 'input should generate a date select for date attributes if HTML5 compatibility is explicitly disabled' do - with_input_for @user, :born_at, :date, html5: false + test 'input should generate a date select for date attributes' do + with_input_for @user, :born_at, :date assert_select 'select.date' end - test 'input should generate a time input for time attributes' do - with_input_for @user, :delivery_time, :time + test 'input should generate a time input for time attributes if HTML5 compatibility is explicitly enbled' do + with_input_for @user, :delivery_time, :time, html5: true assert_select 'input[type="time"]' end - test 'input should generate a time select for time attributes if HTML5 compatibility is explicitly disabled' do - with_input_for @user, :delivery_time, :time, html5: false + test 'input should generate a time select for time attributes' do + with_input_for @user, :delivery_time, :time assert_select 'select.time' end test 'input should generate required html attribute' do - with_input_for @user, :delivery_time, :time, required: true + with_input_for @user, :delivery_time, :time, required: true, html5: true assert_select 'input.required' assert_select 'input[required]' end test 'input should have an aria-required html attribute' do - with_input_for @user, :delivery_time, :time, required: true + with_input_for @user, :delivery_time, :time, required: true, html5: true assert_select 'input[aria-required=true]' end end diff --git a/test/inputs/disabled_test.rb b/test/inputs/disabled_test.rb index 9db6424b..fef3cd36 100644 --- a/test/inputs/disabled_test.rb +++ b/test/inputs/disabled_test.rb @@ -18,12 +18,12 @@ class DisabledTest < ActionView::TestCase test 'date input should be disabled when disabled option is true' do with_input_for @user, :born_at, :date, disabled: true - assert_select 'input.date.disabled[disabled]' + assert_select 'select.date.disabled[disabled]' end test 'datetime input should be disabled when disabled option is true' do with_input_for @user, :created_at, :datetime, disabled: true - assert_select 'input.datetime.disabled[disabled]' + assert_select 'select.datetime.disabled[disabled]' end test 'string input should not be disabled when disabled option is false' do diff --git a/test/inputs/general_test.rb b/test/inputs/general_test.rb index e21a9e1c..5b3e3da8 100644 --- a/test/inputs/general_test.rb +++ b/test/inputs/general_test.rb @@ -10,9 +10,9 @@ class InputTest < ActionView::TestCase with_input_for @user, :age, :integer assert_select 'input.integer' with_input_for @user, :born_at, :date - assert_select 'input.date' + assert_select 'select.date' with_input_for @user, :created_at, :datetime - assert_select 'input.datetime' + assert_select 'select.datetime' end test 'string input should generate autofocus attribute when autofocus option is true' do @@ -48,12 +48,12 @@ class InputTest < ActionView::TestCase test 'date input should generate autofocus attribute when autofocus option is true' do with_input_for @user, :born_at, :date, autofocus: true - assert_select 'input.date[autofocus]' + assert_select 'select.date[autofocus]' end test 'datetime input should generate autofocus attribute when autofocus option is true' do with_input_for @user, :created_at, :datetime, autofocus: true - assert_select 'input.datetime[autofocus]' + assert_select 'select.datetime[autofocus]' end test 'string input should generate autofocus attribute when autofocus option is false' do diff --git a/test/inputs/readonly_test.rb b/test/inputs/readonly_test.rb index c99ecc13..c6f4070a 100644 --- a/test/inputs/readonly_test.rb +++ b/test/inputs/readonly_test.rb @@ -18,12 +18,12 @@ class ReadonlyTest < ActionView::TestCase test 'date input should generate readonly elements when readonly option is true' do with_input_for @user, :born_at, :date, readonly: true - assert_select 'input.date.readonly[readonly]' + assert_select 'select.date.readonly[readonly]' end test 'datetime input should generate readonly elements when readonly option is true' do with_input_for @user, :created_at, :datetime, readonly: true - assert_select 'input.datetime.readonly[readonly]' + assert_select 'select.datetime.readonly[readonly]' end test 'string input should generate readonly elements when readonly option is false' do From df4efa2e935962d85a383868b11cca28c9060da7 Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Mon, 18 Nov 2013 22:23:27 -0200 Subject: [PATCH 07/21] Just `input_options[:html5]` is enough. --- lib/simple_form/inputs/date_time_input.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/simple_form/inputs/date_time_input.rb b/lib/simple_form/inputs/date_time_input.rb index 6c215c7b..0414ad2f 100644 --- a/lib/simple_form/inputs/date_time_input.rb +++ b/lib/simple_form/inputs/date_time_input.rb @@ -25,11 +25,7 @@ module SimpleForm end def use_html5_inputs? - if input_options.key?(:html5) - input_options[:html5] - else - false - end + input_options[:html5] end end end From 476bd96e37ab7f6613744730f637edcb781d73e8 Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Tue, 26 Nov 2013 20:00:17 -0200 Subject: [PATCH 08/21] Fix mapping table regarding datetime columns. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7b3dbcab..ad62cb4a 100644 --- a/README.md +++ b/README.md @@ -500,9 +500,9 @@ specifying the helper method in the column `Mapping` as the `as:` option. `float` | `input[type=number]` | `float` `decimal` | `input[type=number]` | `decimal` `range` | `input[type=range]` | - - `datetime` | `input[type=datetime]` | `datetime/timestamp` - `date` | `input[type=date]` | `date` - `time` | `input[type=time]` | `time` + `datetime` | `datetime select` | `datetime/timestamp` + `date` | `date select` | `date` + `time` | `time select` | `time` `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations From 8cbe9435212d77822663403bb4083da9f63ac58d Mon Sep 17 00:00:00 2001 From: Luiz HD Costa Date: Tue, 12 Nov 2013 20:18:52 -0200 Subject: [PATCH 09/21] Allow not including input wrapper class There could be faulty behavior when setting checkbox or radio class to the input wrapper, as in Bootstrap 3. Fixes #930 --- CHANGELOG.md | 1 + .../config/initializers/simple_form.rb | 4 ++++ lib/simple_form.rb | 4 ++++ .../inputs/collection_radio_buttons_input.rb | 2 +- .../inputs/collection_check_boxes_input_test.rb | 17 +++++++++++++++++ .../collection_radio_buttons_input_test.rb | 17 +++++++++++++++++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8ad938f..2ec6a8d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### enhancements * Add wrapper mapping per form basis [@rcillo](https://github.com/rcillo) and [@bernardoamc](https://github.com/bernardoamc) * Add `for` attribute to `label` when collections are rendered as radio or checkbox [@erichkist](https://github.com/erichkist), [@ulissesalmeida](https://github.com/ulissesalmeida) and [@fabioyamate](https://github.com/fabioyamate) + * Add `include_default_input_wrapper_class` config [@luizcosta](https://github.com/luizcosta) ### bug fix * Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby) diff --git a/lib/generators/simple_form/templates/config/initializers/simple_form.rb b/lib/generators/simple_form/templates/config/initializers/simple_form.rb index ecd67dc2..328bea0c 100644 --- a/lib/generators/simple_form/templates/config/initializers/simple_form.rb +++ b/lib/generators/simple_form/templates/config/initializers/simple_form.rb @@ -142,4 +142,8 @@ SimpleForm.setup do |config| # Default class for inputs # config.input_class = nil + + # Defines if the default input wrapper class should be included in radio + # collection wrappers. + # config.include_default_input_wrapper_class = true end diff --git a/lib/simple_form.rb b/lib/simple_form.rb index 89ca9d67..4f977dea 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -153,6 +153,10 @@ module SimpleForm mattr_accessor :input_class @@input_class = nil + # Defines if an input wrapper class should be included or not + mattr_accessor :include_default_input_wrapper_class + @@include_default_input_wrapper_class = true + ## WRAPPER CONFIGURATION # The default wrapper to be used by the FormBuilder. mattr_accessor :default_wrapper diff --git a/lib/simple_form/inputs/collection_radio_buttons_input.rb b/lib/simple_form/inputs/collection_radio_buttons_input.rb index 44656c37..b13f2fb9 100644 --- a/lib/simple_form/inputs/collection_radio_buttons_input.rb +++ b/lib/simple_form/inputs/collection_radio_buttons_input.rb @@ -23,7 +23,7 @@ module SimpleForm options[:item_wrapper_tag] ||= options.fetch(:item_wrapper_tag, SimpleForm.item_wrapper_tag) options[:item_wrapper_class] = [ item_wrapper_class, options[:item_wrapper_class], SimpleForm.item_wrapper_class - ].compact.presence + ].compact.presence if SimpleForm.include_default_input_wrapper_class options[:collection_wrapper_tag] ||= options.fetch(:collection_wrapper_tag, SimpleForm.collection_wrapper_tag) options[:collection_wrapper_class] = [ diff --git a/test/inputs/collection_check_boxes_input_test.rb b/test/inputs/collection_check_boxes_input_test.rb index 5c839338..6254d1a3 100644 --- a/test/inputs/collection_check_boxes_input_test.rb +++ b/test/inputs/collection_check_boxes_input_test.rb @@ -232,4 +232,21 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase assert_select 'label.checkbox.inline > input' end end + + test 'input check boxes wrapper class are not included when set to falsey' do + swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do + with_input_for @user, :gender, :check_boxes, collection: [:male, :female] + + assert_no_select 'label.checkbox' + end + end + + test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do + swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do + with_input_for @user, :gender, :check_boxes, collection: [:male, :female], item_wrapper_class: 'custom' + + assert_no_select 'label.checkbox' + assert_select 'label.custom' + end + end end diff --git a/test/inputs/collection_radio_buttons_input_test.rb b/test/inputs/collection_radio_buttons_input_test.rb index 476ad70d..85eda075 100644 --- a/test/inputs/collection_radio_buttons_input_test.rb +++ b/test/inputs/collection_radio_buttons_input_test.rb @@ -325,4 +325,21 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase assert_select 'label.radio.inline > input' end end + + test 'input radio wrapper class are not included when set to falsey' do + swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do + with_input_for @user, :gender, :radio_buttons, collection: [:male, :female] + + assert_no_select 'label.radio' + end + end + + test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do + swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do + with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], item_wrapper_class: 'custom' + + assert_no_select 'label.radio' + assert_select 'label.custom' + end + end end From 10c14a579ae940e59c48d78af28e9778aee1ca28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 27 Nov 2013 00:09:47 -0200 Subject: [PATCH 10/21] Use Rails 4.0.1 --- Gemfile.lock | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 46d7040a..98fa7f50 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,44 +8,44 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (4.0.0) - activesupport (= 4.0.0) + actionpack (4.0.1) + activesupport (= 4.0.1) builder (~> 3.1.0) erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) - activemodel (4.0.0) - activesupport (= 4.0.0) + activemodel (4.0.1) + activesupport (= 4.0.1) builder (~> 3.1.0) - activesupport (4.0.0) + activesupport (4.0.1) i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) - atomic (1.1.9) + atomic (1.1.14) builder (3.1.4) country_select (1.1.3) erubis (2.7.0) - i18n (0.6.4) - json (1.7.7) + i18n (0.6.5) + json (1.8.1) minitest (4.7.5) - multi_json (1.7.7) + multi_json (1.8.2) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - railties (4.0.0) - actionpack (= 4.0.0) - activesupport (= 4.0.0) + railties (4.0.1) + actionpack (= 4.0.1) + activesupport (= 4.0.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.0.4) + rake (10.1.0) rdoc (4.0.1) json (~> 1.4) thor (0.18.1) - thread_safe (0.1.0) + thread_safe (0.1.3) atomic - tzinfo (0.3.37) + tzinfo (0.3.38) PLATFORMS ruby From c0cb09215ff85832f207b2ec1586a83945bbceb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 26 Nov 2013 21:07:52 -0200 Subject: [PATCH 11/21] Make sure label text is escaped if it is not safe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafael Mendonça França --- lib/simple_form/components/labels.rb | 3 ++- test/form_builder/label_test.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/components/labels.rb b/lib/simple_form/components/labels.rb index 2e78a3f4..b9f51152 100644 --- a/lib/simple_form/components/labels.rb +++ b/lib/simple_form/components/labels.rb @@ -2,6 +2,7 @@ module SimpleForm module Components module Labels extend ActiveSupport::Concern + include ERB::Util module ClassMethods #:nodoc: def translate_required_html @@ -30,7 +31,7 @@ module SimpleForm end def label_text - SimpleForm.label_text.call(raw_label_text, required_label_text).strip.html_safe + SimpleForm.label_text.call(html_escape(raw_label_text), required_label_text).strip.html_safe end def label_target diff --git a/test/form_builder/label_test.rb b/test/form_builder/label_test.rb index 4d4155c6..4b7e0a78 100644 --- a/test/form_builder/label_test.rb +++ b/test/form_builder/label_test.rb @@ -29,6 +29,16 @@ class LabelTest < ActionView::TestCase assert_select 'label.string.required[for=validating_user_name]', /Name/ end + test 'builder should escape label text' do + with_label_for @user, :name, label: '', required: false + assert_select 'label.string', "<script>alert(1337)</script>" + end + + test 'builder should not escape label text if it is safe' do + with_label_for @user, :name, label: ''.html_safe, required: false + assert_select 'label.string script', "alert(1337)" + end + test 'builder should allow passing options to label tag' do with_label_for @user, :name, label: 'My label', id: 'name_label' assert_select 'label.string#name_label', /My label/ From 5335e42f76436e1c81ac3c0bf747f46b76629df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 26 Nov 2013 23:33:24 -0200 Subject: [PATCH 12/21] Make sure hint text is escaped if it is not safe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafael Mendonça França --- lib/simple_form/components/hints.rb | 9 +++++++-- lib/simple_form/components/labels.rb | 1 - lib/simple_form/inputs/base.rb | 3 +++ test/form_builder/hint_test.rb | 10 ++++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/simple_form/components/hints.rb b/lib/simple_form/components/hints.rb index a95f9c5e..f9890d5b 100644 --- a/lib/simple_form/components/hints.rb +++ b/lib/simple_form/components/hints.rb @@ -5,8 +5,13 @@ module SimpleForm def hint @hint ||= begin hint = options[:hint] - hint_content = hint.is_a?(String) ? hint : translate(:hints) - hint_content.html_safe if hint_content + + if hint.is_a?(String) + html_escape(hint) + else + content = translate(:hints) + content.html_safe if content + end end end diff --git a/lib/simple_form/components/labels.rb b/lib/simple_form/components/labels.rb index b9f51152..ae33f5d2 100644 --- a/lib/simple_form/components/labels.rb +++ b/lib/simple_form/components/labels.rb @@ -2,7 +2,6 @@ module SimpleForm module Components module Labels extend ActiveSupport::Concern - include ERB::Util module ClassMethods #:nodoc: def translate_required_html diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 9d2b17c7..b3f4b0db 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -1,8 +1,11 @@ require 'simple_form/i18n_cache' +require 'active_support/core_ext/string/output_safety' module SimpleForm module Inputs class Base + include ERB::Util + extend I18nCache include SimpleForm::Helpers::Autofocus diff --git a/test/form_builder/hint_test.rb b/test/form_builder/hint_test.rb index f8fd2cbe..38252720 100644 --- a/test/form_builder/hint_test.rb +++ b/test/form_builder/hint_test.rb @@ -43,8 +43,14 @@ class HintTest < ActionView::TestCase end test 'hint should be output as html_safe' do - with_hint_for @user, :name, hint: 'Bold and not...' + with_hint_for @user, :name, hint: 'Bold and not...'.html_safe assert_select 'span.hint', 'Bold and not...' + assert_select 'span.hint b', 'Bold' + end + + test 'builder should escape hint text' do + with_hint_for @user, :name, hint: '' + assert_select 'span.hint', "<script>alert(1337)</script>" end # Without attribute name @@ -132,7 +138,7 @@ class HintTest < ActionView::TestCase test 'hint with custom wrappers works' do swap_wrapper do with_hint_for @user, :name, hint: "can't be blank" - assert_select 'div.omg_hint', "can't be blank" + assert_select 'div.omg_hint', "can't be blank" end end end From 77ab6fe0f8c6e9c6240e9c711b6cdb9baf48d330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 26 Nov 2013 23:47:12 -0200 Subject: [PATCH 13/21] Make sure error_prefix option is escaped if it is not safe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafael Mendonça França --- lib/simple_form/components/errors.rb | 2 +- test/form_builder/error_test.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/simple_form/components/errors.rb b/lib/simple_form/components/errors.rb index 74d6f5ee..aad48335 100644 --- a/lib/simple_form/components/errors.rb +++ b/lib/simple_form/components/errors.rb @@ -12,7 +12,7 @@ module SimpleForm protected def error_text - "#{options[:error_prefix]} #{errors.send(error_method)}".lstrip.html_safe + "#{html_escape(options[:error_prefix])} #{errors.send(error_method)}".lstrip.html_safe end def error_method diff --git a/test/form_builder/error_test.rb b/test/form_builder/error_test.rb index ce42ccb4..06a024a7 100644 --- a/test/form_builder/error_test.rb +++ b/test/form_builder/error_test.rb @@ -80,8 +80,13 @@ class ErrorTest < ActionView::TestCase assert_no_select 'p.error[error_method]' end - test 'error should generate an error message with raw HTML tags' do + test 'error should escape error prefix text' do with_error_for @user, :name, error_prefix: 'Name' + assert_select 'span.error', "<b>Name</b> can't be blank" + end + + test 'error should generate an error message with raw HTML tags' do + with_error_for @user, :name, error_prefix: 'Name'.html_safe assert_select 'span.error', "Name can't be blank" assert_select 'span.error b', "Name" end From 3989c5388911620a05c343800e73c640bc77e3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 29 Nov 2013 13:45:04 -0200 Subject: [PATCH 14/21] Release 3.0.1 --- CHANGELOG.md | 5 +++++ Gemfile.lock | 2 +- lib/simple_form/version.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d1a38b..6da72fbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.1 + +### bug fix + * Fix XSS vulnerability on label, hint and error components. + ## 3.0.0 ### enhancements diff --git a/Gemfile.lock b/Gemfile.lock index 46d7040a..206ff539 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - simple_form (3.0.0) + simple_form (3.0.1) actionpack (>= 4.0.0, < 4.1) activemodel (>= 4.0.0, < 4.1) diff --git a/lib/simple_form/version.rb b/lib/simple_form/version.rb index 7b9bda35..d1115316 100644 --- a/lib/simple_form/version.rb +++ b/lib/simple_form/version.rb @@ -1,3 +1,3 @@ module SimpleForm - VERSION = "3.0.0".freeze + VERSION = "3.0.1".freeze end From 10cc21607fb3d130a81c4a7431a8d9a9a695eac5 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sun, 24 Nov 2013 18:11:05 +0300 Subject: [PATCH 15/21] input_field uses the same wrapper as input but only with attribute components closes #938 #823 --- CHANGELOG.md | 1 + lib/simple_form/form_builder.rb | 25 ++++++++++++++++--------- test/form_builder/input_field_test.rb | 18 +++++++++++++++++- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8ad938f..0cfecb02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## master ### enhancements + * `input_field` uses the same wrapper as input but only with attribute components. [@nashby](https://github.com/nashby) * Add wrapper mapping per form basis [@rcillo](https://github.com/rcillo) and [@bernardoamc](https://github.com/bernardoamc) * Add `for` attribute to `label` when collections are rendered as radio or checkbox [@erichkist](https://github.com/erichkist), [@ulissesalmeida](https://github.com/ulissesalmeida) and [@fabioyamate](https://github.com/fabioyamate) diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index 44ae509e..94a0f5d5 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -108,16 +108,11 @@ module SimpleForm # def input(attribute_name, options={}, &block) options = @defaults.deep_dup.deep_merge(options) if @defaults - input = find_input(attribute_name, options, &block) - chosen = - if name = options[:wrapper] || find_wrapper_mapping(input.input_type) - name.respond_to?(:render) ? name : SimpleForm.wrapper(name) - else - wrapper - end + input = find_input(attribute_name, options, &block) + wrapper = find_wrapper(input.input_type, options) - chosen.render input + wrapper.render input end alias :attribute :input @@ -140,7 +135,11 @@ module SimpleForm options[:input_html] = options.except(:as, :collection, :label_method, :value_method, *ATTRIBUTE_COMPONENTS) options = @defaults.deep_dup.deep_merge(options) if @defaults - SimpleForm::Wrappers::Root.new(ATTRIBUTE_COMPONENTS + [:input], wrapper: false).render find_input(attribute_name, options) + input = find_input(attribute_name, options) + wrapper = find_wrapper(input.input_type, options) + components = (wrapper.components & ATTRIBUTE_COMPONENTS) + [:input] + + SimpleForm::Wrappers::Root.new(components, wrapper.options.merge(wrapper: false)).render input end # Helper for dealing with association selects/radios, generating the @@ -564,6 +563,14 @@ module SimpleForm end end + def find_wrapper(input_type, options) + if name = options[:wrapper] || find_wrapper_mapping(input_type) + name.respond_to?(:render) ? name : SimpleForm.wrapper(name) + else + wrapper + end + end + # If cache_discovery is enabled, use the class level cache that persists # between requests, otherwise use the instance one. def discovery_cache #:nodoc: diff --git a/test/form_builder/input_field_test.rb b/test/form_builder/input_field_test.rb index 755ad85b..1f399c1e 100644 --- a/test/form_builder/input_field_test.rb +++ b/test/form_builder/input_field_test.rb @@ -88,14 +88,30 @@ class InputFieldTest < ActionView::TestCase assert_select 'input[min=18]' end - test 'builder input_field should use pattern component' do + test 'builder input_field should not use pattern component by default' do with_concat_form_for(@other_validating_user) do |f| f.input_field :country, as: :string end + assert_no_select 'input[pattern="\w+"]' + end + + test 'builder input_field should infer pattern from attributes' do + with_concat_form_for(@other_validating_user) do |f| + f.input_field :country, as: :string, pattern: true + end + assert_select 'input[pattern="\w+"]' end + test 'builder input_field should accept custom patter' do + with_concat_form_for(@other_validating_user) do |f| + f.input_field :country, as: :string, pattern: '\d+' + end + + assert_select 'input[pattern="\d+"]' + end + test 'builder input_field should use readonly component' do with_concat_form_for(@other_validating_user) do |f| f.input_field :age, as: :integer, readonly: true From 0a87f3d842b8901ebaf7474951c18c39570a426f Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 4 Dec 2013 09:31:12 -0200 Subject: [PATCH 16/21] Bump dependencies --- Gemfile.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8b36956f..d5806451 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,16 +8,16 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (4.0.1) - activesupport (= 4.0.1) + actionpack (4.0.2) + activesupport (= 4.0.2) builder (~> 3.1.0) erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) - activemodel (4.0.1) - activesupport (= 4.0.1) + activemodel (4.0.2) + activesupport (= 4.0.2) builder (~> 3.1.0) - activesupport (4.0.1) + activesupport (4.0.2) i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) multi_json (~> 1.3) @@ -27,16 +27,16 @@ GEM builder (3.1.4) country_select (1.1.3) erubis (2.7.0) - i18n (0.6.5) + i18n (0.6.9) json (1.8.1) minitest (4.7.5) multi_json (1.8.2) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - railties (4.0.1) - actionpack (= 4.0.1) - activesupport (= 4.0.1) + railties (4.0.2) + actionpack (= 4.0.2) + activesupport (= 4.0.2) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.1.0) From 9be3efe9e8b420cec16e5f7a8b237227746a6b8d Mon Sep 17 00:00:00 2001 From: Andriel Nuernberg Date: Thu, 5 Dec 2013 20:50:15 -0200 Subject: [PATCH 17/21] Bump Rails dependencies to 4-0-stable --- Gemfile | 6 +++--- Gemfile.lock | 40 +++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Gemfile b/Gemfile index eb04fccf..d2d6ea04 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,9 @@ source 'https://rubygems.org' gemspec gem 'country_select', '~> 1.1.1' -gem 'railties', '>= 4.0.0', '< 4.1' -gem 'activemodel', '>= 4.0.0', '< 4.1' -gem 'actionpack', '>= 4.0.0', '< 4.1' +gem 'railties', github: 'rails/rails', branch: '4-0-stable' +gem 'activemodel', github: 'rails/rails', branch: '4-0-stable' +gem 'actionpack', github: 'rails/rails', branch: '4-0-stable' gem 'rake' gem 'rdoc' gem 'tzinfo' diff --git a/Gemfile.lock b/Gemfile.lock index d5806451..8cfe7adc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,7 @@ -PATH - remote: . - specs: - simple_form (3.0.1) - actionpack (>= 4.0.0, < 4.1) - activemodel (>= 4.0.0, < 4.1) - -GEM - remote: https://rubygems.org/ +GIT + remote: git://github.com/rails/rails.git + revision: b632a8237745c62747558551c74e32a3bb056e09 + branch: 4-0-stable specs: actionpack (4.0.2) activesupport (= 4.0.2) @@ -23,6 +18,22 @@ GEM multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) + railties (4.0.2) + actionpack (= 4.0.2) + activesupport (= 4.0.2) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + +PATH + remote: . + specs: + simple_form (3.0.1) + actionpack (>= 4.0.0, < 4.1) + activemodel (>= 4.0.0, < 4.1) + +GEM + remote: https://rubygems.org/ + specs: atomic (1.1.14) builder (3.1.4) country_select (1.1.3) @@ -34,11 +45,6 @@ GEM rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - railties (4.0.2) - actionpack (= 4.0.2) - activesupport (= 4.0.2) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) rake (10.1.0) rdoc (4.0.1) json (~> 1.4) @@ -51,10 +57,10 @@ PLATFORMS ruby DEPENDENCIES - actionpack (>= 4.0.0, < 4.1) - activemodel (>= 4.0.0, < 4.1) + actionpack! + activemodel! country_select (~> 1.1.1) - railties (>= 4.0.0, < 4.1) + railties! rake rdoc simple_form! From f2da72d80c319b554a4ddcf842a85b041c179bb7 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Fri, 6 Dec 2013 13:22:39 +0300 Subject: [PATCH 18/21] fix labels `for` attribute with nested boolean style closes #948 --- lib/simple_form/tags.rb | 2 +- test/inputs/collection_radio_buttons_input_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/tags.rb b/lib/simple_form/tags.rb index 8e9ee41d..2433c970 100644 --- a/lib/simple_form/tags.rb +++ b/lib/simple_form/tags.rb @@ -20,7 +20,7 @@ module SimpleForm if item_wrapper_tag.to_s == 'label' label_options = {} - add_default_name_and_id_for_value(text, label_options) + add_default_name_and_id_for_value(value, label_options) options['for'] = label_options['id'] end diff --git a/test/inputs/collection_radio_buttons_input_test.rb b/test/inputs/collection_radio_buttons_input_test.rb index 85eda075..c1a27279 100644 --- a/test/inputs/collection_radio_buttons_input_test.rb +++ b/test/inputs/collection_radio_buttons_input_test.rb @@ -18,6 +18,14 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase assert_select 'label[for=user_active_false]', 'No' end + test 'input as radio should generate internal labels with accurate `for` values with nested boolean style' do + swap SimpleForm, boolean_style: :nested do + with_input_for @user, :active, :radio_buttons + assert_select 'label[for=user_active_true]', 'Yes' + assert_select 'label[for=user_active_false]', 'No' + end + end + test 'input as radio should use i18n to translate internal labels' do store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do with_input_for @user, :active, :radio_buttons From 8e6c383fe6aab5efb9c7e2aaec3973cba5046080 Mon Sep 17 00:00:00 2001 From: Andriel Nuernberg Date: Fri, 6 Dec 2013 14:59:07 -0200 Subject: [PATCH 19/21] Let Devise play with Rails master --- .travis.yml | 3 +++ gemfiles/Gemfile.rails-head | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 gemfiles/Gemfile.rails-head diff --git a/.travis.yml b/.travis.yml index 331435e7..99522cb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: ruby rvm: - 1.9.3 - 2.0.0 +matrix: + allow_failures: + gemfile: gemfiles/Gemfile.rails-head notifications: email: false campfire: diff --git a/gemfiles/Gemfile.rails-head b/gemfiles/Gemfile.rails-head new file mode 100644 index 00000000..968c0042 --- /dev/null +++ b/gemfiles/Gemfile.rails-head @@ -0,0 +1,11 @@ +source 'https://rubygems.org' + +gemspec :path => '..' + +gem 'country_select', '~> 1.1.1' +gem 'railties', github: 'rails/rails' +gem 'activemodel', github: 'rails/rails' +gem 'actionpack', github: 'rails/rails' +gem 'rake' +gem 'rdoc' +gem 'tzinfo' From e0edc801685da748f3c3facf4f0dbcdfdd9b5042 Mon Sep 17 00:00:00 2001 From: Andriel Nuernberg Date: Fri, 6 Dec 2013 15:24:52 -0200 Subject: [PATCH 20/21] Set alternative gemfiles for Travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 99522cb5..3a4cf607 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: ruby rvm: - 1.9.3 - 2.0.0 +gemfile: + - gemfiles/Gemfile.rails-head + - Gemfile matrix: allow_failures: gemfile: gemfiles/Gemfile.rails-head From 3bb71085c7cc9098cb339fca88fcaae2e92b0fac Mon Sep 17 00:00:00 2001 From: Andriel Nuernberg Date: Fri, 6 Dec 2013 17:59:34 -0200 Subject: [PATCH 21/21] Fix travis.yml syntax for allow_failures --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a4cf607..1cdf0965 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ gemfile: - Gemfile matrix: allow_failures: - gemfile: gemfiles/Gemfile.rails-head + - gemfile: gemfiles/Gemfile.rails-head notifications: email: false campfire: