simple_form 2.1.3 → 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.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -51
  3. data/README.md +195 -161
  4. data/lib/generators/simple_form/install_generator.rb +4 -4
  5. data/lib/generators/simple_form/templates/README +2 -2
  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 +16 -16
  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 -320
  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 +154 -50
  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 -5
  26. data/lib/simple_form/inputs/collection_input.rb +7 -7
  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 -99
  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 +62 -63
  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 +24 -24
  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 -51
  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 +77 -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,7 +80,7 @@ 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'
@@ -80,16 +88,9 @@ class FormBuilderTest < ActionView::TestCase
80
88
  end
81
89
 
82
90
  test 'builder allow to use numbers in the model name' do
83
- user = UserNumber1And2.new({
84
- :id => 1,
85
- :name => 'New in SimpleForm!',
86
- :description => 'Hello!',
87
- :created_at => Time.now
88
- })
91
+ user = UserNumber1And2.build(tags: [Tag.new(nil, 'Tag1')])
89
92
 
90
- user.tags = [Tag.new(nil, 'Tag1')]
91
-
92
- with_concat_form_for(user, :url => '/') do |f|
93
+ with_concat_form_for(user, url: '/') do |f|
93
94
  f.simple_fields_for(:tags) do |tags|
94
95
  tags.input :name
95
96
  end
@@ -176,64 +177,62 @@ class FormBuilderTest < ActionView::TestCase
176
177
  end
177
178
 
178
179
  test 'builder should generate file for file columns' do
179
- @user.avatar = mock("file")
180
- @user.avatar.expects(:respond_to?).with(:mounted_as).returns(false)
181
- @user.avatar.expects(:respond_to?).with(:file?).returns(false)
182
- @user.avatar.expects(:respond_to?).with(:public_filename).returns(true)
180
+ @user.avatar = MiniTest::Mock.new
181
+ @user.avatar.expect(:public_filename, true)
183
182
 
184
183
  with_form_for @user, :avatar
185
184
  assert_select 'form input#user_avatar.file'
186
185
  end
187
186
 
188
187
  test 'builder should generate file for attributes that are real db columns but have file methods' do
189
- @user.home_picture = mock("file")
190
- @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)
191
190
 
192
191
  with_form_for @user, :home_picture
193
192
  assert_select 'form input#user_home_picture.file'
194
193
  end
195
194
 
196
195
  test 'build should generate select if a collection is given' do
197
- with_form_for @user, :age, :collection => 1..60
196
+ with_form_for @user, :age, collection: 1..60
198
197
  assert_select 'form select#user_age.select'
199
198
  end
200
199
 
201
200
  test 'builder should allow overriding default input type for text' do
202
- with_form_for @user, :name, :as => :text
201
+ with_form_for @user, :name, as: :text
203
202
  assert_no_select 'form input#user_name'
204
203
  assert_select 'form textarea#user_name.text'
205
204
 
206
- with_form_for @user, :active, :as => :radio_buttons
205
+ with_form_for @user, :active, as: :radio_buttons
207
206
  assert_no_select 'form input[type=checkbox]'
208
- assert_select 'form input.radio_buttons[type=radio]', :count => 2
207
+ assert_select 'form input.radio_buttons[type=radio]', count: 2
209
208
 
210
- with_form_for @user, :born_at, :as => :string
209
+ with_form_for @user, :born_at, as: :string
211
210
  assert_no_select 'form select'
212
211
  assert_select 'form input#user_born_at.string'
213
212
  end
214
213
 
215
214
  # COMMON OPTIONS
216
215
  test 'builder should add chosen form class' do
217
- swap SimpleForm, :form_class => :my_custom_class do
216
+ swap SimpleForm, form_class: :my_custom_class do
218
217
  with_form_for @user, :name
219
218
  assert_select 'form.my_custom_class'
220
219
  end
221
220
  end
222
221
 
223
222
  test 'builder should allow passing options to input' do
224
- 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' }
225
224
  assert_select 'form input#my_input.my_input.string'
226
225
  end
227
226
 
228
227
  test 'builder should not propagate input options to wrapper' do
229
- 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' }
230
229
  assert_no_select 'form div.input.my_input.string'
231
230
  assert_select 'form input#my_input.my_input.string'
232
231
  end
233
232
 
234
233
  test 'builder should not propagate input options to wrapper with custom wrapper' do
235
234
  swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
236
- with_form_for @user, :name, :input_html => { :class => 'my_input' }
235
+ with_form_for @user, :name, input_html: { class: 'my_input' }
237
236
  assert_no_select 'form div.input.my_input'
238
237
  assert_select 'form input.my_input.string'
239
238
  end
@@ -241,7 +240,7 @@ class FormBuilderTest < ActionView::TestCase
241
240
 
242
241
  test 'builder should not propagate label options to wrapper with custom wrapper' do
243
242
  swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
244
- with_form_for @user, :name, :label_html => { :class => 'my_label' }
243
+ with_form_for @user, :name, label_html: { class: 'my_label' }
245
244
  assert_no_select 'form div.label.my_label'
246
245
  assert_select 'form label.my_label.string'
247
246
  end
@@ -253,22 +252,22 @@ class FormBuilderTest < ActionView::TestCase
253
252
  end
254
253
 
255
254
  test 'builder should be able to disable the label for a input' do
256
- with_form_for @user, :name, :label => false
255
+ with_form_for @user, :name, label: false
257
256
  assert_no_select 'form label'
258
257
  end
259
258
 
260
259
  test 'builder should be able to disable the label for an input and return a html safe string' do
261
- 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
262
261
  assert_select 'form input#user_name'
263
262
  end
264
263
 
265
264
  test 'builder should use custom label' do
266
- with_form_for @user, :name, :label => 'Yay!'
265
+ with_form_for @user, :name, label: 'Yay!'
267
266
  assert_select 'form label', /Yay!/
268
267
  end
269
268
 
270
269
  test 'builder should pass options to label' do
271
- with_form_for @user, :name, :label_html => { :id => "cool" }
270
+ with_form_for @user, :name, label_html: { id: "cool" }
272
271
  assert_select 'form label#cool', /Name/
273
272
  end
274
273
 
@@ -278,21 +277,21 @@ class FormBuilderTest < ActionView::TestCase
278
277
  end
279
278
 
280
279
  test 'builder should be able to add a hint for a input' do
281
- with_form_for @user, :name, :hint => 'test'
280
+ with_form_for @user, :name, hint: 'test'
282
281
  assert_select 'span.hint', 'test'
283
282
  end
284
283
 
285
284
  test 'builder should be able to disable a hint even if it exists in i18n' do
286
- store_translations(:en, :simple_form => { :hints => { :name => 'Hint test' } }) do
287
- SimpleForm::Inputs::Base.any_instance.expects(:hint).never
288
-
289
- with_form_for @user, :name, :hint => false
290
- 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
291
290
  end
292
291
  end
293
292
 
294
293
  test 'builder should pass options to hint' do
295
- with_form_for @user, :name, :hint => 'test', :hint_html => { :id => "cool" }
294
+ with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }
296
295
  assert_select 'span.hint#cool', 'test'
297
296
  end
298
297
 
@@ -303,24 +302,24 @@ class FormBuilderTest < ActionView::TestCase
303
302
 
304
303
  test 'builder should generate errors for attribute with errors' do
305
304
  with_form_for @user, :name
306
- assert_select 'span.error', "can&#x27;t be blank"
305
+ assert_select 'span.error', "can't be blank"
307
306
  end
308
307
 
309
308
  test 'builder should be able to disable showing errors for a input' do
310
- with_form_for @user, :name, :error => false
309
+ with_form_for @user, :name, error: false
311
310
  assert_no_select 'span.error'
312
311
  end
313
312
 
314
313
  test 'builder should pass options to errors' do
315
- with_form_for @user, :name, :error_html => { :id => "cool" }
316
- 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"
317
316
  end
318
317
 
319
318
  test 'placeholder should not be generated when set to false' do
320
- store_translations(:en, :simple_form => { :placeholders => { :user => {
321
- :name => 'Name goes here'
319
+ store_translations(:en, simple_form: { placeholders: { user: {
320
+ name: 'Name goes here'
322
321
  } } }) do
323
- with_form_for @user, :name, :placeholder => false
322
+ with_form_for @user, :name, placeholder: false
324
323
  assert_no_select 'input[placeholder]'
325
324
  end
326
325
  end
@@ -328,14 +327,14 @@ class FormBuilderTest < ActionView::TestCase
328
327
  # DEFAULT OPTIONS
329
328
  [:input, :input_field].each do |method|
330
329
  test "builder should receive a default argument and pass it to the inputs when calling '#{method}'" do
331
- 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|
332
331
  f.send(method, :name)
333
332
  end
334
333
  assert_select 'input.default_class'
335
334
  end
336
335
 
337
336
  test "builder should receive a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
338
- 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|
339
338
  concat(f.send(method, :name))
340
339
  concat(f.send(method, :credit_limit))
341
340
  end
@@ -347,7 +346,7 @@ class FormBuilderTest < ActionView::TestCase
347
346
  test "builder should receive a default argument and pass it to the inputs and nested form when calling '#{method}'" do
348
347
  @user.company = Company.new(1, 'Empresa')
349
348
 
350
- 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|
351
350
  concat(f.send(method, :name))
352
351
  concat(f.simple_fields_for(:company) do |company_form|
353
352
  concat(company_form.send(method, :name))
@@ -360,29 +359,29 @@ class FormBuilderTest < ActionView::TestCase
360
359
  end
361
360
 
362
361
  test "builder should receive a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
363
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
364
- 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' }
365
364
  end
366
365
  assert_select 'input.default_class#specific_id'
367
366
  end
368
367
 
369
368
  test "builder should receive a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
370
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
371
- 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'
372
371
  end
373
372
  assert_select 'input.default_class#specific_id'
374
373
  end
375
374
 
376
375
  test "builder should receive a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
377
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
378
- 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' }
379
378
  end
380
379
  assert_select 'input.default_class#specific_id'
381
380
  end
382
381
 
383
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
384
- with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
385
- 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'
386
385
  end
387
386
  assert_select 'input.default_class#specific_id'
388
387
  end
@@ -406,9 +405,9 @@ class FormBuilderTest < ActionView::TestCase
406
405
  end
407
406
 
408
407
  test 'builder should allow overriding input type when object is not present' do
409
- with_form_for :project, :created_at, :as => :datetime
408
+ with_form_for :project, :created_at, as: :datetime
410
409
  assert_select 'form select.datetime#project_created_at_1i'
411
- with_form_for :project, :budget, :as => :decimal
410
+ with_form_for :project, :budget, as: :decimal
412
411
  assert_select 'form input.decimal#project_budget'
413
412
  end
414
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