simple_form 2.1.2 → 3.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -42
  3. data/README.md +161 -119
  4. data/lib/generators/simple_form/install_generator.rb +3 -3
  5. data/lib/generators/simple_form/templates/README +1 -1
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +16 -13
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  9. data/lib/simple_form/action_view_extensions/builder.rb +1 -319
  10. data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
  12. data/lib/simple_form/components/errors.rb +1 -7
  13. data/lib/simple_form/components/hints.rb +2 -7
  14. data/lib/simple_form/components/html5.rb +5 -2
  15. data/lib/simple_form/components/labels.rb +4 -4
  16. data/lib/simple_form/components/maxlength.rb +1 -8
  17. data/lib/simple_form/components/pattern.rb +2 -2
  18. data/lib/simple_form/components.rb +1 -1
  19. data/lib/simple_form/error_notification.rb +2 -2
  20. data/lib/simple_form/form_builder.rb +155 -51
  21. data/lib/simple_form/form_builder.rb.orig +486 -0
  22. data/lib/simple_form/helpers.rb +1 -1
  23. data/lib/simple_form/inputs/base.rb +7 -10
  24. data/lib/simple_form/inputs/block_input.rb +1 -1
  25. data/lib/simple_form/inputs/boolean_input.rb +6 -4
  26. data/lib/simple_form/inputs/collection_input.rb +6 -6
  27. data/lib/simple_form/inputs/date_time_input.rb +1 -1
  28. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  29. data/lib/simple_form/inputs/password_input.rb +0 -1
  30. data/lib/simple_form/inputs/string_input.rb +0 -1
  31. data/lib/simple_form/railtie.rb +7 -0
  32. data/lib/simple_form/tags.rb +62 -0
  33. data/lib/simple_form/version.rb +1 -1
  34. data/lib/simple_form/version.rb.orig +7 -0
  35. data/lib/simple_form/wrappers/builder.rb +5 -29
  36. data/lib/simple_form/wrappers/many.rb +1 -1
  37. data/lib/simple_form/wrappers/root.rb +1 -1
  38. data/lib/simple_form/wrappers.rb +1 -1
  39. data/lib/simple_form.rb +43 -47
  40. data/test/action_view_extensions/builder_test.rb +78 -92
  41. data/test/action_view_extensions/form_helper_test.rb +25 -16
  42. data/test/components/label_test.rb +46 -46
  43. data/test/form_builder/association_test.rb +47 -29
  44. data/test/form_builder/button_test.rb +4 -4
  45. data/test/form_builder/error_notification_test.rb +8 -8
  46. data/test/form_builder/error_test.rb +18 -65
  47. data/test/form_builder/general_test.rb +73 -54
  48. data/test/form_builder/hint_test.rb +23 -29
  49. data/test/form_builder/input_field_test.rb +29 -12
  50. data/test/form_builder/label_test.rb +7 -17
  51. data/test/form_builder/wrapper_test.rb +21 -21
  52. data/test/inputs/boolean_input_test.rb +35 -23
  53. data/test/inputs/collection_check_boxes_input_test.rb +66 -55
  54. data/test/inputs/collection_radio_buttons_input_test.rb +81 -79
  55. data/test/inputs/collection_select_input_test.rb +76 -45
  56. data/test/inputs/datetime_input_test.rb +17 -11
  57. data/test/inputs/disabled_test.rb +10 -10
  58. data/test/inputs/discovery_test.rb +4 -4
  59. data/test/inputs/file_input_test.rb +1 -1
  60. data/test/inputs/general_test.rb +28 -12
  61. data/test/inputs/grouped_collection_select_input_test.rb +33 -20
  62. data/test/inputs/hidden_input_test.rb +3 -2
  63. data/test/inputs/numeric_input_test.rb +3 -3
  64. data/test/inputs/priority_input_test.rb +9 -3
  65. data/test/inputs/readonly_test.rb +12 -12
  66. data/test/inputs/required_test.rb +5 -5
  67. data/test/inputs/string_input_test.rb +15 -25
  68. data/test/inputs/text_input_test.rb +1 -1
  69. data/test/support/misc_helpers.rb +46 -24
  70. data/test/support/mock_controller.rb +6 -6
  71. data/test/support/models.rb +80 -62
  72. data/test/test_helper.rb +17 -34
  73. metadata +39 -22
  74. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -14,10 +14,6 @@ class ErrorTest < ActionView::TestCase
14
14
  end
15
15
  end
16
16
 
17
- def with_custom_error_for(object, *args)
18
- with_form_for(object, *args)
19
- end
20
-
21
17
  test 'error should not generate content for attribute without errors' do
22
18
  with_error_for @user, :active
23
19
  assert_no_select 'span.error'
@@ -36,38 +32,38 @@ class ErrorTest < ActionView::TestCase
36
32
 
37
33
  test 'error should generate messages for attribute with single error' do
38
34
  with_error_for @user, :name
39
- assert_select 'span.error', "can&#x27;t be blank"
35
+ assert_select 'span.error', "can't be blank"
40
36
  end
41
37
 
42
38
  test 'error should generate messages for attribute with one error when using first' do
43
- swap SimpleForm, :error_method => :first do
39
+ swap SimpleForm, error_method: :first do
44
40
  with_error_for @user, :age
45
41
  assert_select 'span.error', 'is not a number'
46
42
  end
47
43
  end
48
44
 
49
45
  test 'error should generate messages for attribute with several errors when using to_sentence' do
50
- swap SimpleForm, :error_method => :to_sentence do
46
+ swap SimpleForm, error_method: :to_sentence do
51
47
  with_error_for @user, :age
52
48
  assert_select 'span.error', 'is not a number and must be greater than 18'
53
49
  end
54
50
  end
55
51
 
56
52
  test 'error should be able to pass html options' do
57
- with_error_for @user, :name, :id => 'error', :class => 'yay'
53
+ with_error_for @user, :name, id: 'error', class: 'yay'
58
54
  assert_select 'span#error.error.yay'
59
55
  end
60
56
 
61
57
  test 'error should not modify the options hash' do
62
- options = { :id => 'error', :class => 'yay' }
58
+ options = { id: 'error', class: 'yay' }
63
59
  with_error_for @user, :name, options
64
60
  assert_select 'span#error.error.yay'
65
- assert_equal({ :id => 'error', :class => 'yay' }, options)
61
+ assert_equal({ id: 'error', class: 'yay' }, options)
66
62
  end
67
63
 
68
64
  test 'error should find errors on attribute and association' do
69
- with_error_for @user, :company_id, :as => :select,
70
- :error_method => :to_sentence, :reflection => Association.new(Company, :company, {})
65
+ with_error_for @user, :company_id, as: :select,
66
+ error_method: :to_sentence, reflection: Association.new(Company, :company, {})
71
67
  assert_select 'span.error', 'must be valid and company must be present'
72
68
  end
73
69
 
@@ -77,30 +73,16 @@ class ErrorTest < ActionView::TestCase
77
73
  end
78
74
 
79
75
  test 'error should generate an error tag with a clean HTML when errors options are present' do
80
- with_error_for @user, :name, :error_tag => :p, :error_prefix => 'Name', :error_method => :first
76
+ with_error_for @user, :name, error_tag: :p, error_prefix: 'Name', error_method: :first
81
77
  assert_no_select 'p.error[error_html]'
82
78
  assert_no_select 'p.error[error_tag]'
83
79
  assert_no_select 'p.error[error_prefix]'
84
80
  assert_no_select 'p.error[error_method]'
85
81
  end
86
82
 
87
- test 'error should escape error prefix text' do
88
- with_error_for @user, :name, :error_prefix => '<b>Name</b>'
89
- assert_select 'span.error', "&lt;b&gt;Name&lt;/b&gt; can&#x27;t be blank"
90
- end
91
-
92
- test 'error escapes error text' do
93
- @user.errors.merge!(:action => ['must not contain <b>markup</b>'])
94
-
95
- with_error_for @user, :action
96
-
97
- assert_select 'span.error'
98
- assert_no_select 'span.error b', 'markup'
99
- end
100
-
101
83
  test 'error should generate an error message with raw HTML tags' do
102
- with_error_for @user, :name, :error_prefix => '<b>Name</b>'.html_safe
103
- assert_select 'span.error', "Name can&#x27;t be blank"
84
+ with_error_for @user, :name, error_prefix: '<b>Name</b>'
85
+ assert_select 'span.error', "Name can't be blank"
104
86
  assert_select 'span.error b', "Name"
105
87
  end
106
88
 
@@ -108,7 +90,7 @@ class ErrorTest < ActionView::TestCase
108
90
 
109
91
  test 'full error should generate an full error tag for the attribute' do
110
92
  with_full_error_for @user, :name
111
- assert_select 'span.error', "Super User Name! can&#x27;t be blank"
93
+ assert_select 'span.error', "Super User Name! can't be blank"
112
94
  end
113
95
 
114
96
  test 'full error should generate an full error tag with a clean HTML' do
@@ -117,15 +99,15 @@ class ErrorTest < ActionView::TestCase
117
99
  end
118
100
 
119
101
  test 'full error should allow passing options to full error tag' do
120
- with_full_error_for @user, :name, :id => 'name_error', :error_prefix => "Your name"
121
- assert_select 'span.error#name_error', "Your name can&#x27;t be blank"
102
+ with_full_error_for @user, :name, id: 'name_error', error_prefix: "Your name"
103
+ assert_select 'span.error#name_error', "Your name can't be blank"
122
104
  end
123
105
 
124
106
  test 'full error should not modify the options hash' do
125
- options = { :id => 'name_error' }
107
+ options = { id: 'name_error' }
126
108
  with_full_error_for @user, :name, options
127
- assert_select 'span.error#name_error', "Super User Name! can&#x27;t be blank"
128
- assert_equal({ :id => 'name_error' }, options)
109
+ assert_select 'span.error#name_error', "Super User Name! can't be blank"
110
+ assert_equal({ id: 'name_error' }, options)
129
111
  end
130
112
 
131
113
  # CUSTOM WRAPPERS
@@ -133,36 +115,7 @@ class ErrorTest < ActionView::TestCase
133
115
  test 'error with custom wrappers works' do
134
116
  swap_wrapper do
135
117
  with_error_for @user, :name
136
- assert_select 'span.omg_error', "can&#x27;t be blank"
118
+ assert_select 'span.omg_error', "can't be blank"
137
119
  end
138
120
  end
139
-
140
- # CUSTOM ERRORS
141
-
142
- test 'input with custom error works' do
143
- with_custom_error_for(@user, :name, :error => "Super User Name! can't be blank")
144
-
145
- assert_select 'span.error', "Super User Name! can&#x27;t be blank"
146
- end
147
-
148
- test 'input with custom error does not generate the error if there is no error on the attribute' do
149
- error_text = "Super User Active! can't be blank"
150
- with_form_for @user, :active, :error => error_text
151
-
152
- assert_no_select 'span.error'
153
- end
154
-
155
- test 'input with custom error escapes the error text' do
156
- with_form_for @user, :name, :error => 'error must not contain <b>markup</b>'
157
-
158
- assert_select 'span.error'
159
- assert_no_select 'span.error b', 'markup'
160
- end
161
-
162
- test 'input with custom error does not escape the error text if it is safe' do
163
- with_form_for @user, :name, :error => 'error must contain <b>markup</b>'.html_safe
164
-
165
- assert_select 'span.error'
166
- assert_select 'span.error b', 'markup'
167
- end
168
121
  end
@@ -22,16 +22,24 @@ class FormBuilderTest < ActionView::TestCase
22
22
  end
23
23
  end
24
24
 
25
+ test 'builder should work without controller' do
26
+ stub_any_instance ActionView::TestCase, :controller, nil do
27
+ simple_form_for @user do |f|
28
+ assert f.input(:name)
29
+ end
30
+ end
31
+ end
32
+
25
33
  test 'builder input should allow a block to configure input' do
26
34
  with_form_for @user, :name do
27
- text_field_tag :foo, :bar, :id => :cool
35
+ text_field_tag :foo, :bar, id: :cool
28
36
  end
29
37
  assert_no_select 'input.string'
30
38
  assert_select 'input#cool'
31
39
  end
32
40
 
33
41
  test 'builder should allow adding custom input mappings for default input types' do
34
- swap SimpleForm, :input_mappings => { /count$/ => :integer } do
42
+ swap SimpleForm, input_mappings: { /count$/ => :integer } do
35
43
  with_form_for @user, :post_count
36
44
  assert_no_select 'form input#user_post_count.string'
37
45
  assert_select 'form input#user_post_count.numeric.integer'
@@ -39,7 +47,7 @@ class FormBuilderTest < ActionView::TestCase
39
47
  end
40
48
 
41
49
  test 'builder should allow to skip input_type class' do
42
- swap SimpleForm, :generate_additional_classes_for => [:label, :wrapper] do
50
+ swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
43
51
  with_form_for @user, :post_count
44
52
  assert_no_select "form input#user_post_count.integer"
45
53
  assert_select "form input#user_post_count"
@@ -47,7 +55,7 @@ class FormBuilderTest < ActionView::TestCase
47
55
  end
48
56
 
49
57
  test 'builder should allow to add additional classes only for wrapper' do
50
- swap SimpleForm, :generate_additional_classes_for => [:wrapper] do
58
+ swap SimpleForm, generate_additional_classes_for: [:wrapper] do
51
59
  with_form_for @user, :post_count
52
60
  assert_no_select "form input#user_post_count.string"
53
61
  assert_no_select "form label#user_post_count.string"
@@ -56,7 +64,7 @@ class FormBuilderTest < ActionView::TestCase
56
64
  end
57
65
 
58
66
  test 'builder should allow adding custom input mappings for integer input types' do
59
- swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
67
+ swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
60
68
  with_form_for @user, :lock_version
61
69
  assert_no_select 'form input#user_lock_version.integer'
62
70
  assert_select 'form input#user_lock_version.hidden'
@@ -64,7 +72,7 @@ class FormBuilderTest < ActionView::TestCase
64
72
  end
65
73
 
66
74
  test 'builder uses the first matching custom input map when more than one matches' do
67
- swap SimpleForm, :input_mappings => { /count$/ => :integer, /^post_/ => :password } do
75
+ swap SimpleForm, input_mappings: { /count$/ => :integer, /^post_/ => :password } do
68
76
  with_form_for @user, :post_count
69
77
  assert_no_select 'form input#user_post_count.password'
70
78
  assert_select 'form input#user_post_count.numeric.integer'
@@ -72,13 +80,26 @@ class FormBuilderTest < ActionView::TestCase
72
80
  end
73
81
 
74
82
  test 'builder uses the custom map only for matched attributes' do
75
- swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
83
+ swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
76
84
  with_form_for @user, :post_count
77
85
  assert_no_select 'form input#user_post_count.hidden'
78
86
  assert_select 'form input#user_post_count.string'
79
87
  end
80
88
  end
81
89
 
90
+ test 'builder allow to use numbers in the model name' do
91
+ user = UserNumber1And2.build(tags: [Tag.new(nil, 'Tag1')])
92
+
93
+ with_concat_form_for(user, url: '/') do |f|
94
+ f.simple_fields_for(:tags) do |tags|
95
+ tags.input :name
96
+ end
97
+ end
98
+
99
+ assert_select 'form .user_number1_and2_tags_name'
100
+ assert_no_select 'form .user_number1_and2_tags_1_name'
101
+ end
102
+
82
103
  # INPUT TYPES
83
104
  test 'builder should generate text fields for string columns' do
84
105
  with_form_for @user, :name
@@ -156,64 +177,62 @@ class FormBuilderTest < ActionView::TestCase
156
177
  end
157
178
 
158
179
  test 'builder should generate file for file columns' do
159
- @user.avatar = mock("file")
160
- @user.avatar.expects(:respond_to?).with(:mounted_as).returns(false)
161
- @user.avatar.expects(:respond_to?).with(:file?).returns(false)
162
- @user.avatar.expects(:respond_to?).with(:public_filename).returns(true)
180
+ @user.avatar = MiniTest::Mock.new
181
+ @user.avatar.expect(:public_filename, true)
163
182
 
164
183
  with_form_for @user, :avatar
165
184
  assert_select 'form input#user_avatar.file'
166
185
  end
167
186
 
168
187
  test 'builder should generate file for attributes that are real db columns but have file methods' do
169
- @user.home_picture = mock("file")
170
- @user.home_picture.expects(:respond_to?).with(:mounted_as).returns(true)
188
+ @user.home_picture = MiniTest::Mock.new
189
+ @user.home_picture.expect(:mounted_as, true)
171
190
 
172
191
  with_form_for @user, :home_picture
173
192
  assert_select 'form input#user_home_picture.file'
174
193
  end
175
194
 
176
195
  test 'build should generate select if a collection is given' do
177
- with_form_for @user, :age, :collection => 1..60
196
+ with_form_for @user, :age, collection: 1..60
178
197
  assert_select 'form select#user_age.select'
179
198
  end
180
199
 
181
200
  test 'builder should allow overriding default input type for text' do
182
- with_form_for @user, :name, :as => :text
201
+ with_form_for @user, :name, as: :text
183
202
  assert_no_select 'form input#user_name'
184
203
  assert_select 'form textarea#user_name.text'
185
204
 
186
- with_form_for @user, :active, :as => :radio_buttons
205
+ with_form_for @user, :active, as: :radio_buttons
187
206
  assert_no_select 'form input[type=checkbox]'
188
- assert_select 'form input.radio_buttons[type=radio]', :count => 2
207
+ assert_select 'form input.radio_buttons[type=radio]', count: 2
189
208
 
190
- with_form_for @user, :born_at, :as => :string
209
+ with_form_for @user, :born_at, as: :string
191
210
  assert_no_select 'form select'
192
211
  assert_select 'form input#user_born_at.string'
193
212
  end
194
213
 
195
214
  # COMMON OPTIONS
196
215
  test 'builder should add chosen form class' do
197
- swap SimpleForm, :form_class => :my_custom_class do
216
+ swap SimpleForm, form_class: :my_custom_class do
198
217
  with_form_for @user, :name
199
218
  assert_select 'form.my_custom_class'
200
219
  end
201
220
  end
202
221
 
203
222
  test 'builder should allow passing options to input' do
204
- with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
223
+ with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
205
224
  assert_select 'form input#my_input.my_input.string'
206
225
  end
207
226
 
208
227
  test 'builder should not propagate input options to wrapper' do
209
- with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
228
+ with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
210
229
  assert_no_select 'form div.input.my_input.string'
211
230
  assert_select 'form input#my_input.my_input.string'
212
231
  end
213
232
 
214
233
  test 'builder should not propagate input options to wrapper with custom wrapper' do
215
234
  swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
216
- with_form_for @user, :name, :input_html => { :class => 'my_input' }
235
+ with_form_for @user, :name, input_html: { class: 'my_input' }
217
236
  assert_no_select 'form div.input.my_input'
218
237
  assert_select 'form input.my_input.string'
219
238
  end
@@ -221,7 +240,7 @@ class FormBuilderTest < ActionView::TestCase
221
240
 
222
241
  test 'builder should not propagate label options to wrapper with custom wrapper' do
223
242
  swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
224
- with_form_for @user, :name, :label_html => { :class => 'my_label' }
243
+ with_form_for @user, :name, label_html: { class: 'my_label' }
225
244
  assert_no_select 'form div.label.my_label'
226
245
  assert_select 'form label.my_label.string'
227
246
  end
@@ -233,22 +252,22 @@ class FormBuilderTest < ActionView::TestCase
233
252
  end
234
253
 
235
254
  test 'builder should be able to disable the label for a input' do
236
- with_form_for @user, :name, :label => false
255
+ with_form_for @user, :name, label: false
237
256
  assert_no_select 'form label'
238
257
  end
239
258
 
240
259
  test 'builder should be able to disable the label for an input and return a html safe string' do
241
- with_form_for @user, :name, :label => false, :wrapper => custom_wrapper_with_wrapped_label_input
260
+ with_form_for @user, :name, label: false, wrapper: custom_wrapper_with_wrapped_label_input
242
261
  assert_select 'form input#user_name'
243
262
  end
244
263
 
245
264
  test 'builder should use custom label' do
246
- with_form_for @user, :name, :label => 'Yay!'
265
+ with_form_for @user, :name, label: 'Yay!'
247
266
  assert_select 'form label', /Yay!/
248
267
  end
249
268
 
250
269
  test 'builder should pass options to label' do
251
- with_form_for @user, :name, :label_html => { :id => "cool" }
270
+ with_form_for @user, :name, label_html: { id: "cool" }
252
271
  assert_select 'form label#cool', /Name/
253
272
  end
254
273
 
@@ -258,21 +277,21 @@ class FormBuilderTest < ActionView::TestCase
258
277
  end
259
278
 
260
279
  test 'builder should be able to add a hint for a input' do
261
- with_form_for @user, :name, :hint => 'test'
280
+ with_form_for @user, :name, hint: 'test'
262
281
  assert_select 'span.hint', 'test'
263
282
  end
264
283
 
265
284
  test 'builder should be able to disable a hint even if it exists in i18n' do
266
- store_translations(:en, :simple_form => { :hints => { :name => 'Hint test' } }) do
267
- SimpleForm::Inputs::Base.any_instance.expects(:hint).never
268
-
269
- with_form_for @user, :name, :hint => false
270
- assert_no_select 'span.hint'
285
+ store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
286
+ stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
287
+ with_form_for @user, :name, hint: false
288
+ assert_no_select 'span.hint'
289
+ end
271
290
  end
272
291
  end
273
292
 
274
293
  test 'builder should pass options to hint' do
275
- with_form_for @user, :name, :hint => 'test', :hint_html => { :id => "cool" }
294
+ with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }
276
295
  assert_select 'span.hint#cool', 'test'
277
296
  end
278
297
 
@@ -283,24 +302,24 @@ class FormBuilderTest < ActionView::TestCase
283
302
 
284
303
  test 'builder should generate errors for attribute with errors' do
285
304
  with_form_for @user, :name
286
- assert_select 'span.error', "can&#x27;t be blank"
305
+ assert_select 'span.error', "can't be blank"
287
306
  end
288
307
 
289
308
  test 'builder should be able to disable showing errors for a input' do
290
- with_form_for @user, :name, :error => false
309
+ with_form_for @user, :name, error: false
291
310
  assert_no_select 'span.error'
292
311
  end
293
312
 
294
313
  test 'builder should pass options to errors' do
295
- with_form_for @user, :name, :error_html => { :id => "cool" }
296
- assert_select 'span.error#cool', "can&#x27;t be blank"
314
+ with_form_for @user, :name, error_html: { id: "cool" }
315
+ assert_select 'span.error#cool', "can't be blank"
297
316
  end
298
317
 
299
318
  test 'placeholder should not be generated when set to false' do
300
- store_translations(:en, :simple_form => { :placeholders => { :user => {
301
- :name => 'Name goes here'
319
+ store_translations(:en, simple_form: { placeholders: { user: {
320
+ name: 'Name goes here'
302
321
  } } }) do
303
- with_form_for @user, :name, :placeholder => false
322
+ with_form_for @user, :name, placeholder: false
304
323
  assert_no_select 'input[placeholder]'
305
324
  end
306
325
  end
@@ -308,14 +327,14 @@ class FormBuilderTest < ActionView::TestCase
308
327
  # DEFAULT OPTIONS
309
328
  [:input, :input_field].each do |method|
310
329
  test "builder should receive a default argument and pass it to the inputs when calling '#{method}'" do
311
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
330
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
312
331
  f.send(method, :name)
313
332
  end
314
333
  assert_select 'input.default_class'
315
334
  end
316
335
 
317
336
  test "builder should receive a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
318
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
337
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
319
338
  concat(f.send(method, :name))
320
339
  concat(f.send(method, :credit_limit))
321
340
  end
@@ -327,7 +346,7 @@ class FormBuilderTest < ActionView::TestCase
327
346
  test "builder should receive a default argument and pass it to the inputs and nested form when calling '#{method}'" do
328
347
  @user.company = Company.new(1, 'Empresa')
329
348
 
330
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
349
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
331
350
  concat(f.send(method, :name))
332
351
  concat(f.simple_fields_for(:company) do |company_form|
333
352
  concat(company_form.send(method, :name))
@@ -340,29 +359,29 @@ class FormBuilderTest < ActionView::TestCase
340
359
  end
341
360
 
342
361
  test "builder should receive a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
343
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
344
- f.input :name, :input_html => { :id => 'specific_id' }
362
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
363
+ f.input :name, input_html: { id: 'specific_id' }
345
364
  end
346
365
  assert_select 'input.default_class#specific_id'
347
366
  end
348
367
 
349
368
  test "builder should receive a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
350
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
351
- f.input_field :name, :id => 'specific_id'
369
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
370
+ f.input_field :name, id: 'specific_id'
352
371
  end
353
372
  assert_select 'input.default_class#specific_id'
354
373
  end
355
374
 
356
375
  test "builder should receive a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
357
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
358
- f.input :name, :input_html => { :id => 'specific_id' }
376
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
377
+ f.input :name, input_html: { id: 'specific_id' }
359
378
  end
360
379
  assert_select 'input.default_class#specific_id'
361
380
  end
362
381
 
363
382
  test "builder should receive a default argument and pass it to the inputs when calling 'input_field', overwriting the defaults with specific options" do
364
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
365
- f.input_field :name, :id => 'specific_id'
383
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
384
+ f.input_field :name, id: 'specific_id'
366
385
  end
367
386
  assert_select 'input.default_class#specific_id'
368
387
  end
@@ -386,9 +405,9 @@ class FormBuilderTest < ActionView::TestCase
386
405
  end
387
406
 
388
407
  test 'builder should allow overriding input type when object is not present' do
389
- with_form_for :project, :created_at, :as => :datetime
408
+ with_form_for :project, :created_at, as: :datetime
390
409
  assert_select 'form select.datetime#project_created_at_1i'
391
- with_form_for :project, :budget, :as => :decimal
410
+ with_form_for :project, :budget, as: :decimal
392
411
  assert_select 'form input.decimal#project_budget'
393
412
  end
394
413
 
@@ -14,43 +14,37 @@ class HintTest < ActionView::TestCase
14
14
  end
15
15
 
16
16
  test 'hint should be generated with optional text' do
17
- with_hint_for @user, :name, :hint => 'Use with care...'
17
+ with_hint_for @user, :name, hint: 'Use with care...'
18
18
  assert_select 'span.hint', 'Use with care...'
19
19
  end
20
20
 
21
21
  test 'hint should not modify the options hash' do
22
- options = { :hint => 'Use with care...' }
22
+ options = { hint: 'Use with care...' }
23
23
  with_hint_for @user, :name, options
24
24
  assert_select 'span.hint', 'Use with care...'
25
- assert_equal({ :hint => 'Use with care...' }, options)
25
+ assert_equal({ hint: 'Use with care...' }, options)
26
26
  end
27
27
 
28
28
  test 'hint should be generated cleanly with optional text' do
29
- with_hint_for @user, :name, :hint => 'Use with care...', :hint_tag => :span
29
+ with_hint_for @user, :name, hint: 'Use with care...', hint_tag: :span
30
30
  assert_no_select 'span.hint[hint]'
31
31
  assert_no_select 'span.hint[hint_tag]'
32
32
  assert_no_select 'span.hint[hint_html]'
33
33
  end
34
34
 
35
35
  test 'hint uses the current component tag set' do
36
- with_hint_for @user, :name, :hint => 'Use with care...', :hint_tag => :p
36
+ with_hint_for @user, :name, hint: 'Use with care...', hint_tag: :p
37
37
  assert_select 'p.hint', 'Use with care...'
38
38
  end
39
39
 
40
40
  test 'hint should be able to pass html options' do
41
- with_hint_for @user, :name, :hint => 'Yay!', :id => 'hint', :class => 'yay'
41
+ with_hint_for @user, :name, hint: 'Yay!', id: 'hint', class: 'yay'
42
42
  assert_select 'span#hint.hint.yay'
43
43
  end
44
44
 
45
45
  test 'hint should be output as html_safe' do
46
- with_hint_for @user, :name, :hint => '<b>Bold</b> and not...'.html_safe
46
+ with_hint_for @user, :name, hint: '<b>Bold</b> and not...'
47
47
  assert_select 'span.hint', 'Bold and not...'
48
- assert_select 'span.hint b', 'Bold'
49
- end
50
-
51
- test 'builder should escape hint text' do
52
- with_hint_for @user, :name, :hint => '<script>alert(1337)</script>'
53
- assert_select 'span.hint', "&lt;script&gt;alert(1337)&lt;/script&gt;"
54
48
  end
55
49
 
56
50
  # Without attribute name
@@ -67,22 +61,22 @@ class HintTest < ActionView::TestCase
67
61
  end
68
62
 
69
63
  test 'hint without attribute name uses the current component tag set' do
70
- with_hint_for @user, 'Hello World!', :hint_tag => :p
64
+ with_hint_for @user, 'Hello World!', hint_tag: :p
71
65
  assert_no_select 'p.hint[hint]'
72
66
  assert_no_select 'p.hint[hint_html]'
73
67
  assert_no_select 'p.hint[hint_tag]'
74
68
  end
75
69
 
76
70
  test 'hint without attribute name should be able to pass html options' do
77
- with_hint_for @user, 'Yay', :id => 'hint', :class => 'yay'
71
+ with_hint_for @user, 'Yay', id: 'hint', class: 'yay'
78
72
  assert_select 'span#hint.hint.yay', 'Yay'
79
73
  end
80
74
 
81
75
  # I18n
82
76
 
83
77
  test 'hint should use i18n based on model, action, and attribute to lookup translation' do
84
- store_translations(:en, :simple_form => { :hints => { :user => {
85
- :edit => { :name => 'Content of this input will be truncated...' }
78
+ store_translations(:en, simple_form: { hints: { user: {
79
+ edit: { name: 'Content of this input will be truncated...' }
86
80
  } } }) do
87
81
  with_hint_for @user, :name
88
82
  assert_select 'span.hint', 'Content of this input will be truncated...'
@@ -90,8 +84,8 @@ class HintTest < ActionView::TestCase
90
84
  end
91
85
 
92
86
  test 'hint should use i18n with model and attribute to lookup translation' do
93
- store_translations(:en, :simple_form => { :hints => { :user => {
94
- :name => 'Content of this input will be capitalized...'
87
+ store_translations(:en, simple_form: { hints: { user: {
88
+ name: 'Content of this input will be capitalized...'
95
89
  } } }) do
96
90
  with_hint_for @user, :name
97
91
  assert_select 'span.hint', 'Content of this input will be capitalized...'
@@ -99,8 +93,8 @@ class HintTest < ActionView::TestCase
99
93
  end
100
94
 
101
95
  test 'hint should use i18n under defaults namespace to lookup translation' do
102
- store_translations(:en, :simple_form => {
103
- :hints => {:defaults => {:name => 'Content of this input will be downcased...' } }
96
+ store_translations(:en, simple_form: {
97
+ hints: { defaults: { name: 'Content of this input will be downcased...' } }
104
98
  }) do
105
99
  with_hint_for @user, :name
106
100
  assert_select 'span.hint', 'Content of this input will be downcased...'
@@ -108,17 +102,17 @@ class HintTest < ActionView::TestCase
108
102
  end
109
103
 
110
104
  test 'hint should use i18n with lookup for association name' do
111
- store_translations(:en, :simple_form => { :hints => {
112
- :user => { :company => 'My company!' }
105
+ store_translations(:en, simple_form: { hints: {
106
+ user: { company: 'My company!' }
113
107
  } } ) do
114
- with_hint_for @user, :company_id, :as => :string, :reflection => Association.new(Company, :company, {})
108
+ with_hint_for @user, :company_id, as: :string, reflection: Association.new(Company, :company, {})
115
109
  assert_select 'span.hint', /My company!/
116
110
  end
117
111
  end
118
112
 
119
113
  test 'hint should output translations as html_safe' do
120
- store_translations(:en, :simple_form => { :hints => { :user => {
121
- :edit => { :name => '<b>This is bold</b> and this is not...' }
114
+ store_translations(:en, simple_form: { hints: { user: {
115
+ edit: { name: '<b>This is bold</b> and this is not...' }
122
116
  } } }) do
123
117
  with_hint_for @user, :name
124
118
  assert_select 'span.hint', 'This is bold and this is not...'
@@ -129,7 +123,7 @@ class HintTest < ActionView::TestCase
129
123
  # No object
130
124
 
131
125
  test 'hint should generate properly when object is not present' do
132
- with_hint_for :project, :name, :hint => 'Test without object'
126
+ with_hint_for :project, :name, hint: 'Test without object'
133
127
  assert_select 'span.hint', 'Test without object'
134
128
  end
135
129
 
@@ -137,8 +131,8 @@ class HintTest < ActionView::TestCase
137
131
 
138
132
  test 'hint with custom wrappers works' do
139
133
  swap_wrapper do
140
- with_hint_for @user, :name, :hint => "can't be blank"
141
- assert_select 'div.omg_hint', "can&#x27;t be blank"
134
+ with_hint_for @user, :name, hint: "can't be blank"
135
+ assert_select 'div.omg_hint', "can't be blank"
142
136
  end
143
137
  end
144
138
  end