simple_form 3.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +149 -25
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +441 -107
  5. data/lib/generators/simple_form/install_generator.rb +4 -3
  6. data/lib/generators/simple_form/templates/README +4 -5
  7. data/lib/generators/simple_form/templates/_form.html.erb +2 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +2 -0
  9. data/lib/generators/simple_form/templates/_form.html.slim +1 -0
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +48 -11
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +417 -23
  12. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +101 -5
  13. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
  14. data/lib/simple_form/action_view_extensions/builder.rb +2 -0
  15. data/lib/simple_form/action_view_extensions/form_helper.rb +10 -3
  16. data/lib/simple_form/components/errors.rb +38 -3
  17. data/lib/simple_form/components/hints.rb +3 -2
  18. data/lib/simple_form/components/html5.rb +16 -5
  19. data/lib/simple_form/components/label_input.rb +21 -2
  20. data/lib/simple_form/components/labels.rb +22 -11
  21. data/lib/simple_form/components/maxlength.rb +9 -5
  22. data/lib/simple_form/components/min_max.rb +2 -1
  23. data/lib/simple_form/components/minlength.rb +38 -0
  24. data/lib/simple_form/components/pattern.rb +2 -1
  25. data/lib/simple_form/components/placeholders.rb +4 -3
  26. data/lib/simple_form/components/readonly.rb +2 -1
  27. data/lib/simple_form/components.rb +2 -0
  28. data/lib/simple_form/error_notification.rb +1 -0
  29. data/lib/simple_form/form_builder.rb +193 -80
  30. data/lib/simple_form/helpers/autofocus.rb +1 -0
  31. data/lib/simple_form/helpers/disabled.rb +1 -0
  32. data/lib/simple_form/helpers/readonly.rb +1 -0
  33. data/lib/simple_form/helpers/required.rb +1 -0
  34. data/lib/simple_form/helpers/validators.rb +2 -1
  35. data/lib/simple_form/helpers.rb +6 -5
  36. data/lib/simple_form/i18n_cache.rb +1 -0
  37. data/lib/simple_form/inputs/base.rb +57 -14
  38. data/lib/simple_form/inputs/block_input.rb +2 -1
  39. data/lib/simple_form/inputs/boolean_input.rb +39 -16
  40. data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
  41. data/lib/simple_form/inputs/collection_input.rb +37 -14
  42. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +9 -13
  43. data/lib/simple_form/inputs/collection_select_input.rb +5 -2
  44. data/lib/simple_form/inputs/date_time_input.rb +24 -9
  45. data/lib/simple_form/inputs/file_input.rb +5 -2
  46. data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
  47. data/lib/simple_form/inputs/hidden_input.rb +5 -2
  48. data/lib/simple_form/inputs/numeric_input.rb +6 -4
  49. data/lib/simple_form/inputs/password_input.rb +6 -3
  50. data/lib/simple_form/inputs/priority_input.rb +5 -2
  51. data/lib/simple_form/inputs/range_input.rb +2 -1
  52. data/lib/simple_form/inputs/string_input.rb +6 -3
  53. data/lib/simple_form/inputs/text_input.rb +6 -3
  54. data/lib/simple_form/inputs.rb +1 -0
  55. data/lib/simple_form/map_type.rb +1 -0
  56. data/lib/simple_form/railtie.rb +8 -0
  57. data/lib/simple_form/tags.rb +7 -0
  58. data/lib/simple_form/version.rb +2 -1
  59. data/lib/simple_form/wrappers/builder.rb +7 -6
  60. data/lib/simple_form/wrappers/leaf.rb +29 -0
  61. data/lib/simple_form/wrappers/many.rb +7 -6
  62. data/lib/simple_form/wrappers/root.rb +3 -1
  63. data/lib/simple_form/wrappers/single.rb +7 -4
  64. data/lib/simple_form/wrappers.rb +2 -0
  65. data/lib/simple_form.rb +117 -18
  66. data/test/action_view_extensions/builder_test.rb +42 -41
  67. data/test/action_view_extensions/form_helper_test.rb +36 -16
  68. data/test/components/custom_components_test.rb +62 -0
  69. data/test/components/label_test.rb +70 -41
  70. data/test/form_builder/association_test.rb +79 -37
  71. data/test/form_builder/button_test.rb +11 -10
  72. data/test/form_builder/error_notification_test.rb +2 -1
  73. data/test/form_builder/error_test.rb +173 -24
  74. data/test/form_builder/general_test.rb +171 -73
  75. data/test/form_builder/hint_test.rb +24 -18
  76. data/test/form_builder/input_field_test.rb +132 -56
  77. data/test/form_builder/label_test.rb +68 -13
  78. data/test/form_builder/wrapper_test.rb +190 -22
  79. data/test/generators/simple_form_generator_test.rb +8 -7
  80. data/test/inputs/boolean_input_test.rb +89 -6
  81. data/test/inputs/collection_check_boxes_input_test.rb +109 -25
  82. data/test/inputs/collection_radio_buttons_input_test.rb +168 -54
  83. data/test/inputs/collection_select_input_test.rb +183 -77
  84. data/test/inputs/datetime_input_test.rb +131 -50
  85. data/test/inputs/disabled_test.rb +16 -15
  86. data/test/inputs/discovery_test.rb +58 -6
  87. data/test/inputs/file_input_test.rb +3 -2
  88. data/test/inputs/general_test.rb +23 -22
  89. data/test/inputs/grouped_collection_select_input_test.rb +54 -17
  90. data/test/inputs/hidden_input_test.rb +5 -4
  91. data/test/inputs/numeric_input_test.rb +48 -44
  92. data/test/inputs/priority_input_test.rb +23 -14
  93. data/test/inputs/readonly_test.rb +20 -19
  94. data/test/inputs/required_test.rb +58 -13
  95. data/test/inputs/string_input_test.rb +62 -33
  96. data/test/inputs/text_input_test.rb +20 -7
  97. data/test/simple_form_test.rb +9 -0
  98. data/test/support/discovery_inputs.rb +33 -2
  99. data/test/support/misc_helpers.rb +113 -5
  100. data/test/support/mock_controller.rb +7 -1
  101. data/test/support/models.rb +137 -37
  102. data/test/test_helper.rb +15 -1
  103. metadata +25 -33
@@ -1,18 +1,74 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
4
- # Tests for all different kinds of inputs.
5
- class DateTimeInputTest < ActionView::TestCase
6
- # DateTime input
7
- test 'input should generate a datetime select by default for datetime attributes' do
5
+ # Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
6
+ class DateTimeInputWithHtml5Test < ActionView::TestCase
7
+ test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enbled' do
8
+ with_input_for @user, :created_at, :datetime, html5: true
9
+
10
+ if ActionPack::VERSION::STRING >= '5'
11
+ assert_select 'input[type="datetime-local"]'
12
+ elsif ActionPack::VERSION::STRING < '5'
13
+ assert_select 'input[type="datetime"]'
14
+ end
15
+ end
16
+
17
+ test 'input generates a datetime select for datetime attributes' do
8
18
  with_input_for @user, :created_at, :datetime
9
- 1.upto(5) do |i|
10
- assert_select "form select.datetime#user_created_at_#{i}i"
19
+
20
+ assert_select 'select.datetime'
21
+ end
22
+
23
+ test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enbled' do
24
+ with_input_for @user, :born_at, :date, html5: true
25
+
26
+ assert_select 'input[type="date"]'
27
+ end
28
+
29
+ test 'input generates a date select for date attributes' do
30
+ with_input_for @user, :born_at, :date
31
+
32
+ assert_select 'select.date'
33
+ end
34
+
35
+ test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enbled' do
36
+ with_input_for @user, :delivery_time, :time, html5: true
37
+
38
+ assert_select 'input[type="time"]'
39
+ end
40
+
41
+ test 'input generates a time select for time attributes' do
42
+ with_input_for @user, :delivery_time, :time
43
+
44
+ assert_select 'select.time'
45
+ end
46
+
47
+ test 'input generates required html attribute' do
48
+ with_input_for @user, :delivery_time, :time, required: true, html5: true
49
+ assert_select 'input.required'
50
+ assert_select 'input[required]'
51
+ end
52
+
53
+ test 'input has an aria-required html attribute' do
54
+ with_input_for @user, :delivery_time, :time, required: true, html5: true
55
+ assert_select 'input[aria-required=true]'
56
+ end
57
+ end
58
+
59
+ # Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.
60
+ class DateTimeInputWithoutHtml5Test < ActionView::TestCase
61
+ test 'input generates a datetime select by default for datetime attributes' do
62
+ swap_wrapper do
63
+ with_input_for @user, :created_at, :datetime
64
+ 1.upto(5) do |i|
65
+ assert_select "form select.datetime#user_created_at_#{i}i"
66
+ end
11
67
  end
12
68
  end
13
69
 
14
- test 'input should be able to pass options to datetime select' do
15
- with_input_for @user, :created_at, :datetime,
70
+ test 'input is able to pass options to datetime select' do
71
+ with_input_for @user, :created_at, :datetime, html5: false,
16
72
  disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
17
73
 
18
74
  assert_select 'select.datetime[disabled=disabled]'
@@ -21,16 +77,30 @@ class DateTimeInputTest < ActionView::TestCase
21
77
  assert_select 'select.datetime option', 'dia'
22
78
  end
23
79
 
24
- test 'input should generate a date select for date attributes' do
25
- with_input_for @user, :born_at, :date
26
- assert_select 'select.date#user_born_at_1i'
27
- assert_select 'select.date#user_born_at_2i'
28
- assert_select 'select.date#user_born_at_3i'
29
- assert_no_select 'select.date#user_born_at_4i'
80
+ test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explicitly enabled' do
81
+ swap_wrapper do
82
+ with_input_for @user, :created_at, :datetime, html5: true
83
+
84
+ if ActionPack::VERSION::STRING >= '5'
85
+ assert_select 'input[type="datetime-local"]'
86
+ elsif ActionPack::VERSION::STRING < '5'
87
+ assert_select 'input[type="datetime"]'
88
+ end
89
+ end
30
90
  end
31
91
 
32
- test 'input should be able to pass options to date select' do
33
- with_input_for @user, :born_at, :date, as: :date,
92
+ test 'input generates a date select for date attributes' do
93
+ swap_wrapper do
94
+ with_input_for @user, :born_at, :date
95
+ assert_select 'select.date#user_born_at_1i'
96
+ assert_select 'select.date#user_born_at_2i'
97
+ assert_select 'select.date#user_born_at_3i'
98
+ assert_no_select 'select.date#user_born_at_4i'
99
+ end
100
+ end
101
+
102
+ test 'input is able to pass options to date select' do
103
+ with_input_for @user, :born_at, :date, as: :date, html5: false,
34
104
  disabled: true, prompt: { year: 'ano', month: 'mês', day: 'dia' }
35
105
 
36
106
  assert_select 'select.date[disabled=disabled]'
@@ -39,22 +109,32 @@ class DateTimeInputTest < ActionView::TestCase
39
109
  assert_select 'select.date option', 'dia'
40
110
  end
41
111
 
42
- test 'input should be able to pass :default to date select' do
43
- with_input_for @user, :born_at, :date, default: Date.today
44
- assert_select "select.date option[value=#{Date.today.year}][selected=selected]"
112
+ test 'input is able to pass :default to date select' do
113
+ with_input_for @user, :born_at, :date, default: Date.today, html5: false
114
+ assert_select "select.date option[value='#{Date.today.year}'][selected=selected]"
45
115
  end
46
116
 
47
- test 'input should generate a time select for time attributes' do
48
- with_input_for @user, :delivery_time, :time
49
- assert_select 'input[type=hidden]#user_delivery_time_1i'
50
- assert_select 'input[type=hidden]#user_delivery_time_2i'
51
- assert_select 'input[type=hidden]#user_delivery_time_3i'
52
- assert_select 'select.time#user_delivery_time_4i'
53
- assert_select 'select.time#user_delivery_time_5i'
117
+ test 'input generates a date input for date attributes if HTML5 compatibility is explicitly enabled' do
118
+ swap_wrapper do
119
+ with_input_for @user, :born_at, :date, html5: true
120
+
121
+ assert_select 'input[type="date"]'
122
+ end
123
+ end
124
+
125
+ test 'input generates a time select for time attributes' do
126
+ swap_wrapper do
127
+ with_input_for @user, :delivery_time, :time
128
+ assert_select 'input[type=hidden]#user_delivery_time_1i'
129
+ assert_select 'input[type=hidden]#user_delivery_time_2i'
130
+ assert_select 'input[type=hidden]#user_delivery_time_3i'
131
+ assert_select 'select.time#user_delivery_time_4i'
132
+ assert_select 'select.time#user_delivery_time_5i'
133
+ end
54
134
  end
55
135
 
56
- test 'input should be able to pass options to time select' do
57
- with_input_for @user, :delivery_time, :time, required: true,
136
+ test 'input is able to pass options to time select' do
137
+ with_input_for @user, :delivery_time, :time, required: true, html5: false,
58
138
  disabled: true, prompt: { hour: 'hora', minute: 'minuto' }
59
139
 
60
140
  assert_select 'select.time[disabled=disabled]'
@@ -62,44 +142,45 @@ class DateTimeInputTest < ActionView::TestCase
62
142
  assert_select 'select.time option', 'minuto'
63
143
  end
64
144
 
65
- test 'label should use i18n to get target for date input type' do
66
- store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
67
- with_input_for :project, :created_at, :date
145
+ test 'input generates a time input for time attributes if HTML5 compatibility is explicitly enabled' do
146
+ swap_wrapper do
147
+ with_input_for @user, :delivery_time, :time, html5: true
148
+
149
+ assert_select 'input[type="time"]'
150
+ end
151
+ end
152
+
153
+ test 'label uses i18n to get target for date input type' do
154
+ store_translations(:en, date: { order: %w[month day year] }) do
155
+ with_input_for :project, :created_at, :date, html5: false
68
156
  assert_select 'label[for=project_created_at_2i]'
69
157
  end
70
158
  end
71
159
 
72
- test 'label should use i18n to get target for datetime input type' do
73
- store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
74
- with_input_for :project, :created_at, :datetime
160
+ test 'label uses i18n to get target for datetime input type' do
161
+ store_translations(:en, date: { order: %w[month day year] }) do
162
+ with_input_for :project, :created_at, :datetime, html5: false
75
163
  assert_select 'label[for=project_created_at_2i]'
76
164
  end
77
165
  end
78
166
 
79
- test 'label should use order to get target when date input type' do
80
- with_input_for :project, :created_at, :date, order: ['month', 'year', 'day']
167
+ test 'label uses order to get target when date input type' do
168
+ with_input_for :project, :created_at, :date, order: %w[month year day], html5: false
81
169
  assert_select 'label[for=project_created_at_2i]'
82
170
  end
83
171
 
84
- test 'label should use order to get target when datetime input type' do
85
- with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day']
172
+ test 'label uses order to get target when datetime input type' do
173
+ with_input_for :project, :created_at, :datetime, order: %w[month year day], html5: false
86
174
  assert_select 'label[for=project_created_at_2i]'
87
175
  end
88
176
 
89
- test 'label should point to first option when time input type' do
90
- with_input_for :project, :created_at, :time
177
+ test 'label points to first option when time input type' do
178
+ with_input_for :project, :created_at, :time, html5: false
91
179
  assert_select 'label[for=project_created_at_4i]'
92
180
  end
93
181
 
94
- test 'date time input should generate required html attribute' do
95
- with_input_for @user, :delivery_time, :time, required: true
96
- assert_select 'select.required'
97
- assert_select 'select[required]'
98
- end
99
-
100
- test 'date time input has an aria-required html attribute' do
101
- with_input_for @user, :delivery_time, :time, required: true
102
- assert_select 'select.required'
103
- assert_select 'select[aria-required=true]'
182
+ test 'label points to attribute name if HTML5 compatibility is explicitly enabled' do
183
+ with_input_for :project, :created_at, :date, html5: true
184
+ assert_select 'label[for=project_created_at]'
104
185
  end
105
186
  end
@@ -1,77 +1,78 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class DisabledTest < ActionView::TestCase
4
- test 'string input should be disabled when disabled option is true' do
5
+ test 'string input is disabled when disabled option is true' do
5
6
  with_input_for @user, :name, :string, disabled: true
6
7
  assert_select 'input.string.disabled[disabled]'
7
8
  end
8
9
 
9
- test 'text input should be disabled when disabled option is true' do
10
+ test 'text input is disabled when disabled option is true' do
10
11
  with_input_for @user, :description, :text, disabled: true
11
12
  assert_select 'textarea.text.disabled[disabled]'
12
13
  end
13
14
 
14
- test 'numeric input should be disabled when disabled option is true' do
15
+ test 'numeric input is disabled when disabled option is true' do
15
16
  with_input_for @user, :age, :integer, disabled: true
16
17
  assert_select 'input.integer.disabled[disabled]'
17
18
  end
18
19
 
19
- test 'date input should be disabled when disabled option is true' do
20
+ test 'date input is disabled when disabled option is true' do
20
21
  with_input_for @user, :born_at, :date, disabled: true
21
22
  assert_select 'select.date.disabled[disabled]'
22
23
  end
23
24
 
24
- test 'datetime input should be disabled when disabled option is true' do
25
+ test 'datetime input is disabled when disabled option is true' do
25
26
  with_input_for @user, :created_at, :datetime, disabled: true
26
27
  assert_select 'select.datetime.disabled[disabled]'
27
28
  end
28
29
 
29
- test 'string input should not be disabled when disabled option is false' do
30
+ test 'string input does not be disabled when disabled option is false' do
30
31
  with_input_for @user, :name, :string, disabled: false
31
32
  assert_no_select 'input.string.disabled[disabled]'
32
33
  end
33
34
 
34
- test 'text input should not be disabled when disabled option is false' do
35
+ test 'text input does not be disabled when disabled option is false' do
35
36
  with_input_for @user, :description, :text, disabled: false
36
37
  assert_no_select 'textarea.text.disabled[disabled]'
37
38
  end
38
39
 
39
- test 'numeric input should not be disabled when disabled option is false' do
40
+ test 'numeric input does not be disabled when disabled option is false' do
40
41
  with_input_for @user, :age, :integer, disabled: false
41
42
  assert_no_select 'input.integer.disabled[disabled]'
42
43
  end
43
44
 
44
- test 'date input should not be disabled when disabled option is false' do
45
+ test 'date input does not be disabled when disabled option is false' do
45
46
  with_input_for @user, :born_at, :date, disabled: false
46
47
  assert_no_select 'select.date.disabled[disabled]'
47
48
  end
48
49
 
49
- test 'datetime input should not be disabled when disabled option is false' do
50
+ test 'datetime input does not be disabled when disabled option is false' do
50
51
  with_input_for @user, :created_at, :datetime, disabled: false
51
52
  assert_no_select 'select.datetime.disabled[disabled]'
52
53
  end
53
54
 
54
- test 'string input should not be disabled when disabled option is not present' do
55
+ test 'string input does not be disabled when disabled option is not present' do
55
56
  with_input_for @user, :name, :string
56
57
  assert_no_select 'input.string.disabled[disabled]'
57
58
  end
58
59
 
59
- test 'text input should not be disabled when disabled option is not present' do
60
+ test 'text input does not be disabled when disabled option is not present' do
60
61
  with_input_for @user, :description, :text
61
62
  assert_no_select 'textarea.text.disabled[disabled]'
62
63
  end
63
64
 
64
- test 'numeric input should not be disabled when disabled option is not present' do
65
+ test 'numeric input does not be disabled when disabled option is not present' do
65
66
  with_input_for @user, :age, :integer
66
67
  assert_no_select 'input.integer.disabled[disabled]'
67
68
  end
68
69
 
69
- test 'date input should not be disabled when disabled option is not present' do
70
+ test 'date input does not be disabled when disabled option is not present' do
70
71
  with_input_for @user, :born_at, :date
71
72
  assert_no_select 'select.date.disabled[disabled]'
72
73
  end
73
74
 
74
- test 'datetime input should not be disabled when disabled option is not present' do
75
+ test 'datetime input does not be disabled when disabled option is not present' do
75
76
  with_input_for @user, :created_at, :datetime
76
77
  assert_no_select 'select.datetime.disabled[disabled]'
77
78
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class DiscoveryTest < ActionView::TestCase
4
5
  # Setup new inputs and remove them after the test.
5
- def discovery(value=false)
6
+ def discovery(value = false)
6
7
  swap SimpleForm, cache_discovery: value do
7
8
  begin
8
9
  load "support/discovery_inputs.rb"
@@ -12,12 +13,16 @@ class DiscoveryTest < ActionView::TestCase
12
13
  Object.send :remove_const, :StringInput
13
14
  Object.send :remove_const, :NumericInput
14
15
  Object.send :remove_const, :CustomizedInput
16
+ Object.send :remove_const, :DeprecatedInput
15
17
  Object.send :remove_const, :CollectionSelectInput
18
+ CustomInputs.send :remove_const, :CustomizedInput
19
+ CustomInputs.send :remove_const, :PasswordInput
20
+ CustomInputs.send :remove_const, :NumericInput
16
21
  end
17
22
  end
18
23
  end
19
24
 
20
- test 'builder should not discover new inputs if cached' do
25
+ test 'builder does not discover new inputs if cached' do
21
26
  with_form_for @user, :name
22
27
  assert_select 'form input#user_name.string'
23
28
 
@@ -27,14 +32,14 @@ class DiscoveryTest < ActionView::TestCase
27
32
  end
28
33
  end
29
34
 
30
- test 'builder should discover new inputs' do
35
+ test 'builder discovers new inputs' do
31
36
  discovery do
32
37
  with_form_for @user, :name, as: :customized
33
38
  assert_select 'form section input#user_name.string'
34
39
  end
35
40
  end
36
41
 
37
- test 'builder should not discover new inputs if discovery is off' do
42
+ test 'builder does not discover new inputs if discovery is off' do
38
43
  with_form_for @user, :name
39
44
  assert_select 'form input#user_name.string'
40
45
 
@@ -46,24 +51,71 @@ class DiscoveryTest < ActionView::TestCase
46
51
  end
47
52
  end
48
53
 
49
- test 'builder should discover new inputs from mappings if not cached' do
54
+ test 'builder discovers new inputs from mappings if not cached' do
50
55
  discovery do
51
56
  with_form_for @user, :name
52
57
  assert_select 'form section input#user_name.string'
53
58
  end
54
59
  end
55
60
 
56
- test 'builder should discover new inputs from internal fallbacks if not cached' do
61
+ test 'builder discovers new inputs from internal fallbacks if not cached' do
57
62
  discovery do
58
63
  with_form_for @user, :age
59
64
  assert_select 'form section input#user_age.numeric.integer'
60
65
  end
61
66
  end
62
67
 
68
+ test 'builder discovers new maped inputs from configured namespaces if not cached' do
69
+ discovery do
70
+ swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
71
+ with_form_for @user, :password
72
+ assert_select 'form input#user_password.password-custom-input'
73
+ end
74
+ end
75
+ end
76
+
77
+ test 'builder discovers new maped inputs from configured namespaces before the ones from top level namespace' do
78
+ discovery do
79
+ swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
80
+ with_form_for @user, :age
81
+ assert_select 'form input#user_age.numeric-custom-input'
82
+ end
83
+ end
84
+ end
85
+
86
+ test 'builder discovers new custom inputs from configured namespace before the ones from top level namespace' do
87
+ discovery do
88
+ swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
89
+ with_form_for @user, :name, as: 'customized'
90
+ assert_select 'form input#user_name.customized-namespace-custom-input'
91
+ end
92
+ end
93
+ end
94
+
95
+ test 'raises error when configured namespace does not exists' do
96
+ discovery do
97
+ swap SimpleForm, custom_inputs_namespaces: ['InvalidNamespace'] do
98
+ assert_raise NameError do
99
+ with_form_for @user, :age
100
+ end
101
+ end
102
+ end
103
+ end
104
+
63
105
  test 'new inputs can override the input_html_options' do
64
106
  discovery do
65
107
  with_form_for @user, :active, as: :select
66
108
  assert_select 'form select#user_active.select.chosen'
67
109
  end
68
110
  end
111
+
112
+ test 'inputs method without wrapper_options are deprecated' do
113
+ discovery do
114
+ assert_deprecated do
115
+ with_form_for @user, :name, as: :deprecated
116
+ end
117
+
118
+ assert_select 'form section input#user_name.string'
119
+ end
120
+ end
69
121
  end
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
4
5
  class FileInputTest < ActionView::TestCase
5
- test 'input should generate a file field' do
6
+ test 'input generates a file field' do
6
7
  with_input_for @user, :name, :file
7
8
  assert_select 'input#user_name[type=file]'
8
9
  end
9
10
 
10
- test "input should generate a file field that doesn't accept placeholder" do
11
+ test "input generates a file field that doesn't accept placeholder" do
11
12
  store_translations(:en, simple_form: { placeholders: { user: { name: "text" } } }) do
12
13
  with_input_for @user, :name, :file
13
14
  assert_no_select 'input[placeholder]'
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
4
5
  class InputTest < ActionView::TestCase
5
- test 'input should generate css class based on default input type' do
6
+ test 'input generates css class based on default input type' do
6
7
  with_input_for @user, :name, :string
7
8
  assert_select 'input.string'
8
9
  with_input_for @user, :description, :text
@@ -15,7 +16,7 @@ class InputTest < ActionView::TestCase
15
16
  assert_select 'select.datetime'
16
17
  end
17
18
 
18
- test 'string input should generate autofocus attribute when autofocus option is true' do
19
+ test 'string input generates autofocus attribute when autofocus option is true' do
19
20
  with_input_for @user, :name, :string, autofocus: true
20
21
  assert_select 'input.string[autofocus]'
21
22
  end
@@ -36,95 +37,95 @@ class InputTest < ActionView::TestCase
36
37
  end
37
38
  end
38
39
 
39
- test 'text input should generate autofocus attribute when autofocus option is true' do
40
+ test 'text input generates autofocus attribute when autofocus option is true' do
40
41
  with_input_for @user, :description, :text, autofocus: true
41
42
  assert_select 'textarea.text[autofocus]'
42
43
  end
43
44
 
44
- test 'numeric input should generate autofocus attribute when autofocus option is true' do
45
+ test 'numeric input generates autofocus attribute when autofocus option is true' do
45
46
  with_input_for @user, :age, :integer, autofocus: true
46
47
  assert_select 'input.integer[autofocus]'
47
48
  end
48
49
 
49
- test 'date input should generate autofocus attribute when autofocus option is true' do
50
+ test 'date input generates autofocus attribute when autofocus option is true' do
50
51
  with_input_for @user, :born_at, :date, autofocus: true
51
52
  assert_select 'select.date[autofocus]'
52
53
  end
53
54
 
54
- test 'datetime input should generate autofocus attribute when autofocus option is true' do
55
+ test 'datetime input generates autofocus attribute when autofocus option is true' do
55
56
  with_input_for @user, :created_at, :datetime, autofocus: true
56
57
  assert_select 'select.datetime[autofocus]'
57
58
  end
58
59
 
59
- test 'string input should generate autofocus attribute when autofocus option is false' do
60
+ test 'string input generates autofocus attribute when autofocus option is false' do
60
61
  with_input_for @user, :name, :string, autofocus: false
61
62
  assert_no_select 'input.string[autofocus]'
62
63
  end
63
64
 
64
- test 'text input should generate autofocus attribute when autofocus option is false' do
65
+ test 'text input generates autofocus attribute when autofocus option is false' do
65
66
  with_input_for @user, :description, :text, autofocus: false
66
67
  assert_no_select 'textarea.text[autofocus]'
67
68
  end
68
69
 
69
- test 'numeric input should generate autofocus attribute when autofocus option is false' do
70
+ test 'numeric input generates autofocus attribute when autofocus option is false' do
70
71
  with_input_for @user, :age, :integer, autofocus: false
71
72
  assert_no_select 'input.integer[autofocus]'
72
73
  end
73
74
 
74
- test 'date input should generate autofocus attribute when autofocus option is false' do
75
+ test 'date input generates autofocus attribute when autofocus option is false' do
75
76
  with_input_for @user, :born_at, :date, autofocus: false
76
77
  assert_no_select 'select.date[autofocus]'
77
78
  end
78
79
 
79
- test 'datetime input should generate autofocus attribute when autofocus option is false' do
80
+ test 'datetime input generates autofocus attribute when autofocus option is false' do
80
81
  with_input_for @user, :created_at, :datetime, autofocus: false
81
82
  assert_no_select 'select.datetime[autofocus]'
82
83
  end
83
84
 
84
- test 'string input should generate autofocus attribute when autofocus option is not present' do
85
+ test 'string input generates autofocus attribute when autofocus option is not present' do
85
86
  with_input_for @user, :name, :string
86
87
  assert_no_select 'input.string[autofocus]'
87
88
  end
88
89
 
89
- test 'text input should generate autofocus attribute when autofocus option is not present' do
90
+ test 'text input generates autofocus attribute when autofocus option is not present' do
90
91
  with_input_for @user, :description, :text
91
92
  assert_no_select 'textarea.text[autofocus]'
92
93
  end
93
94
 
94
- test 'numeric input should generate autofocus attribute when autofocus option is not present' do
95
+ test 'numeric input generates autofocus attribute when autofocus option is not present' do
95
96
  with_input_for @user, :age, :integer
96
97
  assert_no_select 'input.integer[autofocus]'
97
98
  end
98
99
 
99
- test 'date input should generate autofocus attribute when autofocus option is not present' do
100
+ test 'date input generates autofocus attribute when autofocus option is not present' do
100
101
  with_input_for @user, :born_at, :date
101
102
  assert_no_select 'select.date[autofocus]'
102
103
  end
103
104
 
104
- test 'datetime input should generate autofocus attribute when autofocus option is not present' do
105
+ test 'datetime input generates autofocus attribute when autofocus option is not present' do
105
106
  with_input_for @user, :created_at, :datetime
106
107
  assert_no_select 'select.datetime[autofocus]'
107
108
  end
108
109
 
109
110
  # With no object
110
- test 'input should be generated properly when object is not present' do
111
+ test 'input is generated properly when object is not present' do
111
112
  with_input_for :project, :name, :string
112
113
  assert_select 'input.string.required#project_name'
113
114
  end
114
115
 
115
- test 'input as radio should be generated properly when object is not present ' do
116
+ test 'input as radio is generated properly when object is not present ' do
116
117
  with_input_for :project, :name, :radio_buttons
117
118
  assert_select 'input.radio_buttons#project_name_true'
118
119
  assert_select 'input.radio_buttons#project_name_false'
119
120
  end
120
121
 
121
- test 'input as select with collection should be generated properly when object is not present' do
122
- with_input_for :project, :name, :select, collection: ['Jose', 'Carlos']
122
+ test 'input as select with collection is generated properly when object is not present' do
123
+ with_input_for :project, :name, :select, collection: %w[Jose Carlos]
123
124
  assert_select 'select.select#project_name'
124
125
  end
125
126
 
126
- test 'input should not generate empty css class' do
127
- swap SimpleForm, generate_additional_classes_for: [:wrapper, :label] do
127
+ test 'input does not generate empty css class' do
128
+ swap SimpleForm, generate_additional_classes_for: %i[wrapper label] do
128
129
  with_input_for :project, :name, :string
129
130
  assert_no_select 'input#project_name[class]'
130
131
  end