simple_form 3.0.3 → 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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -39
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +204 -81
  5. data/lib/generators/simple_form/install_generator.rb +3 -3
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +28 -7
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +115 -24
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +86 -5
  10. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
  11. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  12. data/lib/simple_form/action_view_extensions/form_helper.rb +6 -2
  13. data/lib/simple_form/components/errors.rb +24 -4
  14. data/lib/simple_form/components/hints.rb +2 -2
  15. data/lib/simple_form/components/html5.rb +1 -1
  16. data/lib/simple_form/components/label_input.rb +20 -2
  17. data/lib/simple_form/components/labels.rb +10 -6
  18. data/lib/simple_form/components/maxlength.rb +1 -1
  19. data/lib/simple_form/components/min_max.rb +1 -1
  20. data/lib/simple_form/components/pattern.rb +1 -1
  21. data/lib/simple_form/components/placeholders.rb +2 -2
  22. data/lib/simple_form/components/readonly.rb +1 -1
  23. data/lib/simple_form/form_builder.rb +123 -73
  24. data/lib/simple_form/helpers.rb +5 -5
  25. data/lib/simple_form/inputs/base.rb +34 -12
  26. data/lib/simple_form/inputs/block_input.rb +1 -1
  27. data/lib/simple_form/inputs/boolean_input.rb +28 -15
  28. data/lib/simple_form/inputs/collection_input.rb +30 -9
  29. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
  30. data/lib/simple_form/inputs/collection_select_input.rb +4 -2
  31. data/lib/simple_form/inputs/date_time_input.rb +12 -2
  32. data/lib/simple_form/inputs/file_input.rb +4 -2
  33. data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
  34. data/lib/simple_form/inputs/hidden_input.rb +4 -2
  35. data/lib/simple_form/inputs/numeric_input.rb +5 -4
  36. data/lib/simple_form/inputs/password_input.rb +4 -2
  37. data/lib/simple_form/inputs/priority_input.rb +4 -2
  38. data/lib/simple_form/inputs/range_input.rb +1 -1
  39. data/lib/simple_form/inputs/string_input.rb +4 -2
  40. data/lib/simple_form/inputs/text_input.rb +4 -2
  41. data/lib/simple_form/railtie.rb +7 -0
  42. data/lib/simple_form/tags.rb +6 -0
  43. data/lib/simple_form/version.rb +1 -1
  44. data/lib/simple_form/wrappers/builder.rb +6 -6
  45. data/lib/simple_form/wrappers/leaf.rb +28 -0
  46. data/lib/simple_form/wrappers/many.rb +6 -6
  47. data/lib/simple_form/wrappers/root.rb +1 -1
  48. data/lib/simple_form/wrappers/single.rb +5 -3
  49. data/lib/simple_form/wrappers.rb +1 -0
  50. data/lib/simple_form.rb +59 -8
  51. data/test/action_view_extensions/builder_test.rb +36 -36
  52. data/test/action_view_extensions/form_helper_test.rb +33 -14
  53. data/test/components/label_test.rb +37 -37
  54. data/test/form_builder/association_test.rb +52 -35
  55. data/test/form_builder/button_test.rb +10 -10
  56. data/test/form_builder/error_notification_test.rb +1 -1
  57. data/test/form_builder/error_test.rb +111 -33
  58. data/test/form_builder/general_test.rb +89 -64
  59. data/test/form_builder/hint_test.rb +18 -18
  60. data/test/form_builder/input_field_test.rb +80 -16
  61. data/test/form_builder/label_test.rb +45 -13
  62. data/test/form_builder/wrapper_test.rb +135 -19
  63. data/test/generators/simple_form_generator_test.rb +4 -4
  64. data/test/inputs/boolean_input_test.rb +62 -6
  65. data/test/inputs/collection_check_boxes_input_test.rb +85 -17
  66. data/test/inputs/collection_radio_buttons_input_test.rb +134 -36
  67. data/test/inputs/collection_select_input_test.rb +146 -41
  68. data/test/inputs/datetime_input_test.rb +117 -50
  69. data/test/inputs/disabled_test.rb +15 -15
  70. data/test/inputs/discovery_test.rb +56 -6
  71. data/test/inputs/file_input_test.rb +2 -2
  72. data/test/inputs/general_test.rb +20 -20
  73. data/test/inputs/grouped_collection_select_input_test.rb +44 -8
  74. data/test/inputs/hidden_input_test.rb +4 -4
  75. data/test/inputs/numeric_input_test.rb +43 -43
  76. data/test/inputs/priority_input_test.rb +13 -13
  77. data/test/inputs/readonly_test.rb +19 -19
  78. data/test/inputs/required_test.rb +13 -13
  79. data/test/inputs/string_input_test.rb +50 -30
  80. data/test/inputs/text_input_test.rb +7 -7
  81. data/test/simple_form_test.rb +8 -0
  82. data/test/support/discovery_inputs.rb +32 -2
  83. data/test/support/misc_helpers.rb +77 -5
  84. data/test/support/models.rb +60 -24
  85. data/test/test_helper.rb +5 -1
  86. metadata +3 -2
@@ -8,7 +8,7 @@ class AssociationTest < ActionView::TestCase
8
8
  end
9
9
  end
10
10
 
11
- test 'builder should not allow creating an association input when no object exists' do
11
+ test 'builder does not allow creating an association input when no object exists' do
12
12
  assert_raise ArgumentError do
13
13
  with_association_for :post, :author
14
14
  end
@@ -46,9 +46,9 @@ class AssociationTest < ActionView::TestCase
46
46
 
47
47
  with_association_for @user, :tags
48
48
  assert_select 'form select.select#user_tag_ids'
49
- assert_select 'form select option[value=1]', 'Tag 1'
50
- assert_select 'form select option[value=2]', 'Tag 2'
51
- assert_select 'form select option[value=3]', 'Tag 3'
49
+ assert_select 'form select option[value="1"]', 'Tag 1'
50
+ assert_select 'form select option[value="2"]', 'Tag 2'
51
+ assert_select 'form select option[value="3"]', 'Tag 3'
52
52
 
53
53
  value.verify
54
54
  end
@@ -59,9 +59,9 @@ class AssociationTest < ActionView::TestCase
59
59
 
60
60
  with_association_for @user, :tags, preload: false
61
61
  assert_select 'form select.select#user_tag_ids'
62
- assert_select 'form select option[value=1]', 'Tag 1'
63
- assert_select 'form select option[value=2]', 'Tag 2'
64
- assert_select 'form select option[value=3]', 'Tag 3'
62
+ assert_select 'form select option[value="1"]', 'Tag 1'
63
+ assert_select 'form select option[value="2"]', 'Tag 2'
64
+ assert_select 'form select option[value="3"]', 'Tag 3'
65
65
 
66
66
  assert_raises MockExpectationError do
67
67
  value.verify
@@ -74,9 +74,9 @@ class AssociationTest < ActionView::TestCase
74
74
 
75
75
  with_association_for @user, :company
76
76
  assert_select 'form select.select#user_company_id'
77
- assert_select 'form select option[value=1]', 'Company 1'
78
- assert_select 'form select option[value=2]', 'Company 2'
79
- assert_select 'form select option[value=3]', 'Company 3'
77
+ assert_select 'form select option[value="1"]', 'Company 1'
78
+ assert_select 'form select option[value="2"]', 'Company 2'
79
+ assert_select 'form select option[value="3"]', 'Company 3'
80
80
 
81
81
  assert_raises MockExpectationError do
82
82
  value.verify
@@ -87,15 +87,15 @@ class AssociationTest < ActionView::TestCase
87
87
  test 'builder creates a select for belongs_to associations' do
88
88
  with_association_for @user, :company
89
89
  assert_select 'form select.select#user_company_id'
90
- assert_select 'form select option[value=1]', 'Company 1'
91
- assert_select 'form select option[value=2]', 'Company 2'
92
- assert_select 'form select option[value=3]', 'Company 3'
90
+ assert_select 'form select option[value="1"]', 'Company 1'
91
+ assert_select 'form select option[value="2"]', 'Company 2'
92
+ assert_select 'form select option[value="3"]', 'Company 3'
93
93
  end
94
94
 
95
95
  test 'builder creates blank select if collection is nil' do
96
96
  with_association_for @user, :company, collection: nil
97
97
  assert_select 'form select.select#user_company_id'
98
- assert_no_select 'form select option[value=1]', 'Company 1'
98
+ assert_no_select 'form select option[value="1"]', 'Company 1'
99
99
  end
100
100
 
101
101
  test 'builder allows collection radio for belongs_to associations' do
@@ -108,9 +108,17 @@ class AssociationTest < ActionView::TestCase
108
108
  test 'builder allows collection to have a proc as a condition' do
109
109
  with_association_for @user, :extra_special_company
110
110
  assert_select 'form select.select#user_extra_special_company_id'
111
- assert_select 'form select option[value=1]'
112
- assert_no_select 'form select option[value=2]'
113
- assert_no_select 'form select option[value=3]'
111
+ assert_select 'form select option[value="1"]'
112
+ assert_no_select 'form select option[value="2"]'
113
+ assert_no_select 'form select option[value="3"]'
114
+ end
115
+
116
+ test 'builder allows collection to have a scope' do
117
+ with_association_for @user, :special_pictures
118
+ assert_select 'form select.select#user_special_picture_ids'
119
+ assert_select 'form select option[value="3"]', '3'
120
+ assert_no_select 'form select option[value="1"]'
121
+ assert_no_select 'form select option[value="2"]'
114
122
  end
115
123
 
116
124
  test 'builder marks the record which already belongs to the user' do
@@ -122,20 +130,20 @@ class AssociationTest < ActionView::TestCase
122
130
  end
123
131
 
124
132
  # ASSOCIATIONS - FINDERS
125
- test 'builder should use reflection conditions to find collection' do
133
+ test 'builder uses reflection conditions to find collection' do
126
134
  with_association_for @user, :special_company
127
135
  assert_select 'form select.select#user_special_company_id'
128
- assert_select 'form select option[value=1]'
129
- assert_no_select 'form select option[value=2]'
130
- assert_no_select 'form select option[value=3]'
136
+ assert_select 'form select option[value="1"]'
137
+ assert_no_select 'form select option[value="2"]'
138
+ assert_no_select 'form select option[value="3"]'
131
139
  end
132
140
 
133
- test 'builder should allow overriding collection to association input' do
141
+ test 'builder allows overriding collection to association input' do
134
142
  with_association_for @user, :company, include_blank: false,
135
143
  collection: [Company.new(999, 'Teste')]
136
144
  assert_select 'form select.select#user_company_id'
137
- assert_no_select 'form select option[value=1]'
138
- assert_select 'form select option[value=999]', 'Teste'
145
+ assert_no_select 'form select option[value="1"]'
146
+ assert_select 'form select option[value="999"]', 'Teste'
139
147
  assert_select 'form select option', count: 1
140
148
  end
141
149
 
@@ -146,26 +154,35 @@ class AssociationTest < ActionView::TestCase
146
154
  end
147
155
  end
148
156
 
157
+ test 'builder does not call order if the given association does not respond to it' do
158
+ with_association_for @user, :pictures
159
+ assert_select 'form select.select#user_picture_ids'
160
+ assert_select 'form select[multiple=multiple]'
161
+ assert_select 'form select option[value="1"]', 'Picture 1'
162
+ assert_select 'form select option[value="2"]', 'Picture 2'
163
+ assert_select 'form select option[value="3"]', 'Picture 3'
164
+ end
165
+
149
166
  test 'builder creates a select with multiple options for collection associations' do
150
167
  with_association_for @user, :tags
151
168
  assert_select 'form select.select#user_tag_ids'
152
169
  assert_select 'form select[multiple=multiple]'
153
- assert_select 'form select option[value=1]', 'Tag 1'
154
- assert_select 'form select option[value=2]', 'Tag 2'
155
- assert_select 'form select option[value=3]', 'Tag 3'
170
+ assert_select 'form select option[value="1"]', 'Tag 1'
171
+ assert_select 'form select option[value="2"]', 'Tag 2'
172
+ assert_select 'form select option[value="3"]', 'Tag 3'
156
173
  end
157
174
 
158
175
  test 'builder allows size to be overwritten for collection associations' do
159
176
  with_association_for @user, :tags, input_html: { size: 10 }
160
- assert_select 'form select[multiple=multiple][size=10]'
177
+ assert_select 'form select[multiple=multiple][size="10"]'
161
178
  end
162
179
 
163
180
  test 'builder marks all selected records which already belongs to user' do
164
181
  @user.tag_ids = [1, 2]
165
182
  with_association_for @user, :tags
166
- assert_select 'form select option[value=1][selected=selected]'
167
- assert_select 'form select option[value=2][selected=selected]'
168
- assert_no_select 'form select option[value=3][selected=selected]'
183
+ assert_select 'form select option[value="1"][selected=selected]'
184
+ assert_select 'form select option[value="2"][selected=selected]'
185
+ assert_no_select 'form select option[value="3"][selected=selected]'
169
186
  end
170
187
 
171
188
  test 'builder allows a collection of check boxes for collection associations' do
@@ -179,9 +196,9 @@ class AssociationTest < ActionView::TestCase
179
196
  test 'builder marks all selected records for collection boxes' do
180
197
  @user.tag_ids = [1, 2]
181
198
  with_association_for @user, :tags, as: :check_boxes
182
- assert_select 'form input[type=checkbox][value=1][checked=checked]'
183
- assert_select 'form input[type=checkbox][value=2][checked=checked]'
184
- assert_no_select 'form input[type=checkbox][value=3][checked=checked]'
199
+ assert_select 'form input[type=checkbox][value="1"][checked=checked]'
200
+ assert_select 'form input[type=checkbox][value="2"][checked=checked]'
201
+ assert_no_select 'form input[type=checkbox][value="3"][checked=checked]'
185
202
  end
186
203
 
187
204
  test 'builder with collection support giving collection and item wrapper tags' do
@@ -192,7 +209,7 @@ class AssociationTest < ActionView::TestCase
192
209
  assert_select 'form ul li', count: 3
193
210
  end
194
211
 
195
- test 'builder with collection support should not change the options hash' do
212
+ test 'builder with collection support does not change the options hash' do
196
213
  options = { as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li}
197
214
  with_association_for @user, :tags, options
198
215
 
@@ -8,33 +8,33 @@ class ButtonTest < ActionView::TestCase
8
8
  end
9
9
  end
10
10
 
11
- test 'builder should create buttons' do
11
+ test 'builder creates buttons' do
12
12
  with_button_for :post, :submit
13
- assert_select 'form input.button[type=submit][value=Save Post]'
13
+ assert_select 'form input.button[type=submit][value="Save Post"]'
14
14
  end
15
15
 
16
- test 'builder should create buttons with options' do
16
+ test 'builder creates buttons with options' do
17
17
  with_button_for :post, :submit, class: 'my_button'
18
- assert_select 'form input.button.my_button[type=submit][value=Save Post]'
18
+ assert_select 'form input.button.my_button[type=submit][value="Save Post"]'
19
19
  end
20
20
 
21
- test 'builder should not modify the options hash' do
21
+ test 'builder does not modify the options hash' do
22
22
  options = { class: 'my_button' }
23
23
  with_button_for :post, :submit, options
24
- assert_select 'form input.button.my_button[type=submit][value=Save Post]'
24
+ assert_select 'form input.button.my_button[type=submit][value="Save Post"]'
25
25
  assert_equal({ class: 'my_button' }, options)
26
26
  end
27
27
 
28
- test 'builder should create buttons for records' do
28
+ test 'builder creates buttons for records' do
29
29
  @user.new_record!
30
30
  with_button_for @user, :submit
31
- assert_select 'form input.button[type=submit][value=Create User]'
31
+ assert_select 'form input.button[type=submit][value="Create User"]'
32
32
  end
33
33
 
34
- test "builder should use the default class from the configuration" do
34
+ test "builder uses the default class from the configuration" do
35
35
  swap SimpleForm, button_class: 'btn' do
36
36
  with_button_for :post, :submit
37
- assert_select 'form input.btn[type=submit][value=Save Post]'
37
+ assert_select 'form input.btn[type=submit][value="Save Post"]'
38
38
  end
39
39
  end
40
40
 
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
 
4
4
  # Tests for f.error_notification
5
5
  class ErrorNotificationTest < ActionView::TestCase
6
- def with_error_notification_for(object, options={}, &block)
6
+ def with_error_notification_for(object, options = {}, &block)
7
7
  with_concat_form_for(object) do |f|
8
8
  f.error_notification(options)
9
9
  end
@@ -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', "cannot 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,13 +80,13 @@ 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"
85
+ assert_no_select 'span.error b'
90
86
  end
91
87
 
92
88
  test 'error escapes error text' do
93
- @user.errors.merge!(action: ['must not contain <b>markup</b>'])
89
+ @user.errors.add(:action, 'must not contain <b>markup</b>')
94
90
 
95
91
  with_error_for @user, :action
96
92
 
@@ -98,60 +94,116 @@ class ErrorTest < ActionView::TestCase
98
94
  assert_no_select 'span.error b', 'markup'
99
95
  end
100
96
 
101
- test 'error should generate an error message with raw HTML tags' do
97
+
98
+ test 'error generates an error message with raw HTML tags' do
102
99
  with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
103
- assert_select 'span.error', "Name can&#39;t be blank"
100
+ assert_select 'span.error', "Name cannot be blank"
104
101
  assert_select 'span.error b', "Name"
105
102
  end
106
103
 
107
104
  # FULL ERRORS
108
105
 
109
- 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
110
107
  with_full_error_for @user, :name
111
- assert_select 'span.error', "Super User Name! can&#39;t be blank"
108
+ assert_select 'span.error', "Super User Name! cannot be blank"
112
109
  end
113
110
 
114
- 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
115
112
  with_full_error_for @user, :name
116
113
  assert_no_select 'span.error[error_html]'
117
114
  end
118
115
 
119
- test 'full error should allow passing options to full error tag' do
116
+ test 'full error allows passing options to full error tag' do
120
117
  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"
118
+ assert_select 'span.error#name_error', "Your name cannot be blank"
122
119
  end
123
120
 
124
- test 'full error should not modify the options hash' do
121
+ test 'full error does not modify the options hash' do
125
122
  options = { id: 'name_error' }
126
123
  with_full_error_for @user, :name, options
127
- assert_select 'span.error#name_error', "Super User Name! can&#39;t be blank"
124
+ assert_select 'span.error#name_error', "Super User Name! cannot be blank"
128
125
  assert_equal({ id: 'name_error' }, options)
129
126
  end
130
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
+
131
137
  # CUSTOM WRAPPERS
132
138
 
133
139
  test 'error with custom wrappers works' do
134
140
  swap_wrapper do
135
141
  with_error_for @user, :name
136
- assert_select 'span.omg_error', "can&#39;t be blank"
142
+ assert_select 'span.omg_error', "cannot be blank"
143
+ end
144
+ end
145
+
146
+ # FULL_ERROR_WRAPPER
147
+
148
+ test 'full error finds errors on association' do
149
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
150
+ with_form_for @user, :company_id, as: :select
151
+ assert_select 'span.error', 'Company must be valid'
152
+ end
153
+ end
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
+
163
+ test 'full error can be disabled' do
164
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
165
+ with_form_for @user, :company_id, as: :select, full_error: false
166
+ assert_no_select 'span.error'
167
+ end
168
+ end
169
+
170
+ test 'full error can be disabled setting error to false' do
171
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
172
+ with_form_for @user, :company_id, as: :select, error: false
173
+ assert_no_select 'span.error'
137
174
  end
138
175
  end
139
176
 
140
177
  # CUSTOM ERRORS
141
178
 
142
179
  test 'input with custom error works' do
143
- with_custom_error_for(@user, :name, error: "Super User Name! can't be blank")
180
+ error_text = "Super User Name! cannot be blank"
181
+ with_form_for @user, :name, error: error_text
144
182
 
145
- assert_select 'span.error', "Super User Name! can&#39;t be blank"
183
+ assert_select 'span.error', error_text
184
+ end
185
+
186
+ test 'input with error option as true does not use custom error' do
187
+ with_form_for @user, :name, error: true
188
+
189
+ assert_select 'span.error', "cannot be blank"
146
190
  end
147
191
 
148
192
  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
193
+ with_form_for @user, :active, error: "Super User Active! cannot be blank"
151
194
 
152
195
  assert_no_select 'span.error'
153
196
  end
154
197
 
198
+ test 'input with custom error works when using full_error component' do
199
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
200
+ error_text = "Super User Name! cannot be blank"
201
+ with_form_for @user, :name, error: error_text
202
+
203
+ assert_select 'span.error', error_text
204
+ end
205
+ end
206
+
155
207
  test 'input with custom error escapes the error text' do
156
208
  with_form_for @user, :name, error: 'error must not contain <b>markup</b>'
157
209
 
@@ -165,4 +217,30 @@ class ErrorTest < ActionView::TestCase
165
217
  assert_select 'span.error'
166
218
  assert_select 'span.error b', 'markup'
167
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
+
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
240
+ swap_wrapper :default, self.custom_wrapper_with_full_error do
241
+ with_form_for @user, :active, error: "Super User Active! can't be blank"
242
+
243
+ assert_no_select 'span.error'
244
+ end
245
+ end
168
246
  end