simple_form 5.2.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +3 -4
  5. data/lib/simple_form/components/label_input.rb +1 -1
  6. data/lib/simple_form/form_builder.rb +1 -5
  7. data/lib/simple_form/railtie.rb +4 -0
  8. data/lib/simple_form/version.rb +1 -1
  9. data/lib/simple_form/wrappers/leaf.rb +1 -1
  10. data/lib/simple_form.rb +8 -4
  11. metadata +5 -85
  12. data/test/action_view_extensions/builder_test.rb +0 -634
  13. data/test/action_view_extensions/form_helper_test.rb +0 -172
  14. data/test/components/custom_components_test.rb +0 -62
  15. data/test/components/label_test.rb +0 -352
  16. data/test/form_builder/association_test.rb +0 -252
  17. data/test/form_builder/button_test.rb +0 -48
  18. data/test/form_builder/error_notification_test.rb +0 -80
  19. data/test/form_builder/error_test.rb +0 -281
  20. data/test/form_builder/general_test.rb +0 -539
  21. data/test/form_builder/hint_test.rb +0 -150
  22. data/test/form_builder/input_field_test.rb +0 -195
  23. data/test/form_builder/label_test.rb +0 -136
  24. data/test/form_builder/wrapper_test.rb +0 -378
  25. data/test/generators/simple_form_generator_test.rb +0 -43
  26. data/test/inputs/boolean_input_test.rb +0 -256
  27. data/test/inputs/collection_check_boxes_input_test.rb +0 -323
  28. data/test/inputs/collection_radio_buttons_input_test.rb +0 -446
  29. data/test/inputs/collection_select_input_test.rb +0 -380
  30. data/test/inputs/color_input_test.rb +0 -10
  31. data/test/inputs/country_input_test.rb +0 -36
  32. data/test/inputs/datetime_input_test.rb +0 -176
  33. data/test/inputs/disabled_test.rb +0 -92
  34. data/test/inputs/discovery_test.rb +0 -142
  35. data/test/inputs/file_input_test.rb +0 -17
  36. data/test/inputs/general_test.rb +0 -133
  37. data/test/inputs/grouped_collection_select_input_test.rb +0 -196
  38. data/test/inputs/hidden_input_test.rb +0 -32
  39. data/test/inputs/numeric_input_test.rb +0 -177
  40. data/test/inputs/readonly_test.rb +0 -102
  41. data/test/inputs/required_test.rb +0 -158
  42. data/test/inputs/rich_text_area_input_test.rb +0 -15
  43. data/test/inputs/string_input_test.rb +0 -158
  44. data/test/inputs/text_input_test.rb +0 -37
  45. data/test/inputs/time_zone_input_test.rb +0 -36
  46. data/test/simple_form_test.rb +0 -18
  47. data/test/support/discovery_inputs.rb +0 -65
  48. data/test/support/misc_helpers.rb +0 -274
  49. data/test/support/mock_controller.rb +0 -30
  50. data/test/support/models.rb +0 -357
  51. data/test/test_helper.rb +0 -95
@@ -1,252 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- class AssociationTest < ActionView::TestCase
6
- def with_association_for(object, *args)
7
- with_concat_form_for(object) do |f|
8
- f.association(*args)
9
- end
10
- end
11
-
12
- test 'builder does not allow creating an association input when no object exists' do
13
- assert_raise ArgumentError do
14
- with_association_for :post, :author
15
- end
16
- end
17
-
18
- test 'builder association works with decorated object responsive to #to_model' do
19
- assert_nothing_raised do
20
- with_association_for @decorated_user, :company
21
- end
22
- end
23
-
24
- test 'builder association with a block calls simple_fields_for' do
25
- simple_form_for @user do |f|
26
- f.association :posts do |posts_form|
27
- assert posts_form.instance_of?(SimpleForm::FormBuilder)
28
- end
29
- end
30
- end
31
-
32
- test 'builder association forwards collection to simple_fields_for' do
33
- calls = 0
34
- simple_form_for @user do |f|
35
- f.association :company, collection: Company.all do |c|
36
- calls += 1
37
- end
38
- end
39
-
40
- assert_equal 3, calls
41
- end
42
-
43
- test 'builder association marks input as required based on both association and attribute' do
44
- swap SimpleForm, required_by_default: false do
45
- with_association_for @validating_user, :company, collection: []
46
- assert_select 'label.required'
47
- end
48
- end
49
-
50
- test 'builder preloads collection association' do
51
- value = @user.tags = MiniTest::Mock.new
52
- value.expect(:to_a, value)
53
-
54
- with_association_for @user, :tags
55
- assert_select 'form select.select#user_tag_ids'
56
- assert_select 'form select option[value="1"]', 'Tag 1'
57
- assert_select 'form select option[value="2"]', 'Tag 2'
58
- assert_select 'form select option[value="3"]', 'Tag 3'
59
-
60
- value.verify
61
- end
62
-
63
- test 'builder does not preload collection association if preload is false' do
64
- value = @user.tags = MiniTest::Mock.new
65
- value.expect(:to_a, nil)
66
-
67
- with_association_for @user, :tags, preload: false
68
- assert_select 'form select.select#user_tag_ids'
69
- assert_select 'form select option[value="1"]', 'Tag 1'
70
- assert_select 'form select option[value="2"]', 'Tag 2'
71
- assert_select 'form select option[value="3"]', 'Tag 3'
72
-
73
- assert_raises MockExpectationError do
74
- value.verify
75
- end
76
- end
77
-
78
- test 'builder does not preload non-collection association' do
79
- value = @user.company = MiniTest::Mock.new
80
- value.expect(:to_a, nil)
81
-
82
- with_association_for @user, :company
83
- assert_select 'form select.select#user_company_id'
84
- assert_select 'form select option[value="1"]', 'Company 1'
85
- assert_select 'form select option[value="2"]', 'Company 2'
86
- assert_select 'form select option[value="3"]', 'Company 3'
87
-
88
- assert_raises MockExpectationError do
89
- value.verify
90
- end
91
- end
92
-
93
- # ASSOCIATIONS - BELONGS TO
94
- test 'builder creates a select for belongs_to associations' do
95
- with_association_for @user, :company
96
- assert_select 'form select.select#user_company_id'
97
- assert_select 'form select option[value="1"]', 'Company 1'
98
- assert_select 'form select option[value="2"]', 'Company 2'
99
- assert_select 'form select option[value="3"]', 'Company 3'
100
- end
101
-
102
- test 'builder creates blank select if collection is nil' do
103
- with_association_for @user, :company, collection: nil
104
- assert_select 'form select.select#user_company_id'
105
- assert_no_select 'form select option[value="1"]', 'Company 1'
106
- end
107
-
108
- test 'builder allows collection radio for belongs_to associations' do
109
- with_association_for @user, :company, as: :radio_buttons
110
- assert_select 'form input.radio_buttons#user_company_id_1'
111
- assert_select 'form input.radio_buttons#user_company_id_2'
112
- assert_select 'form input.radio_buttons#user_company_id_3'
113
- end
114
-
115
- test 'builder allows collection to have a proc as a condition' do
116
- with_association_for @user, :extra_special_company
117
- assert_select 'form select.select#user_extra_special_company_id'
118
- assert_select 'form select option[value="1"]'
119
- assert_no_select 'form select option[value="2"]'
120
- assert_no_select 'form select option[value="3"]'
121
- end
122
-
123
- test 'builder allows collection to have a scope' do
124
- with_association_for @user, :special_pictures
125
- assert_select 'form select.select#user_special_picture_ids'
126
- assert_select 'form select option[value="3"]', '3'
127
- assert_no_select 'form select option[value="1"]'
128
- assert_no_select 'form select option[value="2"]'
129
- end
130
-
131
- test 'builder allows collection to have a scope with parameter' do
132
- with_association_for @user, :special_tags
133
- assert_select 'form select.select#user_special_tag_ids'
134
- assert_select 'form select[multiple=multiple]'
135
- assert_select 'form select option[value="1"]', 'Tag 1'
136
- assert_no_select 'form select option[value="2"]'
137
- assert_no_select 'form select option[value="3"]'
138
- end
139
-
140
- test 'builder marks the record which already belongs to the user' do
141
- @user.company_id = 2
142
- with_association_for @user, :company, as: :radio_buttons
143
- assert_no_select 'form input.radio_buttons#user_company_id_1[checked=checked]'
144
- assert_select 'form input.radio_buttons#user_company_id_2[checked=checked]'
145
- assert_no_select 'form input.radio_buttons#user_company_id_3[checked=checked]'
146
- end
147
-
148
- # ASSOCIATIONS - FINDERS
149
- test 'builder uses reflection conditions to find collection' do
150
- with_association_for @user, :special_company
151
- assert_select 'form select.select#user_special_company_id'
152
- assert_select 'form select option[value="1"]'
153
- assert_no_select 'form select option[value="2"]'
154
- assert_no_select 'form select option[value="3"]'
155
- end
156
-
157
- test 'builder allows overriding collection to association input' do
158
- with_association_for @user, :company, include_blank: false,
159
- collection: [Company.new(999, 'Teste')]
160
- assert_select 'form select.select#user_company_id'
161
- assert_no_select 'form select option[value="1"]'
162
- assert_select 'form select option[value="999"]', 'Teste'
163
- assert_select 'form select option', count: 1
164
- end
165
-
166
- # ASSOCIATIONS - has_*
167
- test 'builder does not allow has_one associations' do
168
- assert_raise ArgumentError do
169
- with_association_for @user, :first_company, as: :radio_buttons
170
- end
171
- end
172
-
173
- test 'builder does not call where if the given association does not respond to it' do
174
- with_association_for @user, :friends
175
- assert_select 'form select.select#user_friend_ids'
176
- assert_select 'form select[multiple=multiple]'
177
- assert_select 'form select option[value="1"]', 'Friend 1'
178
- assert_select 'form select option[value="2"]', 'Friend 2'
179
- assert_select 'form select option[value="3"]', 'Friend 3'
180
- end
181
-
182
- test 'builder does not call order if the given association does not respond to it' do
183
- with_association_for @user, :pictures
184
- assert_select 'form select.select#user_picture_ids'
185
- assert_select 'form select[multiple=multiple]'
186
- assert_select 'form select option[value="1"]', 'Picture 1'
187
- assert_select 'form select option[value="2"]', 'Picture 2'
188
- assert_select 'form select option[value="3"]', 'Picture 3'
189
- end
190
-
191
- test 'builder creates a select with multiple options for collection associations' do
192
- with_association_for @user, :tags
193
- assert_select 'form select.select#user_tag_ids'
194
- assert_select 'form select[multiple=multiple]'
195
- assert_select 'form select option[value="1"]', 'Tag 1'
196
- assert_select 'form select option[value="2"]', 'Tag 2'
197
- assert_select 'form select option[value="3"]', 'Tag 3'
198
- end
199
-
200
- test 'builder allows size to be overwritten for collection associations' do
201
- with_association_for @user, :tags, input_html: { size: 10 }
202
- assert_select 'form select[multiple=multiple][size="10"]'
203
- end
204
-
205
- test 'builder marks all selected records which already belongs to user' do
206
- @user.tag_ids = [1, 2]
207
- with_association_for @user, :tags
208
- assert_select 'form select option[value="1"][selected=selected]'
209
- assert_select 'form select option[value="2"][selected=selected]'
210
- assert_no_select 'form select option[value="3"][selected=selected]'
211
- end
212
-
213
- test 'builder allows a collection of check boxes for collection associations' do
214
- @user.tag_ids = [1, 2]
215
- with_association_for @user, :tags, as: :check_boxes
216
- assert_select 'form input#user_tag_ids_1[type=checkbox]'
217
- assert_select 'form input#user_tag_ids_2[type=checkbox]'
218
- assert_select 'form input#user_tag_ids_3[type=checkbox]'
219
- end
220
-
221
- test 'builder marks all selected records for collection boxes' do
222
- @user.tag_ids = [1, 2]
223
- with_association_for @user, :tags, as: :check_boxes
224
- assert_select 'form input[type=checkbox][value="1"][checked=checked]'
225
- assert_select 'form input[type=checkbox][value="2"][checked=checked]'
226
- assert_no_select 'form input[type=checkbox][value="3"][checked=checked]'
227
- end
228
-
229
- test 'builder with collection support giving collection and item wrapper tags' do
230
- with_association_for @user, :tags, as: :check_boxes,
231
- collection_wrapper_tag: :ul, item_wrapper_tag: :li
232
-
233
- assert_select 'form ul', count: 1
234
- assert_select 'form ul li', count: 3
235
- end
236
-
237
- test 'builder with collection support does not change the options hash' do
238
- options = { as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li }
239
- with_association_for @user, :tags, options
240
-
241
- assert_select 'form ul', count: 1
242
- assert_select 'form ul li', count: 3
243
- assert_equal({ as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li },
244
- options)
245
- end
246
-
247
- test 'builder with group select considers multiple select by default' do
248
- with_association_for @user, :tags, as: :grouped_select, group_method: :group_method
249
-
250
- assert_select 'select[multiple="multiple"].grouped_select'
251
- end
252
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- class ButtonTest < ActionView::TestCase
6
- def with_button_for(object, *args)
7
- with_concat_form_for(object) do |f|
8
- f.button(*args)
9
- end
10
- end
11
-
12
- test 'builder creates buttons' do
13
- with_button_for :post, :submit
14
- assert_select 'form input.button[type=submit][value="Save Post"]'
15
- end
16
-
17
- test 'builder creates buttons with options' do
18
- with_button_for :post, :submit, class: 'my_button'
19
- assert_select 'form input.button.my_button[type=submit][value="Save Post"]'
20
- end
21
-
22
- test 'builder does not modify the options hash' do
23
- options = { class: 'my_button' }
24
- with_button_for :post, :submit, options
25
- assert_select 'form input.button.my_button[type=submit][value="Save Post"]'
26
- assert_equal({ class: 'my_button' }, options)
27
- end
28
-
29
- test 'builder creates buttons for records' do
30
- @user.new_record!
31
- with_button_for @user, :submit
32
- assert_select 'form input.button[type=submit][value="Create User"]'
33
- end
34
-
35
- test "builder uses the default class from the configuration" do
36
- swap SimpleForm, button_class: 'btn' do
37
- with_button_for :post, :submit
38
- assert_select 'form input.btn[type=submit][value="Save Post"]'
39
- end
40
- end
41
-
42
- if ActionView::Helpers::FormBuilder.method_defined?(:button)
43
- test "allows to use Rails button helper when available" do
44
- with_button_for :post, :button, 'Save!'
45
- assert_select 'form button.button[type=submit]', 'Save!'
46
- end
47
- end
48
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- # Tests for f.error_notification
6
- class ErrorNotificationTest < ActionView::TestCase
7
- def with_error_notification_for(object, options = {}, &block)
8
- with_concat_form_for(object) do |f|
9
- f.error_notification(options)
10
- end
11
- end
12
-
13
- test 'error notification is not generated when the object has no error' do
14
- assert @validating_user.valid?
15
-
16
- with_error_notification_for @validating_user
17
- assert_no_select 'p.error_notification'
18
- end
19
-
20
- test 'error notification is not generated for forms without objects' do
21
- with_error_notification_for :user
22
- assert_no_select 'p.error_notification'
23
- end
24
-
25
- test 'error notification is generated when the object has some error' do
26
- with_error_notification_for @user
27
- assert_select 'p.error_notification', 'Please review the problems below:'
28
- end
29
-
30
- test 'error notification uses I18n based on model to generate the notification message' do
31
- store_translations(:en, simple_form: { error_notification: { user:
32
- 'Alguns erros foram encontrados para o usuário:'
33
- } }) do
34
- with_error_notification_for @user
35
- assert_select 'p.error_notification', 'Alguns erros foram encontrados para o usuário:'
36
- end
37
- end
38
-
39
- test 'error notification uses I18n fallbacking to default message' do
40
- store_translations(:en, simple_form: { error_notification: {
41
- default_message: 'Opa! Alguns erros foram encontrados, poderia verificar?'
42
- } }) do
43
- with_error_notification_for @user
44
- assert_select 'p.error_notification', 'Opa! Alguns erros foram encontrados, poderia verificar?'
45
- end
46
- end
47
-
48
- test 'error notification allows passing the notification message' do
49
- with_error_notification_for @user, message: 'Erro encontrado ao criar usuario'
50
- assert_select 'p.error_notification', 'Erro encontrado ao criar usuario'
51
- end
52
-
53
- test 'error notification accepts other html options' do
54
- with_error_notification_for @user, id: 'user_error_message', class: 'form_error'
55
- assert_select 'p#user_error_message.form_error.error_notification'
56
- end
57
-
58
- test 'error notification allows configuring the wrapper element' do
59
- swap SimpleForm, error_notification_tag: :div do
60
- with_error_notification_for @user
61
- assert_select 'div.error_notification'
62
- end
63
- end
64
-
65
- test 'error notification can contain HTML tags' do
66
- with_error_notification_for @user, message: 'Erro encontrado ao criar <b>usuário</b>'
67
- assert_select 'p.error_notification', 'Erro encontrado ao criar usuário'
68
- assert_select 'p.error_notification b', 'usuário'
69
- end
70
-
71
- test 'error notification uses I18n based on model to generate the notification message and accepts HTML' do
72
- store_translations(:en, simple_form: { error_notification: { user:
73
- 'Alguns erros foram encontrados para o <b>usuário</b>:'
74
- } }) do
75
- with_error_notification_for @user
76
- assert_select 'p.error_notification', 'Alguns erros foram encontrados para o usuário:'
77
- assert_select 'p.error_notification b', 'usuário'
78
- end
79
- end
80
- end
@@ -1,281 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'test_helper'
3
-
4
- # Tests for f.error and f.full_error
5
- class ErrorTest < ActionView::TestCase
6
- def with_error_for(object, *args)
7
- with_concat_form_for(object) do |f|
8
- f.error(*args)
9
- end
10
- end
11
-
12
- def with_full_error_for(object, *args)
13
- with_concat_form_for(object) do |f|
14
- f.full_error(*args)
15
- end
16
- end
17
-
18
- test 'error does not generate content for attribute without errors' do
19
- with_error_for @user, :active
20
- assert_no_select 'span.error'
21
- end
22
-
23
- test 'error does not generate messages when object is not present' do
24
- with_error_for :project, :name
25
- assert_no_select 'span.error'
26
- end
27
-
28
- test "error does not generate messages when object doesn't respond to errors method" do
29
- @user.instance_eval { undef errors }
30
- with_error_for @user, :name
31
- assert_no_select 'span.error'
32
- end
33
-
34
- test 'error generates messages for attribute with single error' do
35
- with_error_for @user, :name
36
- assert_select 'span.error', "cannot be blank"
37
- end
38
-
39
- test 'error generates messages with decorated object responsive to #to_model' do
40
- with_error_for @decorated_user, :name
41
- assert_select 'span.error', "cannot be blank"
42
- end
43
-
44
- test 'error generates messages for attribute with one error when using first' do
45
- swap SimpleForm, error_method: :first do
46
- with_error_for @user, :age
47
- assert_select 'span.error', 'is not a number'
48
- end
49
- end
50
-
51
- test 'error generates messages for attribute with several errors when using to_sentence' do
52
- swap SimpleForm, error_method: :to_sentence do
53
- with_error_for @user, :age
54
- assert_select 'span.error', 'is not a number and must be greater than 18'
55
- end
56
- end
57
-
58
- test 'error is able to pass html options' do
59
- with_error_for @user, :name, id: 'error', class: 'yay'
60
- assert_select 'span#error.error.yay'
61
- end
62
-
63
- test 'error does not modify the options hash' do
64
- options = { id: 'error', class: 'yay' }
65
- with_error_for @user, :name, options
66
- assert_select 'span#error.error.yay'
67
- assert_equal({ id: 'error', class: 'yay' }, options)
68
- end
69
-
70
- test 'error finds errors on attribute and association' do
71
- with_error_for @user, :company_id, as: :select,
72
- error_method: :to_sentence, reflection: Association.new(Company, :company, {})
73
- assert_select 'span.error', 'must be valid and company must be present'
74
- end
75
-
76
- test 'error generates an error tag with a clean HTML' do
77
- with_error_for @user, :name
78
- assert_no_select 'span.error[error_html]'
79
- end
80
-
81
- test 'error generates an error tag with a clean HTML when errors options are present' do
82
- with_error_for @user, :name, error_tag: :p, error_prefix: 'Name', error_method: :first
83
- assert_no_select 'p.error[error_html]'
84
- assert_no_select 'p.error[error_tag]'
85
- assert_no_select 'p.error[error_prefix]'
86
- assert_no_select 'p.error[error_method]'
87
- end
88
-
89
- test 'error escapes error prefix text' do
90
- with_error_for @user, :name, error_prefix: '<b>Name</b>'
91
- assert_no_select 'span.error b'
92
- end
93
-
94
- test 'error escapes error text' do
95
- @user.errors.add(:action, 'must not contain <b>markup</b>')
96
-
97
- with_error_for @user, :action
98
-
99
- assert_select 'span.error'
100
- assert_no_select 'span.error b', 'markup'
101
- end
102
-
103
- test 'error generates an error message with raw HTML tags' do
104
- with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
105
- assert_select 'span.error', "Name cannot be blank"
106
- assert_select 'span.error b', "Name"
107
- end
108
-
109
- test 'error adds aria-invalid attribute to inputs' do
110
- with_form_for @user, :name, error: true
111
- assert_select "input#user_name[name='user[name]'][aria-invalid='true']"
112
-
113
- with_form_for @user, :name, as: :text, error: true
114
- assert_select "textarea#user_name[name='user[name]'][aria-invalid='true']"
115
-
116
- @user.errors.add(:active, 'must select one')
117
- with_form_for @user, :active, as: :radio_buttons
118
- assert_select "input#user_active_true[type=radio][name='user[active]'][aria-invalid='true']"
119
- assert_select "input#user_active_false[type=radio][name='user[active]'][aria-invalid='true']"
120
-
121
- with_form_for @user, :active, as: :check_boxes
122
- assert_select "input#user_active_true[type=checkbox][aria-invalid='true']"
123
- assert_select "input#user_active_false[type=checkbox][aria-invalid='true']"
124
-
125
- with_form_for @user, :company_id, as: :select, error: true
126
- assert_select "select#user_company_id[aria-invalid='true']"
127
-
128
- @user.errors.add(:password, 'must not be blank')
129
- with_form_for @user, :password
130
- assert_select "input#user_password[type=password][aria-invalid='true']"
131
- end
132
-
133
- # FULL ERRORS
134
-
135
- test 'full error generates a full error tag for the attribute' do
136
- with_full_error_for @user, :name
137
- assert_select 'span.error', "Super User Name! cannot be blank"
138
- end
139
-
140
- test 'full error generates a full error tag with a clean HTML' do
141
- with_full_error_for @user, :name
142
- assert_no_select 'span.error[error_html]'
143
- end
144
-
145
- test 'full error allows passing options to full error tag' do
146
- with_full_error_for @user, :name, id: 'name_error', error_prefix: "Your name"
147
- assert_select 'span.error#name_error', "Your name cannot be blank"
148
- end
149
-
150
- test 'full error does not modify the options hash' do
151
- options = { id: 'name_error' }
152
- with_full_error_for @user, :name, options
153
- assert_select 'span.error#name_error', "Super User Name! cannot be blank"
154
- assert_equal({ id: 'name_error' }, options)
155
- end
156
-
157
- test 'full error escapes error text' do
158
- @user.errors.add(:action, 'must not contain <b>markup</b>')
159
-
160
- with_full_error_for @user, :action
161
-
162
- assert_select 'span.error'
163
- assert_no_select 'span.error b', 'markup'
164
- end
165
-
166
- # CUSTOM WRAPPERS
167
-
168
- test 'error with custom wrappers works' do
169
- swap_wrapper do
170
- with_error_for @user, :name
171
- assert_select 'span.omg_error', "cannot be blank"
172
- end
173
- end
174
-
175
- # FULL_ERROR_WRAPPER
176
-
177
- test 'full error finds errors on association' do
178
- swap_wrapper :default, custom_wrapper_with_full_error do
179
- with_form_for @user, :company_id, as: :select
180
- assert_select 'span.error', 'Company must be valid'
181
- end
182
- end
183
-
184
- test 'full error finds errors on association with reflection' do
185
- swap_wrapper :default, custom_wrapper_with_full_error do
186
- with_form_for @user, :company_id, as: :select,
187
- reflection: Association.new(Company, :company, {})
188
- assert_select 'span.error', 'Company must be valid'
189
- end
190
- end
191
-
192
- test 'full error can be disabled' do
193
- swap_wrapper :default, custom_wrapper_with_full_error do
194
- with_form_for @user, :company_id, as: :select, full_error: false
195
- assert_no_select 'span.error'
196
- end
197
- end
198
-
199
- test 'full error can be disabled setting error to false' do
200
- swap_wrapper :default, custom_wrapper_with_full_error do
201
- with_form_for @user, :company_id, as: :select, error: false
202
- assert_no_select 'span.error'
203
- end
204
- end
205
-
206
- # CUSTOM ERRORS
207
-
208
- test 'input with custom error works' do
209
- error_text = "Super User Name! cannot be blank"
210
- with_form_for @user, :name, error: error_text
211
-
212
- assert_select 'span.error', error_text
213
- end
214
-
215
- test 'input with error option as true does not use custom error' do
216
- with_form_for @user, :name, error: true
217
-
218
- assert_select 'span.error', "cannot be blank"
219
- end
220
-
221
- test 'input with custom error does not generate the error if there is no error on the attribute' do
222
- with_form_for @user, :active, error: "Super User Active! cannot be blank"
223
-
224
- assert_no_select 'span.error'
225
- end
226
-
227
- test 'input with custom error works when form does not use a model' do
228
- with_form_for :user, :active, error: "Super User Active! cannot be blank"
229
-
230
- assert_select 'span.error'
231
- end
232
-
233
- test 'input with custom error works when using full_error component' do
234
- swap_wrapper :default, custom_wrapper_with_full_error do
235
- error_text = "Super User Name! cannot be blank"
236
- with_form_for @user, :name, error: error_text
237
-
238
- assert_select 'span.error', error_text
239
- end
240
- end
241
-
242
- test 'input with custom error escapes the error text' do
243
- with_form_for @user, :name, error: 'error must not contain <b>markup</b>'
244
-
245
- assert_select 'span.error'
246
- assert_no_select 'span.error b', 'markup'
247
- end
248
-
249
- test 'input with custom error does not escape the error text if it is safe' do
250
- with_form_for @user, :name, error: 'error must contain <b>markup</b>'.html_safe
251
-
252
- assert_select 'span.error'
253
- assert_select 'span.error b', 'markup'
254
- end
255
-
256
- test 'input with custom error escapes the error text using full_error component' do
257
- swap_wrapper :default, custom_wrapper_with_full_error do
258
- with_form_for @user, :name, error: 'error must not contain <b>markup</b>'
259
-
260
- assert_select 'span.error'
261
- assert_no_select 'span.error b', 'markup'
262
- end
263
- end
264
-
265
- test 'input with custom error does not escape the error text if it is safe using full_error component' do
266
- swap_wrapper :default, custom_wrapper_with_full_error do
267
- with_form_for @user, :name, error: 'error must contain <b>markup</b>'.html_safe
268
-
269
- assert_select 'span.error'
270
- assert_select 'span.error b', 'markup'
271
- end
272
- end
273
-
274
- test 'input with custom error when using full_error component does not generate the error if there is no error on the attribute' do
275
- swap_wrapper :default, custom_wrapper_with_full_error do
276
- with_form_for @user, :active, error: "Super User Active! can't be blank"
277
-
278
- assert_no_select 'span.error'
279
- end
280
- end
281
- end