simple_form 2.0.0 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +97 -198
- data/MIT-LICENSE +1 -1
- data/README.md +572 -296
- data/lib/generators/simple_form/install_generator.rb +17 -7
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/_form.html.erb +1 -0
- data/lib/generators/simple_form/templates/_form.html.haml +1 -0
- data/lib/generators/simple_form/templates/config/initializers/{simple_form.rb.tt → simple_form.rb} +57 -63
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +155 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +111 -0
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +14 -7
- data/lib/simple_form/action_view_extensions/builder.rb +5 -305
- data/lib/simple_form/action_view_extensions/form_helper.rb +18 -20
- data/lib/simple_form/components/errors.rb +30 -3
- data/lib/simple_form/components/hints.rb +10 -3
- data/lib/simple_form/components/html5.rb +17 -3
- data/lib/simple_form/components/label_input.rb +21 -2
- data/lib/simple_form/components/labels.rb +16 -11
- data/lib/simple_form/components/maxlength.rb +19 -12
- data/lib/simple_form/components/min_max.rb +4 -2
- data/lib/simple_form/components/minlength.rb +48 -0
- data/lib/simple_form/components/pattern.rb +5 -4
- data/lib/simple_form/components/placeholders.rb +3 -2
- data/lib/simple_form/components/readonly.rb +3 -2
- data/lib/simple_form/components.rb +15 -11
- data/lib/simple_form/error_notification.rb +4 -3
- data/lib/simple_form/form_builder.rb +283 -105
- data/lib/simple_form/helpers/autofocus.rb +1 -0
- data/lib/simple_form/helpers/disabled.rb +1 -0
- data/lib/simple_form/helpers/readonly.rb +1 -0
- data/lib/simple_form/helpers/required.rb +1 -0
- data/lib/simple_form/helpers/validators.rb +4 -3
- data/lib/simple_form/helpers.rb +7 -6
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +76 -23
- data/lib/simple_form/inputs/block_input.rb +3 -2
- data/lib/simple_form/inputs/boolean_input.rb +55 -16
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +41 -18
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +11 -19
- data/lib/simple_form/inputs/collection_select_input.rb +5 -2
- data/lib/simple_form/inputs/date_time_input.rb +23 -12
- data/lib/simple_form/inputs/file_input.rb +5 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
- data/lib/simple_form/inputs/hidden_input.rb +5 -2
- data/lib/simple_form/inputs/numeric_input.rb +4 -8
- data/lib/simple_form/inputs/password_input.rb +6 -4
- data/lib/simple_form/inputs/priority_input.rb +5 -2
- data/lib/simple_form/inputs/range_input.rb +2 -1
- data/lib/simple_form/inputs/string_input.rb +6 -4
- data/lib/simple_form/inputs/text_input.rb +6 -3
- data/lib/simple_form/inputs.rb +20 -17
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +15 -0
- data/lib/simple_form/tags.rb +69 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +12 -35
- data/lib/simple_form/wrappers/leaf.rb +29 -0
- data/lib/simple_form/wrappers/many.rb +12 -7
- data/lib/simple_form/wrappers/root.rb +7 -4
- data/lib/simple_form/wrappers/single.rb +12 -3
- data/lib/simple_form/wrappers.rb +3 -1
- data/lib/simple_form.rb +118 -63
- data/test/action_view_extensions/builder_test.rb +230 -164
- data/test/action_view_extensions/form_helper_test.rb +107 -39
- data/test/components/label_test.rb +105 -87
- data/test/form_builder/association_test.rb +131 -62
- data/test/form_builder/button_test.rb +15 -14
- data/test/form_builder/error_notification_test.rb +11 -10
- data/test/form_builder/error_test.rb +188 -34
- data/test/form_builder/general_test.rb +247 -102
- data/test/form_builder/hint_test.rb +59 -32
- data/test/form_builder/input_field_test.rb +138 -25
- data/test/form_builder/label_test.rb +84 -13
- data/test/form_builder/wrapper_test.rb +236 -33
- data/test/generators/simple_form_generator_test.rb +15 -4
- data/test/inputs/boolean_input_test.rb +147 -13
- data/test/inputs/collection_check_boxes_input_test.rb +166 -71
- data/test/inputs/collection_radio_buttons_input_test.rb +229 -113
- data/test/inputs/collection_select_input_test.rb +222 -85
- data/test/inputs/datetime_input_test.rb +134 -47
- data/test/inputs/disabled_test.rb +62 -21
- data/test/inputs/discovery_test.rb +70 -10
- data/test/inputs/file_input_test.rb +4 -3
- data/test/inputs/general_test.rb +90 -26
- data/test/inputs/grouped_collection_select_input_test.rb +88 -23
- data/test/inputs/hidden_input_test.rb +7 -5
- data/test/inputs/numeric_input_test.rb +56 -46
- data/test/inputs/priority_input_test.rb +31 -16
- data/test/inputs/readonly_test.rb +68 -27
- data/test/inputs/required_test.rb +63 -18
- data/test/inputs/string_input_test.rb +76 -51
- data/test/inputs/text_input_test.rb +21 -8
- data/test/simple_form_test.rb +9 -0
- data/test/support/discovery_inputs.rb +39 -2
- data/test/support/misc_helpers.rb +176 -20
- data/test/support/mock_controller.rb +13 -7
- data/test/support/models.rb +187 -71
- data/test/test_helper.rb +38 -39
- metadata +53 -39
- data/lib/simple_form/core_ext/hash.rb +0 -16
- data/test/support/mock_response.rb +0 -14
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
require 'test_helper'
|
|
3
4
|
|
|
@@ -8,12 +9,18 @@ class AssociationTest < ActionView::TestCase
|
|
|
8
9
|
end
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
test 'builder
|
|
12
|
+
test 'builder does not allow creating an association input when no object exists' do
|
|
12
13
|
assert_raise ArgumentError do
|
|
13
14
|
with_association_for :post, :author
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
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
|
+
|
|
17
24
|
test 'builder association with a block calls simple_fields_for' do
|
|
18
25
|
simple_form_for @user do |f|
|
|
19
26
|
f.association :posts do |posts_form|
|
|
@@ -25,7 +32,7 @@ class AssociationTest < ActionView::TestCase
|
|
|
25
32
|
test 'builder association forwards collection to simple_fields_for' do
|
|
26
33
|
calls = 0
|
|
27
34
|
simple_form_for @user do |f|
|
|
28
|
-
f.association :company, :
|
|
35
|
+
f.association :company, collection: Company.all do |c|
|
|
29
36
|
calls += 1
|
|
30
37
|
end
|
|
31
38
|
end
|
|
@@ -34,116 +41,178 @@ class AssociationTest < ActionView::TestCase
|
|
|
34
41
|
end
|
|
35
42
|
|
|
36
43
|
test 'builder association marks input as required based on both association and attribute' do
|
|
37
|
-
swap SimpleForm, :
|
|
38
|
-
with_association_for @validating_user, :company, :
|
|
44
|
+
swap SimpleForm, required_by_default: false do
|
|
45
|
+
with_association_for @validating_user, :company, collection: []
|
|
39
46
|
assert_select 'label.required'
|
|
40
47
|
end
|
|
41
48
|
end
|
|
42
49
|
|
|
43
50
|
test 'builder preloads collection association' do
|
|
44
|
-
value = @user.tags
|
|
45
|
-
value.
|
|
51
|
+
value = @user.tags = MiniTest::Mock.new
|
|
52
|
+
value.expect(:to_a, value)
|
|
53
|
+
|
|
46
54
|
with_association_for @user, :tags
|
|
47
55
|
assert_select 'form select.select#user_tag_ids'
|
|
48
|
-
assert_select 'form select option[value=1]', 'Tag 1'
|
|
49
|
-
assert_select 'form select option[value=2]', 'Tag 2'
|
|
50
|
-
assert_select 'form select option[value=3]', 'Tag 3'
|
|
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
|
|
51
61
|
end
|
|
52
62
|
|
|
53
63
|
test 'builder does not preload collection association if preload is false' do
|
|
54
|
-
value = @user.
|
|
55
|
-
value.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
assert_select 'form select
|
|
59
|
-
assert_select 'form select option[value=
|
|
60
|
-
assert_select 'form select option[value=
|
|
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
|
|
61
76
|
end
|
|
62
77
|
|
|
63
78
|
test 'builder does not preload non-collection association' do
|
|
64
|
-
value = @user.company
|
|
65
|
-
value.
|
|
66
|
-
|
|
79
|
+
value = @user.company = MiniTest::Mock.new
|
|
80
|
+
value.expect(:to_a, nil)
|
|
81
|
+
|
|
82
|
+
with_association_for @user, :company
|
|
67
83
|
assert_select 'form select.select#user_company_id'
|
|
68
|
-
assert_select 'form select option[value=1]', 'Company 1'
|
|
69
|
-
assert_select 'form select option[value=2]', 'Company 2'
|
|
70
|
-
assert_select 'form select option[value=3]', 'Company 3'
|
|
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
|
|
71
91
|
end
|
|
72
92
|
|
|
73
93
|
# ASSOCIATIONS - BELONGS TO
|
|
74
94
|
test 'builder creates a select for belongs_to associations' do
|
|
75
95
|
with_association_for @user, :company
|
|
76
96
|
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'
|
|
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'
|
|
80
106
|
end
|
|
81
107
|
|
|
82
108
|
test 'builder allows collection radio for belongs_to associations' do
|
|
83
|
-
with_association_for @user, :company, :
|
|
109
|
+
with_association_for @user, :company, as: :radio_buttons
|
|
84
110
|
assert_select 'form input.radio_buttons#user_company_id_1'
|
|
85
111
|
assert_select 'form input.radio_buttons#user_company_id_2'
|
|
86
112
|
assert_select 'form input.radio_buttons#user_company_id_3'
|
|
87
113
|
end
|
|
88
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
|
+
|
|
89
140
|
test 'builder marks the record which already belongs to the user' do
|
|
90
141
|
@user.company_id = 2
|
|
91
|
-
with_association_for @user, :company, :
|
|
142
|
+
with_association_for @user, :company, as: :radio_buttons
|
|
92
143
|
assert_no_select 'form input.radio_buttons#user_company_id_1[checked=checked]'
|
|
93
144
|
assert_select 'form input.radio_buttons#user_company_id_2[checked=checked]'
|
|
94
145
|
assert_no_select 'form input.radio_buttons#user_company_id_3[checked=checked]'
|
|
95
146
|
end
|
|
96
147
|
|
|
97
148
|
# ASSOCIATIONS - FINDERS
|
|
98
|
-
test 'builder
|
|
149
|
+
test 'builder uses reflection conditions to find collection' do
|
|
99
150
|
with_association_for @user, :special_company
|
|
100
151
|
assert_select 'form select.select#user_special_company_id'
|
|
101
|
-
assert_select 'form select option[value=1]'
|
|
102
|
-
assert_no_select 'form select option[value=2]'
|
|
103
|
-
assert_no_select 'form select option[value=3]'
|
|
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"]'
|
|
104
155
|
end
|
|
105
156
|
|
|
106
|
-
test 'builder
|
|
107
|
-
with_association_for @user, :company, :
|
|
108
|
-
:
|
|
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')]
|
|
109
160
|
assert_select 'form select.select#user_company_id'
|
|
110
|
-
assert_no_select 'form select option[value=1]'
|
|
111
|
-
assert_select 'form select option[value=999]', 'Teste'
|
|
112
|
-
assert_select 'form select option', :
|
|
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
|
|
113
164
|
end
|
|
114
165
|
|
|
115
166
|
# ASSOCIATIONS - has_*
|
|
116
167
|
test 'builder does not allow has_one associations' do
|
|
117
|
-
assert_raise
|
|
118
|
-
with_association_for @user, :first_company, :
|
|
168
|
+
assert_raise ArgumentError do
|
|
169
|
+
with_association_for @user, :first_company, as: :radio_buttons
|
|
119
170
|
end
|
|
120
171
|
end
|
|
121
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
|
+
|
|
122
191
|
test 'builder creates a select with multiple options for collection associations' do
|
|
123
192
|
with_association_for @user, :tags
|
|
124
193
|
assert_select 'form select.select#user_tag_ids'
|
|
125
|
-
assert_select 'form select[multiple=multiple]
|
|
126
|
-
assert_select 'form select option[value=1]', 'Tag 1'
|
|
127
|
-
assert_select 'form select option[value=2]', 'Tag 2'
|
|
128
|
-
assert_select 'form select option[value=3]', 'Tag 3'
|
|
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'
|
|
129
198
|
end
|
|
130
199
|
|
|
131
200
|
test 'builder allows size to be overwritten for collection associations' do
|
|
132
|
-
with_association_for @user, :tags, :
|
|
133
|
-
assert_select 'form select[multiple=multiple][size=10]'
|
|
201
|
+
with_association_for @user, :tags, input_html: { size: 10 }
|
|
202
|
+
assert_select 'form select[multiple=multiple][size="10"]'
|
|
134
203
|
end
|
|
135
204
|
|
|
136
205
|
test 'builder marks all selected records which already belongs to user' do
|
|
137
206
|
@user.tag_ids = [1, 2]
|
|
138
207
|
with_association_for @user, :tags
|
|
139
|
-
assert_select 'form select option[value=1][selected=selected]'
|
|
140
|
-
assert_select 'form select option[value=2][selected=selected]'
|
|
141
|
-
assert_no_select 'form select option[value=3][selected=selected]'
|
|
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]'
|
|
142
211
|
end
|
|
143
212
|
|
|
144
213
|
test 'builder allows a collection of check boxes for collection associations' do
|
|
145
214
|
@user.tag_ids = [1, 2]
|
|
146
|
-
with_association_for @user, :tags, :
|
|
215
|
+
with_association_for @user, :tags, as: :check_boxes
|
|
147
216
|
assert_select 'form input#user_tag_ids_1[type=checkbox]'
|
|
148
217
|
assert_select 'form input#user_tag_ids_2[type=checkbox]'
|
|
149
218
|
assert_select 'form input#user_tag_ids_3[type=checkbox]'
|
|
@@ -151,27 +220,27 @@ class AssociationTest < ActionView::TestCase
|
|
|
151
220
|
|
|
152
221
|
test 'builder marks all selected records for collection boxes' do
|
|
153
222
|
@user.tag_ids = [1, 2]
|
|
154
|
-
with_association_for @user, :tags, :
|
|
155
|
-
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
|
156
|
-
assert_select 'form input[type=checkbox][value=2][checked=checked]'
|
|
157
|
-
assert_no_select 'form input[type=checkbox][value=3][checked=checked]'
|
|
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]'
|
|
158
227
|
end
|
|
159
228
|
|
|
160
229
|
test 'builder with collection support giving collection and item wrapper tags' do
|
|
161
|
-
with_association_for @user, :tags, :
|
|
162
|
-
:
|
|
230
|
+
with_association_for @user, :tags, as: :check_boxes,
|
|
231
|
+
collection_wrapper_tag: :ul, item_wrapper_tag: :li
|
|
163
232
|
|
|
164
|
-
assert_select 'form ul', :
|
|
165
|
-
assert_select 'form ul li', :
|
|
233
|
+
assert_select 'form ul', count: 1
|
|
234
|
+
assert_select 'form ul li', count: 3
|
|
166
235
|
end
|
|
167
236
|
|
|
168
|
-
test 'builder with collection support
|
|
169
|
-
options = { :
|
|
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 }
|
|
170
239
|
with_association_for @user, :tags, options
|
|
171
240
|
|
|
172
|
-
assert_select 'form ul', :
|
|
173
|
-
assert_select 'form ul li', :
|
|
174
|
-
assert_equal({ :
|
|
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 },
|
|
175
244
|
options)
|
|
176
245
|
end
|
|
177
246
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
require 'test_helper'
|
|
3
4
|
|
|
@@ -8,33 +9,33 @@ class ButtonTest < ActionView::TestCase
|
|
|
8
9
|
end
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
test 'builder
|
|
12
|
+
test 'builder creates buttons' do
|
|
12
13
|
with_button_for :post, :submit
|
|
13
|
-
assert_select 'form input.button[type=submit][value=Save Post]'
|
|
14
|
+
assert_select 'form input.button[type=submit][value="Save Post"]'
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
test 'builder
|
|
17
|
-
with_button_for :post, :submit, :
|
|
18
|
-
assert_select 'form input.button.my_button[type=submit][value=Save Post]'
|
|
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"]'
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
test 'builder
|
|
22
|
-
options = { :
|
|
22
|
+
test 'builder does not modify the options hash' do
|
|
23
|
+
options = { class: 'my_button' }
|
|
23
24
|
with_button_for :post, :submit, options
|
|
24
|
-
assert_select 'form input.button.my_button[type=submit][value=Save Post]'
|
|
25
|
-
assert_equal({ :
|
|
25
|
+
assert_select 'form input.button.my_button[type=submit][value="Save Post"]'
|
|
26
|
+
assert_equal({ class: 'my_button' }, options)
|
|
26
27
|
end
|
|
27
28
|
|
|
28
|
-
test 'builder
|
|
29
|
+
test 'builder creates buttons for records' do
|
|
29
30
|
@user.new_record!
|
|
30
31
|
with_button_for @user, :submit
|
|
31
|
-
assert_select 'form input.button[type=submit][value=Create User]'
|
|
32
|
+
assert_select 'form input.button[type=submit][value="Create User"]'
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
test "builder
|
|
35
|
-
swap SimpleForm, :
|
|
35
|
+
test "builder uses the default class from the configuration" do
|
|
36
|
+
swap SimpleForm, button_class: 'btn' do
|
|
36
37
|
with_button_for :post, :submit
|
|
37
|
-
assert_select 'form input.btn[type=submit][value=Save Post]'
|
|
38
|
+
assert_select 'form input.btn[type=submit][value="Save Post"]'
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
require 'test_helper'
|
|
3
4
|
|
|
4
5
|
# Tests for f.error_notification
|
|
5
6
|
class ErrorNotificationTest < ActionView::TestCase
|
|
6
|
-
def with_error_notification_for(object, options={}, &block)
|
|
7
|
+
def with_error_notification_for(object, options = {}, &block)
|
|
7
8
|
with_concat_form_for(object) do |f|
|
|
8
9
|
f.error_notification(options)
|
|
9
10
|
end
|
|
@@ -23,11 +24,11 @@ class ErrorNotificationTest < ActionView::TestCase
|
|
|
23
24
|
|
|
24
25
|
test 'error notification is generated when the object has some error' do
|
|
25
26
|
with_error_notification_for @user
|
|
26
|
-
assert_select 'p.error_notification', '
|
|
27
|
+
assert_select 'p.error_notification', 'Please review the problems below:'
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
test 'error notification uses I18n based on model to generate the notification message' do
|
|
30
|
-
store_translations(:en, :
|
|
31
|
+
store_translations(:en, simple_form: { error_notification: { user:
|
|
31
32
|
'Alguns erros foram encontrados para o usuário:'
|
|
32
33
|
} }) do
|
|
33
34
|
with_error_notification_for @user
|
|
@@ -36,8 +37,8 @@ class ErrorNotificationTest < ActionView::TestCase
|
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
test 'error notification uses I18n fallbacking to default message' do
|
|
39
|
-
store_translations(:en, :
|
|
40
|
-
:
|
|
40
|
+
store_translations(:en, simple_form: { error_notification: {
|
|
41
|
+
default_message: 'Opa! Alguns erros foram encontrados, poderia verificar?'
|
|
41
42
|
} }) do
|
|
42
43
|
with_error_notification_for @user
|
|
43
44
|
assert_select 'p.error_notification', 'Opa! Alguns erros foram encontrados, poderia verificar?'
|
|
@@ -45,30 +46,30 @@ class ErrorNotificationTest < ActionView::TestCase
|
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
test 'error notification allows passing the notification message' do
|
|
48
|
-
with_error_notification_for @user, :
|
|
49
|
+
with_error_notification_for @user, message: 'Erro encontrado ao criar usuario'
|
|
49
50
|
assert_select 'p.error_notification', 'Erro encontrado ao criar usuario'
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
test 'error notification accepts other html options' do
|
|
53
|
-
with_error_notification_for @user, :
|
|
54
|
+
with_error_notification_for @user, id: 'user_error_message', class: 'form_error'
|
|
54
55
|
assert_select 'p#user_error_message.form_error.error_notification'
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
test 'error notification allows configuring the wrapper element' do
|
|
58
|
-
swap SimpleForm, :
|
|
59
|
+
swap SimpleForm, error_notification_tag: :div do
|
|
59
60
|
with_error_notification_for @user
|
|
60
61
|
assert_select 'div.error_notification'
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
test 'error notification can contain HTML tags' do
|
|
65
|
-
with_error_notification_for @user, :
|
|
66
|
+
with_error_notification_for @user, message: 'Erro encontrado ao criar <b>usuário</b>'
|
|
66
67
|
assert_select 'p.error_notification', 'Erro encontrado ao criar usuário'
|
|
67
68
|
assert_select 'p.error_notification b', 'usuário'
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
test 'error notification uses I18n based on model to generate the notification message and accepts HTML' do
|
|
71
|
-
store_translations(:en, :
|
|
72
|
+
store_translations(:en, simple_form: { error_notification: { user:
|
|
72
73
|
'Alguns erros foram encontrados para o <b>usuário</b>:'
|
|
73
74
|
} }) do
|
|
74
75
|
with_error_notification_for @user
|