simple_form 3.0.4 → 3.1.0.rc2

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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -43
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +179 -73
  5. data/lib/generators/simple_form/install_generator.rb +2 -2
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +25 -5
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +108 -24
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
  10. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
  12. data/lib/simple_form/components/errors.rb +27 -5
  13. data/lib/simple_form/components/hints.rb +2 -2
  14. data/lib/simple_form/components/html5.rb +1 -1
  15. data/lib/simple_form/components/label_input.rb +20 -2
  16. data/lib/simple_form/components/labels.rb +10 -6
  17. data/lib/simple_form/components/maxlength.rb +1 -1
  18. data/lib/simple_form/components/min_max.rb +1 -1
  19. data/lib/simple_form/components/pattern.rb +1 -1
  20. data/lib/simple_form/components/placeholders.rb +2 -2
  21. data/lib/simple_form/components/readonly.rb +1 -1
  22. data/lib/simple_form/form_builder.rb +121 -74
  23. data/lib/simple_form/helpers.rb +5 -5
  24. data/lib/simple_form/inputs/base.rb +34 -12
  25. data/lib/simple_form/inputs/block_input.rb +1 -1
  26. data/lib/simple_form/inputs/boolean_input.rb +27 -14
  27. data/lib/simple_form/inputs/collection_input.rb +32 -9
  28. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
  29. data/lib/simple_form/inputs/collection_select_input.rb +4 -2
  30. data/lib/simple_form/inputs/date_time_input.rb +12 -2
  31. data/lib/simple_form/inputs/file_input.rb +4 -2
  32. data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
  33. data/lib/simple_form/inputs/hidden_input.rb +4 -2
  34. data/lib/simple_form/inputs/numeric_input.rb +5 -4
  35. data/lib/simple_form/inputs/password_input.rb +4 -2
  36. data/lib/simple_form/inputs/priority_input.rb +4 -2
  37. data/lib/simple_form/inputs/range_input.rb +1 -1
  38. data/lib/simple_form/inputs/string_input.rb +4 -2
  39. data/lib/simple_form/inputs/text_input.rb +4 -2
  40. data/lib/simple_form/railtie.rb +7 -0
  41. data/lib/simple_form/tags.rb +8 -0
  42. data/lib/simple_form/version.rb +1 -1
  43. data/lib/simple_form/wrappers/builder.rb +6 -6
  44. data/lib/simple_form/wrappers/leaf.rb +28 -0
  45. data/lib/simple_form/wrappers/many.rb +6 -6
  46. data/lib/simple_form/wrappers/root.rb +1 -1
  47. data/lib/simple_form/wrappers/single.rb +5 -3
  48. data/lib/simple_form/wrappers.rb +1 -0
  49. data/lib/simple_form.rb +46 -6
  50. data/test/action_view_extensions/builder_test.rb +5 -5
  51. data/test/action_view_extensions/form_helper_test.rb +13 -13
  52. data/test/components/label_test.rb +36 -36
  53. data/test/form_builder/association_test.rb +21 -4
  54. data/test/form_builder/button_test.rb +5 -5
  55. data/test/form_builder/error_notification_test.rb +1 -1
  56. data/test/form_builder/error_test.rb +68 -49
  57. data/test/form_builder/general_test.rb +67 -62
  58. data/test/form_builder/hint_test.rb +15 -15
  59. data/test/form_builder/input_field_test.rb +33 -49
  60. data/test/form_builder/label_test.rb +44 -12
  61. data/test/form_builder/wrapper_test.rb +120 -19
  62. data/test/generators/simple_form_generator_test.rb +2 -2
  63. data/test/inputs/boolean_input_test.rb +54 -6
  64. data/test/inputs/collection_check_boxes_input_test.rb +63 -17
  65. data/test/inputs/collection_radio_buttons_input_test.rb +112 -36
  66. data/test/inputs/collection_select_input_test.rb +141 -36
  67. data/test/inputs/datetime_input_test.rb +116 -49
  68. data/test/inputs/disabled_test.rb +15 -15
  69. data/test/inputs/discovery_test.rb +56 -6
  70. data/test/inputs/file_input_test.rb +2 -2
  71. data/test/inputs/general_test.rb +20 -20
  72. data/test/inputs/grouped_collection_select_input_test.rb +38 -2
  73. data/test/inputs/hidden_input_test.rb +4 -4
  74. data/test/inputs/numeric_input_test.rb +24 -24
  75. data/test/inputs/priority_input_test.rb +7 -7
  76. data/test/inputs/readonly_test.rb +19 -19
  77. data/test/inputs/required_test.rb +13 -13
  78. data/test/inputs/string_input_test.rb +41 -21
  79. data/test/inputs/text_input_test.rb +4 -4
  80. data/test/simple_form_test.rb +8 -0
  81. data/test/support/discovery_inputs.rb +32 -2
  82. data/test/support/misc_helpers.rb +66 -6
  83. data/test/support/models.rb +50 -24
  84. metadata +7 -7
@@ -14,69 +14,65 @@ 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
- test 'error should not generate content for attribute without errors' do
17
+ test 'error does not generate content for attribute without errors' do
22
18
  with_error_for @user, :active
23
19
  assert_no_select 'span.error'
24
20
  end
25
21
 
26
- test 'error should not generate messages when object is not present' do
22
+ test 'error does not generate messages when object is not present' do
27
23
  with_error_for :project, :name
28
24
  assert_no_select 'span.error'
29
25
  end
30
26
 
31
- test "error should not generate messages when object doesn't respond to errors method" do
27
+ test "error does not generate messages when object doesn't respond to errors method" do
32
28
  @user.instance_eval { undef errors }
33
29
  with_error_for @user, :name
34
30
  assert_no_select 'span.error'
35
31
  end
36
32
 
37
- test 'error should generate messages for attribute with single error' do
33
+ test 'error generates messages for attribute with single error' do
38
34
  with_error_for @user, :name
39
- assert_select 'span.error', "can&#39;t be blank"
35
+ assert_select 'span.error', "can't be blank"
40
36
  end
41
37
 
42
- test 'error should generate messages for attribute with one error when using first' do
38
+ test 'error generates messages for attribute with one error when using first' do
43
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
- test 'error should generate messages for attribute with several errors when using to_sentence' do
45
+ test 'error generates messages for attribute with several errors when using to_sentence' do
50
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
- test 'error should be able to pass html options' do
52
+ test 'error is able to pass html options' do
57
53
  with_error_for @user, :name, id: 'error', class: 'yay'
58
54
  assert_select 'span#error.error.yay'
59
55
  end
60
56
 
61
- test 'error should not modify the options hash' do
57
+ test 'error does not modify the options hash' do
62
58
  options = { id: 'error', class: 'yay' }
63
59
  with_error_for @user, :name, options
64
60
  assert_select 'span#error.error.yay'
65
61
  assert_equal({ id: 'error', class: 'yay' }, options)
66
62
  end
67
63
 
68
- test 'error should find errors on attribute and association' do
64
+ test 'error finds errors on attribute and association' do
69
65
  with_error_for @user, :company_id, as: :select,
70
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
 
74
- test 'error should generate an error tag with a clean HTML' do
70
+ test 'error generates an error tag with a clean HTML' do
75
71
  with_error_for @user, :name
76
72
  assert_no_select 'span.error[error_html]'
77
73
  end
78
74
 
79
- test 'error should generate an error tag with a clean HTML when errors options are present' do
75
+ test 'error generates an error tag with a clean HTML when errors options are present' do
80
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]'
@@ -84,47 +80,38 @@ class ErrorTest < ActionView::TestCase
84
80
  assert_no_select 'p.error[error_method]'
85
81
  end
86
82
 
87
- test 'error should escape error prefix text' do
83
+ test 'error escapes error prefix text' do
88
84
  with_error_for @user, :name, error_prefix: '<b>Name</b>'
89
- assert_select 'span.error', "&lt;b&gt;Name&lt;/b&gt; can&#39;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'
85
+ assert_select 'span.error', "&lt;b&gt;Name&lt;/b&gt; can't be blank"
99
86
  end
100
87
 
101
- test 'error should generate an error message with raw HTML tags' do
88
+ test 'error generates an error message with raw HTML tags' do
102
89
  with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
103
- assert_select 'span.error', "Name can&#39;t be blank"
90
+ assert_select 'span.error', "Name can't be blank"
104
91
  assert_select 'span.error b', "Name"
105
92
  end
106
93
 
107
94
  # FULL ERRORS
108
95
 
109
- test 'full error should generate an full error tag for the attribute' do
96
+ test 'full error generates a full error tag for the attribute' do
110
97
  with_full_error_for @user, :name
111
- assert_select 'span.error', "Super User Name! can&#39;t be blank"
98
+ assert_select 'span.error', "Super User Name! can't be blank"
112
99
  end
113
100
 
114
- test 'full error should generate an full error tag with a clean HTML' do
101
+ test 'full error generates a full error tag with a clean HTML' do
115
102
  with_full_error_for @user, :name
116
103
  assert_no_select 'span.error[error_html]'
117
104
  end
118
105
 
119
- test 'full error should allow passing options to full error tag' do
106
+ test 'full error allows passing options to full error tag' do
120
107
  with_full_error_for @user, :name, id: 'name_error', error_prefix: "Your name"
121
- assert_select 'span.error#name_error', "Your name can&#39;t be blank"
108
+ assert_select 'span.error#name_error', "Your name can't be blank"
122
109
  end
123
110
 
124
- test 'full error should not modify the options hash' do
111
+ test 'full error does not modify the options hash' do
125
112
  options = { id: 'name_error' }
126
113
  with_full_error_for @user, :name, options
127
- assert_select 'span.error#name_error', "Super User Name! can&#39;t be blank"
114
+ assert_select 'span.error#name_error', "Super User Name! can't be blank"
128
115
  assert_equal({ id: 'name_error' }, options)
129
116
  end
130
117
 
@@ -133,36 +120,68 @@ class ErrorTest < ActionView::TestCase
133
120
  test 'error with custom wrappers works' do
134
121
  swap_wrapper do
135
122
  with_error_for @user, :name
136
- assert_select 'span.omg_error', "can&#39;t be blank"
123
+ assert_select 'span.omg_error', "can't be blank"
124
+ end
125
+ end
126
+
127
+ # FULL_ERROR_WRAPPER
128
+
129
+ test 'full error finds errors on association' do
130
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
131
+ with_form_for @user, :company_id, as: :select
132
+ assert_select 'span.error', 'Company must be valid'
133
+ end
134
+ end
135
+
136
+ test 'full error can be disabled' do
137
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
138
+ with_form_for @user, :company_id, as: :select, full_error: false
139
+ assert_no_select 'span.error'
140
+ end
141
+ end
142
+
143
+ test 'full error can be disabled setting error to false' do
144
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
145
+ with_form_for @user, :company_id, as: :select, error: false
146
+ assert_no_select 'span.error'
137
147
  end
138
148
  end
139
149
 
140
150
  # CUSTOM ERRORS
141
151
 
142
152
  test 'input with custom error works' do
143
- with_custom_error_for(@user, :name, error: "Super User Name! can't be blank")
153
+ error_text = "Super User Name! can't be blank"
154
+ with_form_for @user, :name, error: error_text
144
155
 
145
- assert_select 'span.error', "Super User Name! can&#39;t be blank"
156
+ assert_select 'span.error', error_text
157
+ end
158
+
159
+ test 'input with error option as true does not use custom error' do
160
+ with_form_for @user, :name, error: true
161
+
162
+ assert_select 'span.error', "can't be blank"
146
163
  end
147
164
 
148
165
  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
166
+ with_form_for @user, :active, error: "Super User Active! can't be blank"
151
167
 
152
168
  assert_no_select 'span.error'
153
169
  end
154
170
 
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>'
171
+ test 'input with custom error works when using full_error component' do
172
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
173
+ error_text = "Super User Name! can't be blank"
174
+ with_form_for @user, :name, error: error_text
157
175
 
158
- assert_select 'span.error'
159
- assert_no_select 'span.error b', 'markup'
176
+ assert_select 'span.error', error_text
177
+ end
160
178
  end
161
179
 
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
180
+ test 'input with custom error when using full_error component does not generate the error if there is no error on the attribute' do
181
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
182
+ with_form_for @user, :active, error: "Super User Active! can't be blank"
164
183
 
165
- assert_select 'span.error'
166
- assert_select 'span.error b', 'markup'
184
+ assert_no_select 'span.error'
185
+ end
167
186
  end
168
187
  end
@@ -8,7 +8,7 @@ class FormBuilderTest < ActionView::TestCase
8
8
  end
9
9
  end
10
10
 
11
- test 'nested simple fields should yield an instance of FormBuilder' do
11
+ test 'nested simple fields yields an instance of FormBuilder' do
12
12
  simple_form_for :user do |f|
13
13
  f.simple_fields_for :posts do |posts_form|
14
14
  assert posts_form.instance_of?(SimpleForm::FormBuilder)
@@ -22,7 +22,7 @@ class FormBuilderTest < ActionView::TestCase
22
22
  end
23
23
  end
24
24
 
25
- test 'builder should work without controller' do
25
+ test 'builder works without controller' do
26
26
  stub_any_instance ActionView::TestCase, :controller, nil do
27
27
  simple_form_for @user do |f|
28
28
  assert f.input(:name)
@@ -30,7 +30,7 @@ class FormBuilderTest < ActionView::TestCase
30
30
  end
31
31
  end
32
32
 
33
- test 'builder input should allow a block to configure input' do
33
+ test 'builder input allows a block to configure input' do
34
34
  with_form_for @user, :name do
35
35
  text_field_tag :foo, :bar, id: :cool
36
36
  end
@@ -38,7 +38,7 @@ class FormBuilderTest < ActionView::TestCase
38
38
  assert_select 'input#cool'
39
39
  end
40
40
 
41
- test 'builder should allow adding custom input mappings for default input types' do
41
+ test 'builder allows adding custom input mappings for default input types' do
42
42
  swap SimpleForm, input_mappings: { /count$/ => :integer } do
43
43
  with_form_for @user, :post_count
44
44
  assert_no_select 'form input#user_post_count.string'
@@ -46,7 +46,7 @@ class FormBuilderTest < ActionView::TestCase
46
46
  end
47
47
  end
48
48
 
49
- test 'builder should allow to skip input_type class' do
49
+ test 'builder allows to skip input_type class' do
50
50
  swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
51
51
  with_form_for @user, :post_count
52
52
  assert_no_select "form input#user_post_count.integer"
@@ -54,7 +54,7 @@ class FormBuilderTest < ActionView::TestCase
54
54
  end
55
55
  end
56
56
 
57
- test 'builder should allow to add additional classes only for wrapper' do
57
+ test 'builder allows to add additional classes only for wrapper' do
58
58
  swap SimpleForm, generate_additional_classes_for: [:wrapper] do
59
59
  with_form_for @user, :post_count
60
60
  assert_no_select "form input#user_post_count.string"
@@ -63,7 +63,7 @@ class FormBuilderTest < ActionView::TestCase
63
63
  end
64
64
  end
65
65
 
66
- test 'builder should allow adding custom input mappings for integer input types' do
66
+ test 'builder allows adding custom input mappings for integer input types' do
67
67
  swap SimpleForm, input_mappings: { /lock_version/ => :hidden } do
68
68
  with_form_for @user, :lock_version
69
69
  assert_no_select 'form input#user_lock_version.integer'
@@ -101,82 +101,87 @@ class FormBuilderTest < ActionView::TestCase
101
101
  end
102
102
 
103
103
  # INPUT TYPES
104
- test 'builder should generate text fields for string columns' do
104
+ test 'builder generates text fields for string columns' do
105
105
  with_form_for @user, :name
106
106
  assert_select 'form input#user_name.string'
107
107
  end
108
108
 
109
- test 'builder should generate text areas for text columns' do
109
+ test 'builder generates text areas for text columns' do
110
110
  with_form_for @user, :description
111
111
  assert_select 'form textarea#user_description.text'
112
112
  end
113
113
 
114
- test 'builder should generate a checkbox for boolean columns' do
114
+ test 'builder generates a checkbox for boolean columns' do
115
115
  with_form_for @user, :active
116
116
  assert_select 'form input[type=checkbox]#user_active.boolean'
117
117
  end
118
118
 
119
- test 'builder should use integer text field for integer columns' do
119
+ test 'builder uses integer text field for integer columns' do
120
120
  with_form_for @user, :age
121
121
  assert_select 'form input#user_age.numeric.integer'
122
122
  end
123
123
 
124
- test 'builder should generate decimal text field for decimal columns' do
124
+ test 'builder generates decimal text field for decimal columns' do
125
125
  with_form_for @user, :credit_limit
126
126
  assert_select 'form input#user_credit_limit.numeric.decimal'
127
127
  end
128
128
 
129
- test 'builder should generate password fields for columns that matches password' do
129
+ test 'builder generates uuid fields for uuid columns' do
130
+ with_form_for @user, :uuid
131
+ assert_select 'form input#user_uuid.string.uuid'
132
+ end
133
+
134
+ test 'builder generates password fields for columns that matches password' do
130
135
  with_form_for @user, :password
131
136
  assert_select 'form input#user_password.password'
132
137
  end
133
138
 
134
- test 'builder should generate country fields for columns that matches country' do
139
+ test 'builder generates country fields for columns that matches country' do
135
140
  with_form_for @user, :residence_country
136
141
  assert_select 'form select#user_residence_country.country'
137
142
  end
138
143
 
139
- test 'builder should generate time_zone fields for columns that matches time_zone' do
144
+ test 'builder generates time_zone fields for columns that matches time_zone' do
140
145
  with_form_for @user, :time_zone
141
146
  assert_select 'form select#user_time_zone.time_zone'
142
147
  end
143
148
 
144
- test 'builder should generate email fields for columns that matches email' do
149
+ test 'builder generates email fields for columns that matches email' do
145
150
  with_form_for @user, :email
146
151
  assert_select 'form input#user_email.string.email'
147
152
  end
148
153
 
149
- test 'builder should generate tel fields for columns that matches phone' do
154
+ test 'builder generates tel fields for columns that matches phone' do
150
155
  with_form_for @user, :phone_number
151
156
  assert_select 'form input#user_phone_number.string.tel'
152
157
  end
153
158
 
154
- test 'builder should generate url fields for columns that matches url' do
159
+ test 'builder generates url fields for columns that matches url' do
155
160
  with_form_for @user, :url
156
161
  assert_select 'form input#user_url.string.url'
157
162
  end
158
163
 
159
- test 'builder should generate date select for date columns' do
164
+ test 'builder generates date select for date columns' do
160
165
  with_form_for @user, :born_at
161
166
  assert_select 'form select#user_born_at_1i.date'
162
167
  end
163
168
 
164
- test 'builder should generate time select for time columns' do
169
+ test 'builder generates time select for time columns' do
165
170
  with_form_for @user, :delivery_time
166
171
  assert_select 'form select#user_delivery_time_4i.time'
167
172
  end
168
173
 
169
- test 'builder should generate datetime select for datetime columns' do
174
+ test 'builder generates datetime select for datetime columns' do
170
175
  with_form_for @user, :created_at
171
176
  assert_select 'form select#user_created_at_1i.datetime'
172
177
  end
173
178
 
174
- test 'builder should generate datetime select for timestamp columns' do
179
+ test 'builder generates datetime select for timestamp columns' do
175
180
  with_form_for @user, :updated_at
176
181
  assert_select 'form select#user_updated_at_1i.datetime'
177
182
  end
178
183
 
179
- test 'builder should generate file for file columns' do
184
+ test 'builder generates file for file columns' do
180
185
  @user.avatar = MiniTest::Mock.new
181
186
  @user.avatar.expect(:public_filename, true)
182
187
 
@@ -184,7 +189,7 @@ class FormBuilderTest < ActionView::TestCase
184
189
  assert_select 'form input#user_avatar.file'
185
190
  end
186
191
 
187
- test 'builder should generate file for attributes that are real db columns but have file methods' do
192
+ test 'builder generates file for attributes that are real db columns but have file methods' do
188
193
  @user.home_picture = MiniTest::Mock.new
189
194
  @user.home_picture.expect(:mounted_as, true)
190
195
 
@@ -192,12 +197,12 @@ class FormBuilderTest < ActionView::TestCase
192
197
  assert_select 'form input#user_home_picture.file'
193
198
  end
194
199
 
195
- test 'build should generate select if a collection is given' do
200
+ test 'build generates select if a collection is given' do
196
201
  with_form_for @user, :age, collection: 1..60
197
202
  assert_select 'form select#user_age.select'
198
203
  end
199
204
 
200
- test 'builder should allow overriding default input type for text' do
205
+ test 'builder allows overriding default input type for text' do
201
206
  with_form_for @user, :name, as: :text
202
207
  assert_no_select 'form input#user_name'
203
208
  assert_select 'form textarea#user_name.text'
@@ -212,25 +217,25 @@ class FormBuilderTest < ActionView::TestCase
212
217
  end
213
218
 
214
219
  # COMMON OPTIONS
215
- test 'builder should add chosen form class' do
220
+ test 'builder adds chosen form class' do
216
221
  swap SimpleForm, form_class: :my_custom_class do
217
222
  with_form_for @user, :name
218
223
  assert_select 'form.my_custom_class'
219
224
  end
220
225
  end
221
226
 
222
- test 'builder should allow passing options to input' do
227
+ test 'builder allows passing options to input' do
223
228
  with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
224
229
  assert_select 'form input#my_input.my_input.string'
225
230
  end
226
231
 
227
- test 'builder should not propagate input options to wrapper' do
232
+ test 'builder does not propagate input options to wrapper' do
228
233
  with_form_for @user, :name, input_html: { class: 'my_input', id: 'my_input' }
229
234
  assert_no_select 'form div.input.my_input.string'
230
235
  assert_select 'form input#my_input.my_input.string'
231
236
  end
232
237
 
233
- test 'builder should not propagate input options to wrapper with custom wrapper' do
238
+ test 'builder does not propagate input options to wrapper with custom wrapper' do
234
239
  swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
235
240
  with_form_for @user, :name, input_html: { class: 'my_input' }
236
241
  assert_no_select 'form div.input.my_input'
@@ -238,7 +243,7 @@ class FormBuilderTest < ActionView::TestCase
238
243
  end
239
244
  end
240
245
 
241
- test 'builder should not propagate label options to wrapper with custom wrapper' do
246
+ test 'builder does not propagate label options to wrapper with custom wrapper' do
242
247
  swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
243
248
  with_form_for @user, :name, label_html: { class: 'my_label' }
244
249
  assert_no_select 'form div.label.my_label'
@@ -246,42 +251,42 @@ class FormBuilderTest < ActionView::TestCase
246
251
  end
247
252
  end
248
253
 
249
- test 'builder should generate a input with label' do
254
+ test 'builder generates an input with label' do
250
255
  with_form_for @user, :name
251
256
  assert_select 'form label.string[for=user_name]', /Name/
252
257
  end
253
258
 
254
- test 'builder should be able to disable the label for a input' do
259
+ test 'builder is able to disable the label for an input' do
255
260
  with_form_for @user, :name, label: false
256
261
  assert_no_select 'form label'
257
262
  end
258
263
 
259
- test 'builder should be able to disable the label for an input and return a html safe string' do
264
+ test 'builder is able to disable the label for an input and return a html safe string' do
260
265
  with_form_for @user, :name, label: false, wrapper: custom_wrapper_with_wrapped_label_input
261
266
  assert_select 'form input#user_name'
262
267
  end
263
268
 
264
- test 'builder should use custom label' do
269
+ test 'builder uses custom label' do
265
270
  with_form_for @user, :name, label: 'Yay!'
266
271
  assert_select 'form label', /Yay!/
267
272
  end
268
273
 
269
- test 'builder should pass options to label' do
274
+ test 'builder passes options to label' do
270
275
  with_form_for @user, :name, label_html: { id: "cool" }
271
276
  assert_select 'form label#cool', /Name/
272
277
  end
273
278
 
274
- test 'builder should not generate hints for a input' do
279
+ test 'builder does not generate hints for an input' do
275
280
  with_form_for @user, :name
276
281
  assert_no_select 'span.hint'
277
282
  end
278
283
 
279
- test 'builder should be able to add a hint for a input' do
284
+ test 'builder is able to add a hint for an input' do
280
285
  with_form_for @user, :name, hint: 'test'
281
286
  assert_select 'span.hint', 'test'
282
287
  end
283
288
 
284
- test 'builder should be able to disable a hint even if it exists in i18n' do
289
+ test 'builder is able to disable a hint even if it exists in i18n' do
285
290
  store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
286
291
  stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
287
292
  with_form_for @user, :name, hint: false
@@ -290,32 +295,32 @@ class FormBuilderTest < ActionView::TestCase
290
295
  end
291
296
  end
292
297
 
293
- test 'builder should pass options to hint' do
298
+ test 'builder passes options to hint' do
294
299
  with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }
295
300
  assert_select 'span.hint#cool', 'test'
296
301
  end
297
302
 
298
- test 'builder should generate errors for attribute without errors' do
303
+ test 'builder generates errors for attribute without errors' do
299
304
  with_form_for @user, :credit_limit
300
305
  assert_no_select 'span.errors'
301
306
  end
302
307
 
303
- test 'builder should generate errors for attribute with errors' do
308
+ test 'builder generates errors for attribute with errors' do
304
309
  with_form_for @user, :name
305
- assert_select 'span.error', "can&#39;t be blank"
310
+ assert_select 'span.error', "can't be blank"
306
311
  end
307
312
 
308
- test 'builder should be able to disable showing errors for a input' do
313
+ test 'builder is able to disable showing errors for an input' do
309
314
  with_form_for @user, :name, error: false
310
315
  assert_no_select 'span.error'
311
316
  end
312
317
 
313
- test 'builder should pass options to errors' do
318
+ test 'builder passes options to errors' do
314
319
  with_form_for @user, :name, error_html: { id: "cool" }
315
- assert_select 'span.error#cool', "can&#39;t be blank"
320
+ assert_select 'span.error#cool', "can't be blank"
316
321
  end
317
322
 
318
- test 'placeholder should not be generated when set to false' do
323
+ test 'placeholder does not be generated when set to false' do
319
324
  store_translations(:en, simple_form: { placeholders: { user: {
320
325
  name: 'Name goes here'
321
326
  } } }) do
@@ -326,14 +331,14 @@ class FormBuilderTest < ActionView::TestCase
326
331
 
327
332
  # DEFAULT OPTIONS
328
333
  [:input, :input_field].each do |method|
329
- test "builder should receive a default argument and pass it to the inputs when calling '#{method}'" do
334
+ test "builder receives a default argument and pass it to the inputs when calling '#{method}'" do
330
335
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
331
336
  f.send(method, :name)
332
337
  end
333
338
  assert_select 'input.default_class'
334
339
  end
335
340
 
336
- test "builder should receive a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
341
+ test "builder receives a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
337
342
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
338
343
  concat(f.send(method, :name))
339
344
  concat(f.send(method, :credit_limit))
@@ -343,7 +348,7 @@ class FormBuilderTest < ActionView::TestCase
343
348
  assert_no_select "input.string[name='user[credit_limit]']"
344
349
  end
345
350
 
346
- test "builder should receive a default argument and pass it to the inputs and nested form when calling '#{method}'" do
351
+ test "builder receives a default argument and pass it to the inputs and nested form when calling '#{method}'" do
347
352
  @user.company = Company.new(1, 'Empresa')
348
353
 
349
354
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
@@ -358,28 +363,28 @@ class FormBuilderTest < ActionView::TestCase
358
363
  end
359
364
  end
360
365
 
361
- test "builder should receive a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
366
+ test "builder receives a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
362
367
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
363
368
  f.input :name, input_html: { id: 'specific_id' }
364
369
  end
365
370
  assert_select 'input.default_class#specific_id'
366
371
  end
367
372
 
368
- test "builder should receive a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
373
+ test "builder receives a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
369
374
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
370
375
  f.input_field :name, id: 'specific_id'
371
376
  end
372
377
  assert_select 'input.default_class#specific_id'
373
378
  end
374
379
 
375
- test "builder should receive a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
380
+ test "builder receives a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
376
381
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
377
382
  f.input :name, input_html: { id: 'specific_id' }
378
383
  end
379
384
  assert_select 'input.default_class#specific_id'
380
385
  end
381
386
 
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
387
+ test "builder receives a default argument and pass it to the inputs when calling 'input_field', overwriting the defaults with specific options" do
383
388
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
384
389
  f.input_field :name, id: 'specific_id'
385
390
  end
@@ -387,24 +392,24 @@ class FormBuilderTest < ActionView::TestCase
387
392
  end
388
393
 
389
394
  # WITHOUT OBJECT
390
- test 'builder should generate properly when object is not present' do
395
+ test 'builder generates properly when object is not present' do
391
396
  with_form_for :project, :name
392
397
  assert_select 'form input.string#project_name'
393
398
  end
394
399
 
395
- test 'builder should generate password fields based on attribute name when object is not present' do
400
+ test 'builder generates password fields based on attribute name when object is not present' do
396
401
  with_form_for :project, :password_confirmation
397
402
  assert_select 'form input[type=password].password#project_password_confirmation'
398
403
  end
399
404
 
400
- test 'builder should generate text fields by default for all attributes when object is not present' do
405
+ test 'builder generates text fields by default for all attributes when object is not present' do
401
406
  with_form_for :project, :created_at
402
407
  assert_select 'form input.string#project_created_at'
403
408
  with_form_for :project, :budget
404
409
  assert_select 'form input.string#project_budget'
405
410
  end
406
411
 
407
- test 'builder should allow overriding input type when object is not present' do
412
+ test 'builder allows overriding input type when object is not present' do
408
413
  with_form_for :project, :created_at, as: :datetime
409
414
  assert_select 'form select.datetime#project_created_at_1i'
410
415
  with_form_for :project, :budget, as: :decimal
@@ -412,24 +417,24 @@ class FormBuilderTest < ActionView::TestCase
412
417
  end
413
418
 
414
419
  # CUSTOM FORM BUILDER
415
- test 'custom builder should inherit mappings' do
420
+ test 'custom builder inherits mappings' do
416
421
  with_custom_form_for @user, :email
417
422
  assert_select 'form input[type=email]#user_email.custom'
418
423
  end
419
424
 
420
- test 'form with CustomMapTypeFormBuilder should use custom map type builder' do
425
+ test 'form with CustomMapTypeFormBuilder uses custom map type builder' do
421
426
  with_concat_custom_mapping_form_for(:user) do |user|
422
427
  assert user.instance_of?(CustomMapTypeFormBuilder)
423
428
  end
424
429
  end
425
430
 
426
- test 'form with CustomMapTypeFormBuilder should use custom mapping' do
431
+ test 'form with CustomMapTypeFormBuilder uses custom mapping' do
427
432
  with_concat_custom_mapping_form_for(:user) do |user|
428
433
  assert_equal SimpleForm::Inputs::StringInput, user.class.mappings[:custom_type]
429
434
  end
430
435
  end
431
436
 
432
- test 'form without CustomMapTypeFormBuilder should not use custom mapping' do
437
+ test 'form without CustomMapTypeFormBuilder does not use custom mapping' do
433
438
  with_concat_form_for(:user) do |user|
434
439
  assert_nil user.class.mappings[:custom_type]
435
440
  end