simple_form 2.1.3 → 3.0.0.beta1

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 (72) hide show
  1. data/CHANGELOG.md +6 -54
  2. data/README.md +129 -111
  3. data/lib/generators/simple_form/install_generator.rb +4 -4
  4. data/lib/generators/simple_form/templates/README +2 -2
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +8 -11
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  8. data/lib/simple_form.rb +31 -47
  9. data/lib/simple_form/action_view_extensions/builder.rb +0 -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 +1 -1
  12. data/lib/simple_form/components.rb +1 -1
  13. data/lib/simple_form/components/errors.rb +1 -7
  14. data/lib/simple_form/components/hints.rb +2 -7
  15. data/lib/simple_form/components/html5.rb +1 -1
  16. data/lib/simple_form/components/labels.rb +4 -4
  17. data/lib/simple_form/components/maxlength.rb +1 -8
  18. data/lib/simple_form/error_notification.rb +2 -2
  19. data/lib/simple_form/form_builder.rb +144 -46
  20. data/lib/simple_form/form_builder.rb.orig +486 -0
  21. data/lib/simple_form/helpers.rb +1 -1
  22. data/lib/simple_form/inputs/base.rb +3 -10
  23. data/lib/simple_form/inputs/block_input.rb +1 -1
  24. data/lib/simple_form/inputs/boolean_input.rb +6 -6
  25. data/lib/simple_form/inputs/collection_input.rb +7 -7
  26. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  27. data/lib/simple_form/inputs/password_input.rb +0 -1
  28. data/lib/simple_form/inputs/string_input.rb +0 -1
  29. data/lib/simple_form/railtie.rb +7 -0
  30. data/lib/simple_form/tags.rb +61 -0
  31. data/lib/simple_form/version.rb +1 -1
  32. data/lib/simple_form/version.rb.orig +7 -0
  33. data/lib/simple_form/wrappers.rb +1 -1
  34. data/lib/simple_form/wrappers/builder.rb +5 -29
  35. data/lib/simple_form/wrappers/many.rb +1 -1
  36. data/lib/simple_form/wrappers/root.rb +1 -1
  37. data/test/action_view_extensions/builder_test.rb +67 -87
  38. data/test/action_view_extensions/form_helper_test.rb +16 -16
  39. data/test/components/label_test.rb +46 -46
  40. data/test/form_builder/association_test.rb +23 -23
  41. data/test/form_builder/button_test.rb +4 -4
  42. data/test/form_builder/error_notification_test.rb +8 -8
  43. data/test/form_builder/error_test.rb +18 -65
  44. data/test/form_builder/general_test.rb +45 -65
  45. data/test/form_builder/hint_test.rb +23 -29
  46. data/test/form_builder/input_field_test.rb +12 -12
  47. data/test/form_builder/label_test.rb +6 -16
  48. data/test/form_builder/wrapper_test.rb +21 -21
  49. data/test/inputs/boolean_input_test.rb +23 -35
  50. data/test/inputs/collection_check_boxes_input_test.rb +55 -55
  51. data/test/inputs/collection_radio_buttons_input_test.rb +70 -79
  52. data/test/inputs/collection_select_input_test.rb +45 -51
  53. data/test/inputs/datetime_input_test.rb +11 -11
  54. data/test/inputs/disabled_test.rb +10 -10
  55. data/test/inputs/discovery_test.rb +4 -4
  56. data/test/inputs/file_input_test.rb +1 -1
  57. data/test/inputs/general_test.rb +12 -12
  58. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  59. data/test/inputs/hidden_input_test.rb +1 -1
  60. data/test/inputs/numeric_input_test.rb +3 -3
  61. data/test/inputs/priority_input_test.rb +3 -3
  62. data/test/inputs/readonly_test.rb +12 -12
  63. data/test/inputs/required_test.rb +5 -5
  64. data/test/inputs/string_input_test.rb +10 -25
  65. data/test/inputs/text_input_test.rb +1 -1
  66. data/test/support/misc_helpers.rb +24 -24
  67. data/test/support/mock_controller.rb +6 -6
  68. data/test/support/models.rb +37 -46
  69. data/test/test_helper.rb +20 -20
  70. metadata +49 -24
  71. checksums.yaml +0 -7
  72. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -14,15 +14,15 @@ class ButtonTest < ActionView::TestCase
14
14
  end
15
15
 
16
16
  test 'builder should create buttons with options' do
17
- with_button_for :post, :submit, :class => 'my_button'
17
+ with_button_for :post, :submit, class: 'my_button'
18
18
  assert_select 'form input.button.my_button[type=submit][value=Save Post]'
19
19
  end
20
20
 
21
21
  test 'builder should not modify the options hash' do
22
- options = { :class => 'my_button' }
22
+ options = { class: 'my_button' }
23
23
  with_button_for :post, :submit, options
24
24
  assert_select 'form input.button.my_button[type=submit][value=Save Post]'
25
- assert_equal({ :class => 'my_button' }, options)
25
+ assert_equal({ class: 'my_button' }, options)
26
26
  end
27
27
 
28
28
  test 'builder should create buttons for records' do
@@ -32,7 +32,7 @@ class ButtonTest < ActionView::TestCase
32
32
  end
33
33
 
34
34
  test "builder should use the default class from the configuration" do
35
- swap SimpleForm, :button_class => 'btn' do
35
+ swap SimpleForm, button_class: 'btn' do
36
36
  with_button_for :post, :submit
37
37
  assert_select 'form input.btn[type=submit][value=Save Post]'
38
38
  end
@@ -27,7 +27,7 @@ class ErrorNotificationTest < ActionView::TestCase
27
27
  end
28
28
 
29
29
  test 'error notification uses I18n based on model to generate the notification message' do
30
- store_translations(:en, :simple_form => { :error_notification => { :user =>
30
+ store_translations(:en, simple_form: { error_notification: { user:
31
31
  'Alguns erros foram encontrados para o usuário:'
32
32
  } }) do
33
33
  with_error_notification_for @user
@@ -36,8 +36,8 @@ class ErrorNotificationTest < ActionView::TestCase
36
36
  end
37
37
 
38
38
  test 'error notification uses I18n fallbacking to default message' do
39
- store_translations(:en, :simple_form => { :error_notification => {
40
- :default_message => 'Opa! Alguns erros foram encontrados, poderia verificar?'
39
+ store_translations(:en, simple_form: { error_notification: {
40
+ default_message: 'Opa! Alguns erros foram encontrados, poderia verificar?'
41
41
  } }) do
42
42
  with_error_notification_for @user
43
43
  assert_select 'p.error_notification', 'Opa! Alguns erros foram encontrados, poderia verificar?'
@@ -45,30 +45,30 @@ class ErrorNotificationTest < ActionView::TestCase
45
45
  end
46
46
 
47
47
  test 'error notification allows passing the notification message' do
48
- with_error_notification_for @user, :message => 'Erro encontrado ao criar usuario'
48
+ with_error_notification_for @user, message: 'Erro encontrado ao criar usuario'
49
49
  assert_select 'p.error_notification', 'Erro encontrado ao criar usuario'
50
50
  end
51
51
 
52
52
  test 'error notification accepts other html options' do
53
- with_error_notification_for @user, :id => 'user_error_message', :class => 'form_error'
53
+ with_error_notification_for @user, id: 'user_error_message', class: 'form_error'
54
54
  assert_select 'p#user_error_message.form_error.error_notification'
55
55
  end
56
56
 
57
57
  test 'error notification allows configuring the wrapper element' do
58
- swap SimpleForm, :error_notification_tag => :div do
58
+ swap SimpleForm, error_notification_tag: :div do
59
59
  with_error_notification_for @user
60
60
  assert_select 'div.error_notification'
61
61
  end
62
62
  end
63
63
 
64
64
  test 'error notification can contain HTML tags' do
65
- with_error_notification_for @user, :message => 'Erro encontrado ao criar <b>usuário</b>'
65
+ with_error_notification_for @user, message: 'Erro encontrado ao criar <b>usuário</b>'
66
66
  assert_select 'p.error_notification', 'Erro encontrado ao criar usuário'
67
67
  assert_select 'p.error_notification b', 'usuário'
68
68
  end
69
69
 
70
70
  test 'error notification uses I18n based on model to generate the notification message and accepts HTML' do
71
- store_translations(:en, :simple_form => { :error_notification => { :user =>
71
+ store_translations(:en, simple_form: { error_notification: { user:
72
72
  'Alguns erros foram encontrados para o <b>usuário</b>:'
73
73
  } }) do
74
74
  with_error_notification_for @user
@@ -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
@@ -24,14 +24,14 @@ class FormBuilderTest < ActionView::TestCase
24
24
 
25
25
  test 'builder input should allow a block to configure input' do
26
26
  with_form_for @user, :name do
27
- text_field_tag :foo, :bar, :id => :cool
27
+ text_field_tag :foo, :bar, id: :cool
28
28
  end
29
29
  assert_no_select 'input.string'
30
30
  assert_select 'input#cool'
31
31
  end
32
32
 
33
33
  test 'builder should allow adding custom input mappings for default input types' do
34
- swap SimpleForm, :input_mappings => { /count$/ => :integer } do
34
+ swap SimpleForm, input_mappings: { /count$/ => :integer } do
35
35
  with_form_for @user, :post_count
36
36
  assert_no_select 'form input#user_post_count.string'
37
37
  assert_select 'form input#user_post_count.numeric.integer'
@@ -39,7 +39,7 @@ class FormBuilderTest < ActionView::TestCase
39
39
  end
40
40
 
41
41
  test 'builder should allow to skip input_type class' do
42
- swap SimpleForm, :generate_additional_classes_for => [:label, :wrapper] do
42
+ swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
43
43
  with_form_for @user, :post_count
44
44
  assert_no_select "form input#user_post_count.integer"
45
45
  assert_select "form input#user_post_count"
@@ -47,7 +47,7 @@ class FormBuilderTest < ActionView::TestCase
47
47
  end
48
48
 
49
49
  test 'builder should allow to add additional classes only for wrapper' do
50
- swap SimpleForm, :generate_additional_classes_for => [:wrapper] do
50
+ swap SimpleForm, generate_additional_classes_for: [:wrapper] do
51
51
  with_form_for @user, :post_count
52
52
  assert_no_select "form input#user_post_count.string"
53
53
  assert_no_select "form label#user_post_count.string"
@@ -56,7 +56,7 @@ class FormBuilderTest < ActionView::TestCase
56
56
  end
57
57
 
58
58
  test 'builder should allow adding custom input mappings for integer input types' do
59
- swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
59
+ swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
60
60
  with_form_for @user, :lock_version
61
61
  assert_no_select 'form input#user_lock_version.integer'
62
62
  assert_select 'form input#user_lock_version.hidden'
@@ -64,7 +64,7 @@ class FormBuilderTest < ActionView::TestCase
64
64
  end
65
65
 
66
66
  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
67
+ swap SimpleForm, input_mappings: { /count$/ => :integer, /^post_/ => :password } do
68
68
  with_form_for @user, :post_count
69
69
  assert_no_select 'form input#user_post_count.password'
70
70
  assert_select 'form input#user_post_count.numeric.integer'
@@ -72,33 +72,13 @@ class FormBuilderTest < ActionView::TestCase
72
72
  end
73
73
 
74
74
  test 'builder uses the custom map only for matched attributes' do
75
- swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
75
+ swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
76
76
  with_form_for @user, :post_count
77
77
  assert_no_select 'form input#user_post_count.hidden'
78
78
  assert_select 'form input#user_post_count.string'
79
79
  end
80
80
  end
81
81
 
82
- 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
- })
89
-
90
- user.tags = [Tag.new(nil, 'Tag1')]
91
-
92
- with_concat_form_for(user, :url => '/') do |f|
93
- f.simple_fields_for(:tags) do |tags|
94
- tags.input :name
95
- end
96
- end
97
-
98
- assert_select 'form .user_number1_and2_tags_name'
99
- assert_no_select 'form .user_number1_and2_tags_1_name'
100
- end
101
-
102
82
  # INPUT TYPES
103
83
  test 'builder should generate text fields for string columns' do
104
84
  with_form_for @user, :name
@@ -194,46 +174,46 @@ class FormBuilderTest < ActionView::TestCase
194
174
  end
195
175
 
196
176
  test 'build should generate select if a collection is given' do
197
- with_form_for @user, :age, :collection => 1..60
177
+ with_form_for @user, :age, collection: 1..60
198
178
  assert_select 'form select#user_age.select'
199
179
  end
200
180
 
201
181
  test 'builder should allow overriding default input type for text' do
202
- with_form_for @user, :name, :as => :text
182
+ with_form_for @user, :name, as: :text
203
183
  assert_no_select 'form input#user_name'
204
184
  assert_select 'form textarea#user_name.text'
205
185
 
206
- with_form_for @user, :active, :as => :radio_buttons
186
+ with_form_for @user, :active, as: :radio_buttons
207
187
  assert_no_select 'form input[type=checkbox]'
208
- assert_select 'form input.radio_buttons[type=radio]', :count => 2
188
+ assert_select 'form input.radio_buttons[type=radio]', count: 2
209
189
 
210
- with_form_for @user, :born_at, :as => :string
190
+ with_form_for @user, :born_at, as: :string
211
191
  assert_no_select 'form select'
212
192
  assert_select 'form input#user_born_at.string'
213
193
  end
214
194
 
215
195
  # COMMON OPTIONS
216
196
  test 'builder should add chosen form class' do
217
- swap SimpleForm, :form_class => :my_custom_class do
197
+ swap SimpleForm, form_class: :my_custom_class do
218
198
  with_form_for @user, :name
219
199
  assert_select 'form.my_custom_class'
220
200
  end
221
201
  end
222
202
 
223
203
  test 'builder should allow passing options to input' do
224
- with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
204
+ with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
225
205
  assert_select 'form input#my_input.my_input.string'
226
206
  end
227
207
 
228
208
  test 'builder should not propagate input options to wrapper' do
229
- with_form_for @user, :name, :input_html => { :class => 'my_input', :id => 'my_input' }
209
+ with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
230
210
  assert_no_select 'form div.input.my_input.string'
231
211
  assert_select 'form input#my_input.my_input.string'
232
212
  end
233
213
 
234
214
  test 'builder should not propagate input options to wrapper with custom wrapper' do
235
215
  swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
236
- with_form_for @user, :name, :input_html => { :class => 'my_input' }
216
+ with_form_for @user, :name, input_html: { class: 'my_input' }
237
217
  assert_no_select 'form div.input.my_input'
238
218
  assert_select 'form input.my_input.string'
239
219
  end
@@ -241,7 +221,7 @@ class FormBuilderTest < ActionView::TestCase
241
221
 
242
222
  test 'builder should not propagate label options to wrapper with custom wrapper' do
243
223
  swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
244
- with_form_for @user, :name, :label_html => { :class => 'my_label' }
224
+ with_form_for @user, :name, label_html: { class: 'my_label' }
245
225
  assert_no_select 'form div.label.my_label'
246
226
  assert_select 'form label.my_label.string'
247
227
  end
@@ -253,22 +233,22 @@ class FormBuilderTest < ActionView::TestCase
253
233
  end
254
234
 
255
235
  test 'builder should be able to disable the label for a input' do
256
- with_form_for @user, :name, :label => false
236
+ with_form_for @user, :name, label: false
257
237
  assert_no_select 'form label'
258
238
  end
259
239
 
260
240
  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
241
+ with_form_for @user, :name, label: false, wrapper: custom_wrapper_with_wrapped_label_input
262
242
  assert_select 'form input#user_name'
263
243
  end
264
244
 
265
245
  test 'builder should use custom label' do
266
- with_form_for @user, :name, :label => 'Yay!'
246
+ with_form_for @user, :name, label: 'Yay!'
267
247
  assert_select 'form label', /Yay!/
268
248
  end
269
249
 
270
250
  test 'builder should pass options to label' do
271
- with_form_for @user, :name, :label_html => { :id => "cool" }
251
+ with_form_for @user, :name, label_html: { id: "cool" }
272
252
  assert_select 'form label#cool', /Name/
273
253
  end
274
254
 
@@ -278,21 +258,21 @@ class FormBuilderTest < ActionView::TestCase
278
258
  end
279
259
 
280
260
  test 'builder should be able to add a hint for a input' do
281
- with_form_for @user, :name, :hint => 'test'
261
+ with_form_for @user, :name, hint: 'test'
282
262
  assert_select 'span.hint', 'test'
283
263
  end
284
264
 
285
265
  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
266
+ store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
287
267
  SimpleForm::Inputs::Base.any_instance.expects(:hint).never
288
268
 
289
- with_form_for @user, :name, :hint => false
269
+ with_form_for @user, :name, hint: false
290
270
  assert_no_select 'span.hint'
291
271
  end
292
272
  end
293
273
 
294
274
  test 'builder should pass options to hint' do
295
- with_form_for @user, :name, :hint => 'test', :hint_html => { :id => "cool" }
275
+ with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }
296
276
  assert_select 'span.hint#cool', 'test'
297
277
  end
298
278
 
@@ -303,24 +283,24 @@ class FormBuilderTest < ActionView::TestCase
303
283
 
304
284
  test 'builder should generate errors for attribute with errors' do
305
285
  with_form_for @user, :name
306
- assert_select 'span.error', "can&#x27;t be blank"
286
+ assert_select 'span.error', "can't be blank"
307
287
  end
308
288
 
309
289
  test 'builder should be able to disable showing errors for a input' do
310
- with_form_for @user, :name, :error => false
290
+ with_form_for @user, :name, error: false
311
291
  assert_no_select 'span.error'
312
292
  end
313
293
 
314
294
  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"
295
+ with_form_for @user, :name, error_html: { id: "cool" }
296
+ assert_select 'span.error#cool', "can't be blank"
317
297
  end
318
298
 
319
299
  test 'placeholder should not be generated when set to false' do
320
- store_translations(:en, :simple_form => { :placeholders => { :user => {
321
- :name => 'Name goes here'
300
+ store_translations(:en, simple_form: { placeholders: { user: {
301
+ name: 'Name goes here'
322
302
  } } }) do
323
- with_form_for @user, :name, :placeholder => false
303
+ with_form_for @user, :name, placeholder: false
324
304
  assert_no_select 'input[placeholder]'
325
305
  end
326
306
  end
@@ -328,14 +308,14 @@ class FormBuilderTest < ActionView::TestCase
328
308
  # DEFAULT OPTIONS
329
309
  [:input, :input_field].each do |method|
330
310
  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|
311
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
332
312
  f.send(method, :name)
333
313
  end
334
314
  assert_select 'input.default_class'
335
315
  end
336
316
 
337
317
  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|
318
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
339
319
  concat(f.send(method, :name))
340
320
  concat(f.send(method, :credit_limit))
341
321
  end
@@ -347,7 +327,7 @@ class FormBuilderTest < ActionView::TestCase
347
327
  test "builder should receive a default argument and pass it to the inputs and nested form when calling '#{method}'" do
348
328
  @user.company = Company.new(1, 'Empresa')
349
329
 
350
- 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|
351
331
  concat(f.send(method, :name))
352
332
  concat(f.simple_fields_for(:company) do |company_form|
353
333
  concat(company_form.send(method, :name))
@@ -360,29 +340,29 @@ class FormBuilderTest < ActionView::TestCase
360
340
  end
361
341
 
362
342
  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' }
343
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
344
+ f.input :name, input_html: { id: 'specific_id' }
365
345
  end
366
346
  assert_select 'input.default_class#specific_id'
367
347
  end
368
348
 
369
349
  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'
350
+ with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
351
+ f.input_field :name, id: 'specific_id'
372
352
  end
373
353
  assert_select 'input.default_class#specific_id'
374
354
  end
375
355
 
376
356
  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' }
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' }
379
359
  end
380
360
  assert_select 'input.default_class#specific_id'
381
361
  end
382
362
 
383
363
  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'
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'
386
366
  end
387
367
  assert_select 'input.default_class#specific_id'
388
368
  end
@@ -406,9 +386,9 @@ class FormBuilderTest < ActionView::TestCase
406
386
  end
407
387
 
408
388
  test 'builder should allow overriding input type when object is not present' do
409
- with_form_for :project, :created_at, :as => :datetime
389
+ with_form_for :project, :created_at, as: :datetime
410
390
  assert_select 'form select.datetime#project_created_at_1i'
411
- with_form_for :project, :budget, :as => :decimal
391
+ with_form_for :project, :budget, as: :decimal
412
392
  assert_select 'form input.decimal#project_budget'
413
393
  end
414
394