simple_form 3.1.0.rc1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -1
  3. data/README.md +64 -16
  4. data/lib/generators/simple_form/install_generator.rb +2 -2
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +9 -4
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -15
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +85 -4
  8. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  9. data/lib/simple_form/action_view_extensions/form_helper.rb +5 -1
  10. data/lib/simple_form/components/errors.rb +3 -5
  11. data/lib/simple_form/components/labels.rb +1 -1
  12. data/lib/simple_form/form_builder.rb +34 -19
  13. data/lib/simple_form/inputs/boolean_input.rb +8 -5
  14. data/lib/simple_form/inputs/collection_input.rb +2 -4
  15. data/lib/simple_form/tags.rb +3 -4
  16. data/lib/simple_form/version.rb +1 -1
  17. data/lib/simple_form/wrappers/builder.rb +2 -2
  18. data/lib/simple_form/wrappers/many.rb +1 -0
  19. data/lib/simple_form.rb +21 -2
  20. data/test/action_view_extensions/builder_test.rb +34 -34
  21. data/test/action_view_extensions/form_helper_test.rb +33 -14
  22. data/test/components/label_test.rb +36 -36
  23. data/test/form_builder/association_test.rb +41 -41
  24. data/test/form_builder/button_test.rb +10 -10
  25. data/test/form_builder/error_test.rb +88 -29
  26. data/test/form_builder/general_test.rb +89 -64
  27. data/test/form_builder/hint_test.rb +18 -18
  28. data/test/form_builder/input_field_test.rb +59 -19
  29. data/test/form_builder/label_test.rb +23 -14
  30. data/test/form_builder/wrapper_test.rb +70 -21
  31. data/test/generators/simple_form_generator_test.rb +2 -2
  32. data/test/inputs/boolean_input_test.rb +17 -9
  33. data/test/inputs/collection_check_boxes_input_test.rb +46 -7
  34. data/test/inputs/collection_radio_buttons_input_test.rb +65 -26
  35. data/test/inputs/collection_select_input_test.rb +62 -62
  36. data/test/inputs/datetime_input_test.rb +24 -24
  37. data/test/inputs/disabled_test.rb +15 -15
  38. data/test/inputs/discovery_test.rb +44 -5
  39. data/test/inputs/file_input_test.rb +2 -2
  40. data/test/inputs/general_test.rb +20 -20
  41. data/test/inputs/grouped_collection_select_input_test.rb +10 -10
  42. data/test/inputs/hidden_input_test.rb +4 -4
  43. data/test/inputs/numeric_input_test.rb +43 -43
  44. data/test/inputs/priority_input_test.rb +13 -13
  45. data/test/inputs/readonly_test.rb +19 -19
  46. data/test/inputs/required_test.rb +13 -13
  47. data/test/inputs/string_input_test.rb +33 -33
  48. data/test/inputs/text_input_test.rb +7 -7
  49. data/test/support/discovery_inputs.rb +20 -0
  50. data/test/support/misc_helpers.rb +28 -0
  51. data/test/support/models.rb +13 -2
  52. data/test/test_helper.rb +5 -1
  53. metadata +4 -4
@@ -14,65 +14,65 @@ class ErrorTest < ActionView::TestCase
14
14
  end
15
15
  end
16
16
 
17
- test 'error should not generate content for attribute without errors' do
17
+ test 'error does not generate content for attribute without errors' do
18
18
  with_error_for @user, :active
19
19
  assert_no_select 'span.error'
20
20
  end
21
21
 
22
- 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
23
23
  with_error_for :project, :name
24
24
  assert_no_select 'span.error'
25
25
  end
26
26
 
27
- 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
28
28
  @user.instance_eval { undef errors }
29
29
  with_error_for @user, :name
30
30
  assert_no_select 'span.error'
31
31
  end
32
32
 
33
- test 'error should generate messages for attribute with single error' do
33
+ test 'error generates messages for attribute with single error' do
34
34
  with_error_for @user, :name
35
- assert_select 'span.error', "can't be blank"
35
+ assert_select 'span.error', "cannot be blank"
36
36
  end
37
37
 
38
- 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
39
39
  swap SimpleForm, error_method: :first do
40
40
  with_error_for @user, :age
41
41
  assert_select 'span.error', 'is not a number'
42
42
  end
43
43
  end
44
44
 
45
- 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
46
46
  swap SimpleForm, error_method: :to_sentence do
47
47
  with_error_for @user, :age
48
48
  assert_select 'span.error', 'is not a number and must be greater than 18'
49
49
  end
50
50
  end
51
51
 
52
- test 'error should be able to pass html options' do
52
+ test 'error is able to pass html options' do
53
53
  with_error_for @user, :name, id: 'error', class: 'yay'
54
54
  assert_select 'span#error.error.yay'
55
55
  end
56
56
 
57
- test 'error should not modify the options hash' do
57
+ test 'error does not modify the options hash' do
58
58
  options = { id: 'error', class: 'yay' }
59
59
  with_error_for @user, :name, options
60
60
  assert_select 'span#error.error.yay'
61
61
  assert_equal({ id: 'error', class: 'yay' }, options)
62
62
  end
63
63
 
64
- test 'error should find errors on attribute and association' do
64
+ test 'error finds errors on attribute and association' do
65
65
  with_error_for @user, :company_id, as: :select,
66
66
  error_method: :to_sentence, reflection: Association.new(Company, :company, {})
67
67
  assert_select 'span.error', 'must be valid and company must be present'
68
68
  end
69
69
 
70
- test 'error should generate an error tag with a clean HTML' do
70
+ test 'error generates an error tag with a clean HTML' do
71
71
  with_error_for @user, :name
72
72
  assert_no_select 'span.error[error_html]'
73
73
  end
74
74
 
75
- 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
76
76
  with_error_for @user, :name, error_tag: :p, error_prefix: 'Name', error_method: :first
77
77
  assert_no_select 'p.error[error_html]'
78
78
  assert_no_select 'p.error[error_tag]'
@@ -80,59 +80,86 @@ class ErrorTest < ActionView::TestCase
80
80
  assert_no_select 'p.error[error_method]'
81
81
  end
82
82
 
83
- test 'error should escape error prefix text' do
83
+ test 'error escapes error prefix text' do
84
84
  with_error_for @user, :name, error_prefix: '<b>Name</b>'
85
- assert_select 'span.error', "&lt;b&gt;Name&lt;/b&gt; can't be blank"
85
+ assert_no_select 'span.error b'
86
86
  end
87
87
 
88
- test 'error should generate an error message with raw HTML tags' do
88
+ test 'error escapes error text' do
89
+ @user.errors.add(:action, 'must not contain <b>markup</b>')
90
+
91
+ with_error_for @user, :action
92
+
93
+ assert_select 'span.error'
94
+ assert_no_select 'span.error b', 'markup'
95
+ end
96
+
97
+
98
+ test 'error generates an error message with raw HTML tags' do
89
99
  with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
90
- assert_select 'span.error', "Name can't be blank"
100
+ assert_select 'span.error', "Name cannot be blank"
91
101
  assert_select 'span.error b', "Name"
92
102
  end
93
103
 
94
104
  # FULL ERRORS
95
105
 
96
- test 'full error should generate an full error tag for the attribute' do
106
+ test 'full error generates a full error tag for the attribute' do
97
107
  with_full_error_for @user, :name
98
- assert_select 'span.error', "Super User Name! can't be blank"
108
+ assert_select 'span.error', "Super User Name! cannot be blank"
99
109
  end
100
110
 
101
- test 'full error should generate an full error tag with a clean HTML' do
111
+ test 'full error generates a full error tag with a clean HTML' do
102
112
  with_full_error_for @user, :name
103
113
  assert_no_select 'span.error[error_html]'
104
114
  end
105
115
 
106
- test 'full error should allow passing options to full error tag' do
116
+ test 'full error allows passing options to full error tag' do
107
117
  with_full_error_for @user, :name, id: 'name_error', error_prefix: "Your name"
108
- assert_select 'span.error#name_error', "Your name can't be blank"
118
+ assert_select 'span.error#name_error', "Your name cannot be blank"
109
119
  end
110
120
 
111
- test 'full error should not modify the options hash' do
121
+ test 'full error does not modify the options hash' do
112
122
  options = { id: 'name_error' }
113
123
  with_full_error_for @user, :name, options
114
- assert_select 'span.error#name_error', "Super User Name! can't be blank"
124
+ assert_select 'span.error#name_error', "Super User Name! cannot be blank"
115
125
  assert_equal({ id: 'name_error' }, options)
116
126
  end
117
127
 
128
+ test 'full error escapes error text' do
129
+ @user.errors.add(:action, 'must not contain <b>markup</b>')
130
+
131
+ with_full_error_for @user, :action
132
+
133
+ assert_select 'span.error'
134
+ assert_no_select 'span.error b', 'markup'
135
+ end
136
+
118
137
  # CUSTOM WRAPPERS
119
138
 
120
139
  test 'error with custom wrappers works' do
121
140
  swap_wrapper do
122
141
  with_error_for @user, :name
123
- assert_select 'span.omg_error', "can't be blank"
142
+ assert_select 'span.omg_error', "cannot be blank"
124
143
  end
125
144
  end
126
145
 
127
146
  # FULL_ERROR_WRAPPER
128
147
 
129
- test 'full error should find errors on association' do
148
+ test 'full error finds errors on association' do
130
149
  swap_wrapper :default, self.custom_wrapper_with_full_error do
131
150
  with_form_for @user, :company_id, as: :select
132
151
  assert_select 'span.error', 'Company must be valid'
133
152
  end
134
153
  end
135
154
 
155
+ test 'full error finds errors on association with reflection' do
156
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
157
+ with_form_for @user, :company_id, as: :select,
158
+ reflection: Association.new(Company, :company, {})
159
+ assert_select 'span.error', 'Company must be valid'
160
+ end
161
+ end
162
+
136
163
  test 'full error can be disabled' do
137
164
  swap_wrapper :default, self.custom_wrapper_with_full_error do
138
165
  with_form_for @user, :company_id, as: :select, full_error: false
@@ -150,7 +177,7 @@ class ErrorTest < ActionView::TestCase
150
177
  # CUSTOM ERRORS
151
178
 
152
179
  test 'input with custom error works' do
153
- error_text = "Super User Name! can't be blank"
180
+ error_text = "Super User Name! cannot be blank"
154
181
  with_form_for @user, :name, error: error_text
155
182
 
156
183
  assert_select 'span.error', error_text
@@ -159,24 +186,56 @@ class ErrorTest < ActionView::TestCase
159
186
  test 'input with error option as true does not use custom error' do
160
187
  with_form_for @user, :name, error: true
161
188
 
162
- assert_select 'span.error', "can't be blank"
189
+ assert_select 'span.error', "cannot be blank"
163
190
  end
164
191
 
165
192
  test 'input with custom error does not generate the error if there is no error on the attribute' do
166
- with_form_for @user, :active, error: "Super User Active! can't be blank"
193
+ with_form_for @user, :active, error: "Super User Active! cannot be blank"
167
194
 
168
195
  assert_no_select 'span.error'
169
196
  end
170
197
 
171
198
  test 'input with custom error works when using full_error component' do
172
199
  swap_wrapper :default, self.custom_wrapper_with_full_error do
173
- error_text = "Super User Name! can't be blank"
200
+ error_text = "Super User Name! cannot be blank"
174
201
  with_form_for @user, :name, error: error_text
175
202
 
176
203
  assert_select 'span.error', error_text
177
204
  end
178
205
  end
179
206
 
207
+ test 'input with custom error escapes the error text' do
208
+ with_form_for @user, :name, error: 'error must not contain <b>markup</b>'
209
+
210
+ assert_select 'span.error'
211
+ assert_no_select 'span.error b', 'markup'
212
+ end
213
+
214
+ test 'input with custom error does not escape the error text if it is safe' do
215
+ with_form_for @user, :name, error: 'error must contain <b>markup</b>'.html_safe
216
+
217
+ assert_select 'span.error'
218
+ assert_select 'span.error b', 'markup'
219
+ end
220
+
221
+ test 'input with custom error escapes the error text using full_error component' do
222
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
223
+ with_form_for @user, :name, error: 'error must not contain <b>markup</b>'
224
+
225
+ assert_select 'span.error'
226
+ assert_no_select 'span.error b', 'markup'
227
+ end
228
+ end
229
+
230
+ test 'input with custom error does not escape the error text if it is safe using full_error component' do
231
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
232
+ with_form_for @user, :name, error: 'error must contain <b>markup</b>'.html_safe
233
+
234
+ assert_select 'span.error'
235
+ assert_select 'span.error b', 'markup'
236
+ end
237
+ end
238
+
180
239
  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
240
  swap_wrapper :default, self.custom_wrapper_with_full_error do
182
241
  with_form_for @user, :active, error: "Super User Active! can't be blank"