dry_crud 6.0.0 → 8.0.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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +2 -2
- data/README.rdoc +7 -6
- data/VERSION +1 -1
- data/app/assets/stylesheets/sample.scss +45 -24
- data/app/controllers/crud_controller.rb +24 -26
- data/app/controllers/dry_crud/generic_model.rb +6 -12
- data/app/controllers/dry_crud/nestable.rb +1 -4
- data/app/controllers/dry_crud/rememberable.rb +1 -4
- data/app/controllers/dry_crud/render_callbacks.rb +4 -12
- data/app/controllers/dry_crud/searchable.rb +3 -10
- data/app/controllers/dry_crud/sortable.rb +3 -10
- data/app/controllers/list_controller.rb +1 -3
- data/app/helpers/actions_helper.rb +13 -15
- data/app/helpers/dry_crud/form/builder.rb +56 -62
- data/app/helpers/dry_crud/form/control.rb +12 -19
- data/app/helpers/dry_crud/table/actions.rb +15 -20
- data/app/helpers/dry_crud/table/builder.rb +12 -15
- data/app/helpers/dry_crud/table/col.rb +5 -8
- data/app/helpers/dry_crud/table/sorting.rb +3 -6
- data/app/helpers/form_helper.rb +11 -15
- data/app/helpers/format_helper.rb +18 -20
- data/app/helpers/i18n_helper.rb +13 -15
- data/app/helpers/table_helper.rb +16 -19
- data/app/helpers/utility_helper.rb +12 -14
- data/app/views/crud/new.html.erb +1 -1
- data/app/views/crud/new.html.haml +1 -1
- data/app/views/layouts/application.html.erb +8 -6
- data/app/views/layouts/application.html.haml +6 -5
- data/app/views/list/_search.html.erb +1 -3
- data/app/views/list/_search.html.haml +1 -2
- data/app/views/shared/_error_messages.html.erb +2 -2
- data/lib/dry_crud/engine.rb +1 -3
- data/lib/dry_crud.rb +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +18 -18
- data/lib/generators/dry_crud/dry_crud_generator_base.rb +8 -8
- data/lib/generators/dry_crud/file_generator.rb +6 -6
- data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +1 -1
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +122 -122
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +55 -60
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +24 -26
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +16 -18
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +90 -94
- data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +33 -34
- data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +59 -61
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +20 -23
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +66 -68
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +11 -13
- data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +63 -65
- data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +25 -27
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +74 -74
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +21 -21
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +21 -23
- data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +68 -70
- data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +26 -28
- data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +28 -30
- data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +17 -19
- data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +13 -15
- data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +15 -19
- data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +9 -14
- data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +16 -20
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +8 -10
- metadata +9 -10
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "test_helper"
|
2
|
+
require "support/crud_test_model"
|
3
3
|
|
4
4
|
module DryCrud
|
5
5
|
module Form
|
@@ -22,226 +22,226 @@ module DryCrud
|
|
22
22
|
@form = DryCrud::Form::Builder.new(:entry, @entry, self, {})
|
23
23
|
end
|
24
24
|
|
25
|
-
test
|
25
|
+
test "input_field dispatches string attr to string_field" do
|
26
26
|
assert_equal form.with_addon(
|
27
27
|
form.string_field(:name,
|
28
|
-
required:
|
29
|
-
|
28
|
+
required: "required"),
|
29
|
+
"*"
|
30
30
|
),
|
31
31
|
form.input_field(:name)
|
32
32
|
assert form.string_field(:name).html_safe?
|
33
33
|
end
|
34
34
|
|
35
|
-
test
|
35
|
+
test "input_field dispatches password attr to password_field" do
|
36
36
|
assert_equal form.password_field(:password),
|
37
37
|
form.input_field(:password)
|
38
38
|
assert form.password_field(:name).html_safe?
|
39
39
|
end
|
40
40
|
|
41
|
-
test
|
41
|
+
test "input_field dispatches email attr to email_field" do
|
42
42
|
assert_equal form.email_field(:email),
|
43
43
|
form.input_field(:email)
|
44
44
|
assert form.email_field(:name).html_safe?
|
45
45
|
end
|
46
46
|
|
47
|
-
test
|
47
|
+
test "input_field dispatches text attr to text_area" do
|
48
48
|
assert_equal form.text_area(:remarks),
|
49
49
|
form.input_field(:remarks)
|
50
50
|
assert form.text_area(:remarks).html_safe?
|
51
51
|
end
|
52
52
|
|
53
|
-
test
|
53
|
+
test "input_field dispatches integer attr to integer_field" do
|
54
54
|
assert_equal form.integer_field(:children),
|
55
55
|
form.input_field(:children)
|
56
56
|
assert form.integer_field(:children).html_safe?
|
57
57
|
end
|
58
58
|
|
59
|
-
test
|
59
|
+
test "input_field dispatches boolean attr to boolean_field" do
|
60
60
|
assert_equal form.boolean_field(:human),
|
61
61
|
form.input_field(:human)
|
62
62
|
assert form.boolean_field(:human).html_safe?
|
63
63
|
end
|
64
64
|
|
65
|
-
test
|
65
|
+
test "input_field dispatches date attr to date_field" do
|
66
66
|
assert_equal form.date_field(:birthdate),
|
67
67
|
form.input_field(:birthdate)
|
68
68
|
assert form.date_field(:birthdate).html_safe?
|
69
69
|
end
|
70
70
|
|
71
|
-
test
|
71
|
+
test "input_field dispatches belongs_to attr to select field" do
|
72
72
|
assert_equal form.belongs_to_field(:companion_id),
|
73
73
|
form.input_field(:companion_id)
|
74
74
|
assert form.belongs_to_field(:companion_id).html_safe?
|
75
75
|
end
|
76
76
|
|
77
|
-
test
|
78
|
-
|
77
|
+
test "input_field dispatches has_and_belongs_to_many attr to " \
|
78
|
+
"select field" do
|
79
79
|
assert_equal form.has_many_field(:other_ids),
|
80
80
|
form.input_field(:other_ids)
|
81
81
|
assert form.has_many_field(:other_ids).html_safe?
|
82
82
|
end
|
83
83
|
|
84
|
-
test
|
84
|
+
test "input_field dispatches has_many attr to select field" do
|
85
85
|
assert_equal form.has_many_field(:more_ids),
|
86
86
|
form.input_field(:more_ids)
|
87
87
|
assert form.has_many_field(:more_ids).html_safe?
|
88
88
|
end
|
89
89
|
|
90
|
-
test
|
90
|
+
test "input_fields concats multiple fields" do
|
91
91
|
result = form.labeled_input_fields(:name, :remarks, :children)
|
92
92
|
assert result.html_safe?
|
93
|
-
assert result.include?(form.input_field(:name, required:
|
93
|
+
assert result.include?(form.input_field(:name, required: "required"))
|
94
94
|
assert result.include?(form.input_field(:remarks))
|
95
95
|
assert result.include?(form.input_field(:children))
|
96
96
|
end
|
97
97
|
|
98
|
-
test
|
98
|
+
test "labeld_input_field adds required mark" do
|
99
99
|
result = form.labeled_input_field(:name)
|
100
|
-
assert result.include?(
|
100
|
+
assert result.include?("input-group-text")
|
101
101
|
result = form.labeled_input_field(:remarks)
|
102
|
-
assert_not result.include?(
|
102
|
+
assert_not result.include?("input-group-text")
|
103
103
|
end
|
104
104
|
|
105
|
-
test
|
106
|
-
result = form.labeled_input_field(:name, help:
|
107
|
-
assert result.include?(form.help_block(
|
108
|
-
assert result.include?(
|
105
|
+
test "labeld_input_field adds help text" do
|
106
|
+
result = form.labeled_input_field(:name, help: "Some Help")
|
107
|
+
assert result.include?(form.help_block("Some Help"))
|
108
|
+
assert result.include?("input-group-text")
|
109
109
|
end
|
110
110
|
|
111
|
-
test
|
111
|
+
test "belongs_to_field has all options by default" do
|
112
112
|
f = form.belongs_to_field(:companion_id)
|
113
|
-
assert_equal 7, f.scan(
|
113
|
+
assert_equal 7, f.scan("</option>").size
|
114
114
|
end
|
115
115
|
|
116
|
-
test
|
116
|
+
test "belongs_to_field with :list option" do
|
117
117
|
list = CrudTestModel.all
|
118
118
|
f = form.belongs_to_field(:companion_id,
|
119
|
-
list: [list.first, list.second])
|
120
|
-
assert_equal 3, f.scan(
|
119
|
+
list: [ list.first, list.second ])
|
120
|
+
assert_equal 3, f.scan("</option>").size
|
121
121
|
end
|
122
122
|
|
123
|
-
test
|
123
|
+
test "belongs_to_field with instance variable" do
|
124
124
|
list = CrudTestModel.all
|
125
|
-
@companions = [list.first, list.second]
|
125
|
+
@companions = [ list.first, list.second ]
|
126
126
|
f = form.belongs_to_field(:companion_id)
|
127
|
-
assert_equal 3, f.scan(
|
127
|
+
assert_equal 3, f.scan("</option>").size
|
128
128
|
end
|
129
129
|
|
130
|
-
test
|
130
|
+
test "belongs_to_field with empty list" do
|
131
131
|
@companions = []
|
132
132
|
f = form.belongs_to_field(:companion_id)
|
133
|
-
assert_match t(
|
134
|
-
assert_equal 0, f.scan(
|
133
|
+
assert_match t("global.associations.none_available"), f
|
134
|
+
assert_equal 0, f.scan("</option>").size
|
135
135
|
end
|
136
136
|
|
137
|
-
test
|
137
|
+
test "has_and_belongs_to_many_field has all options by default" do
|
138
138
|
f = form.has_many_field(:other_ids)
|
139
|
-
assert_equal 6, f.scan(
|
139
|
+
assert_equal 6, f.scan("</option>").size
|
140
140
|
end
|
141
141
|
|
142
|
-
test
|
142
|
+
test "has_and_belongs_to_many_field with :list option" do
|
143
143
|
list = OtherCrudTestModel.all
|
144
|
-
f = form.has_many_field(:other_ids, list: [list.first, list.second])
|
145
|
-
assert_equal 2, f.scan(
|
144
|
+
f = form.has_many_field(:other_ids, list: [ list.first, list.second ])
|
145
|
+
assert_equal 2, f.scan("</option>").size
|
146
146
|
end
|
147
147
|
|
148
|
-
test
|
148
|
+
test "has_and_belongs_to_many_field with instance variable" do
|
149
149
|
list = OtherCrudTestModel.all
|
150
|
-
@others = [list.first, list.second]
|
150
|
+
@others = [ list.first, list.second ]
|
151
151
|
f = form.has_many_field(:other_ids)
|
152
|
-
assert_equal 2, f.scan(
|
152
|
+
assert_equal 2, f.scan("</option>").size
|
153
153
|
end
|
154
154
|
|
155
|
-
test
|
155
|
+
test "has_and_belongs_to_many_field with empty list" do
|
156
156
|
@others = []
|
157
157
|
f = form.has_many_field(:other_ids)
|
158
|
-
assert_match t(
|
159
|
-
assert_equal 0, f.scan(
|
158
|
+
assert_match t("global.associations.none_available"), f
|
159
|
+
assert_equal 0, f.scan("</option>").size
|
160
160
|
end
|
161
161
|
|
162
|
-
test
|
162
|
+
test "has_many_field has all options by default" do
|
163
163
|
f = form.has_many_field(:more_ids)
|
164
|
-
assert_equal 6, f.scan(
|
164
|
+
assert_equal 6, f.scan("</option>").size
|
165
165
|
end
|
166
166
|
|
167
|
-
test
|
167
|
+
test "has_many_field with :list option" do
|
168
168
|
list = OtherCrudTestModel.all
|
169
|
-
f = form.has_many_field(:more_ids, list: [list.first, list.second])
|
170
|
-
assert_equal 2, f.scan(
|
169
|
+
f = form.has_many_field(:more_ids, list: [ list.first, list.second ])
|
170
|
+
assert_equal 2, f.scan("</option>").size
|
171
171
|
end
|
172
172
|
|
173
|
-
test
|
173
|
+
test "has_many_field with instance variable" do
|
174
174
|
list = OtherCrudTestModel.all
|
175
|
-
@mores = [list.first, list.second]
|
175
|
+
@mores = [ list.first, list.second ]
|
176
176
|
f = form.has_many_field(:more_ids)
|
177
|
-
assert_equal 2, f.scan(
|
177
|
+
assert_equal 2, f.scan("</option>").size
|
178
178
|
end
|
179
179
|
|
180
|
-
test
|
180
|
+
test "has_many_field with empty list" do
|
181
181
|
@mores = []
|
182
182
|
f = form.has_many_field(:more_ids)
|
183
|
-
assert_match t(
|
184
|
-
assert_equal 0, f.scan(
|
183
|
+
assert_match t("global.associations.none_available"), f
|
184
|
+
assert_equal 0, f.scan("</option>").size
|
185
185
|
end
|
186
186
|
|
187
|
-
test
|
187
|
+
test "string_field sets maxlength attribute if limit" do
|
188
188
|
assert_match(/maxlength="50"/, form.string_field(:name))
|
189
189
|
end
|
190
190
|
|
191
|
-
test
|
191
|
+
test "label creates captionized label" do
|
192
192
|
assert_match(/label [^>]*for.+Gugus dada/, form.label(:gugus_dada))
|
193
193
|
assert form.label(:gugus_dada).html_safe?
|
194
194
|
end
|
195
195
|
|
196
|
-
test
|
197
|
-
assert_match(/label [^>]*for.+hoho/, form.label(:gugus_dada,
|
198
|
-
assert form.label(:gugus_dada,
|
196
|
+
test "classic label still works" do
|
197
|
+
assert_match(/label [^>]*for.+hoho/, form.label(:gugus_dada, "hoho"))
|
198
|
+
assert form.label(:gugus_dada, "hoho").html_safe?
|
199
199
|
end
|
200
200
|
|
201
|
-
test
|
201
|
+
test "labeled_text_field create label" do
|
202
202
|
assert_match(/label [^>]*for.+input/m,
|
203
203
|
form.labeled_string_field(:name))
|
204
204
|
assert form.labeled_string_field(:name).html_safe?
|
205
205
|
end
|
206
206
|
|
207
|
-
test
|
208
|
-
result = form.labeled(
|
207
|
+
test "labeled field creates label" do
|
208
|
+
result = form.labeled("gugus",
|
209
209
|
"<input type='text' name='gugus' />".html_safe)
|
210
210
|
assert result.html_safe?
|
211
211
|
assert_match(/label [^>]*for.+<input/m, result)
|
212
212
|
end
|
213
213
|
|
214
|
-
test
|
215
|
-
result = form.labeled(
|
214
|
+
test "labeled field creates label and block" do
|
215
|
+
result = form.labeled("gugus") do
|
216
216
|
"<input type='text' name='gugus' />".html_safe
|
217
217
|
end
|
218
218
|
assert result.html_safe?
|
219
219
|
assert_match(/label [^>]*for.+<input/m, result)
|
220
220
|
end
|
221
221
|
|
222
|
-
test
|
223
|
-
result = form.labeled(
|
222
|
+
test "labeled field creates label with caption" do
|
223
|
+
result = form.labeled("gugus",
|
224
224
|
"<input type='text' name='gugus' />".html_safe,
|
225
|
-
caption:
|
225
|
+
caption: "Caption")
|
226
226
|
assert result.html_safe?
|
227
227
|
assert_match(/label [^>]*for.+>Caption<\/label>.*<input/m, result)
|
228
228
|
end
|
229
229
|
|
230
|
-
test
|
231
|
-
result = form.labeled(
|
230
|
+
test "labeled field creates label with caption and block" do
|
231
|
+
result = form.labeled("gugus", caption: "Caption") do
|
232
232
|
"<input type='text' name='gugus' />".html_safe
|
233
233
|
end
|
234
234
|
assert result.html_safe?
|
235
235
|
assert_match(/label [^>]*for.+>Caption<\/label>.*<input/m, result)
|
236
236
|
end
|
237
237
|
|
238
|
-
test
|
238
|
+
test "method missing still works" do
|
239
239
|
assert_raise(NoMethodError) do
|
240
240
|
form.blabla
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
244
|
-
test
|
244
|
+
test "respond to still works" do
|
245
245
|
assert_not form.respond_to?(:blalba)
|
246
246
|
assert form.respond_to?(:text_field)
|
247
247
|
assert form.respond_to?(:labeled_text_field)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
module DryCrud
|
4
4
|
module Table
|
@@ -20,47 +20,47 @@ module DryCrud
|
|
20
20
|
"#{obj.size} chars"
|
21
21
|
end
|
22
22
|
|
23
|
-
test
|
23
|
+
test "html header" do
|
24
24
|
table.attrs :upcase, :size
|
25
25
|
|
26
|
-
dom =
|
26
|
+
dom = "<tr><th>Upcase</th><th>Size</th></tr>"
|
27
27
|
|
28
28
|
assert_dom_equal dom, table.send(:html_header)
|
29
29
|
end
|
30
30
|
|
31
|
-
test
|
31
|
+
test "single attr row" do
|
32
32
|
table.attrs :upcase, :size
|
33
33
|
|
34
|
-
dom =
|
34
|
+
dom = "<tr><td>FOO</td><td>3 chars</td></tr>"
|
35
35
|
|
36
36
|
assert_dom_equal dom, table.send(:html_row, entries.first)
|
37
37
|
end
|
38
38
|
|
39
|
-
test
|
40
|
-
table.col(
|
39
|
+
test "custom row" do
|
40
|
+
table.col("Header", class: "hula") { |e| "Weights #{e.size} kg" }
|
41
41
|
|
42
42
|
dom = '<tr><td class="hula">Weights 3 kg</td></tr>'
|
43
43
|
|
44
44
|
assert_dom_equal dom, table.send(:html_row, entries.first)
|
45
45
|
end
|
46
46
|
|
47
|
-
test
|
47
|
+
test "attr col output" do
|
48
48
|
table.attrs :upcase
|
49
49
|
col = table.cols.first
|
50
50
|
|
51
|
-
assert_equal
|
52
|
-
assert_equal
|
53
|
-
assert_equal
|
51
|
+
assert_equal "<th>Upcase</th>", col.html_header
|
52
|
+
assert_equal "FOO", col.content("foo")
|
53
|
+
assert_equal "<td>FOO</td>", col.html_cell("foo")
|
54
54
|
end
|
55
55
|
|
56
|
-
test
|
56
|
+
test "attr col content with custom format_size method" do
|
57
57
|
table.attrs :size
|
58
58
|
col = table.cols.first
|
59
59
|
|
60
|
-
assert_equal
|
60
|
+
assert_equal "4 chars", col.content("abcd")
|
61
61
|
end
|
62
62
|
|
63
|
-
test
|
63
|
+
test "two x two table" do
|
64
64
|
dom = <<-FIN
|
65
65
|
<table>
|
66
66
|
<thead>
|
@@ -72,14 +72,14 @@ module DryCrud
|
|
72
72
|
</tbody>
|
73
73
|
</table>
|
74
74
|
FIN
|
75
|
-
dom.gsub!(/[\n\t]/,
|
75
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
76
76
|
|
77
77
|
table.attrs :upcase, :size
|
78
78
|
|
79
79
|
assert_dom_equal dom, table.to_html
|
80
80
|
end
|
81
81
|
|
82
|
-
test
|
82
|
+
test "table with before and after cells" do
|
83
83
|
dom = <<-FIN
|
84
84
|
<table>
|
85
85
|
<thead>
|
@@ -105,16 +105,16 @@ module DryCrud
|
|
105
105
|
</tbody>
|
106
106
|
</table>
|
107
107
|
FIN
|
108
|
-
dom.gsub!(/[\n\t]/,
|
108
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
109
109
|
|
110
|
-
table.col(
|
110
|
+
table.col("head", class: "left") { |e| link_to e, "/" }
|
111
111
|
table.attrs :upcase, :size
|
112
112
|
table.col { |e| "Never #{e}" }
|
113
113
|
|
114
114
|
assert_dom_equal dom, table.to_html
|
115
115
|
end
|
116
116
|
|
117
|
-
test
|
117
|
+
test "empty entries collection renders empty table" do
|
118
118
|
dom = <<-FIN
|
119
119
|
<table>
|
120
120
|
<thead>
|
@@ -129,10 +129,10 @@ module DryCrud
|
|
129
129
|
</tbody>
|
130
130
|
</table>
|
131
131
|
FIN
|
132
|
-
dom.gsub!(/[\n\t]/,
|
132
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
133
133
|
|
134
134
|
table = DryCrud::Table::Builder.new([], self)
|
135
|
-
table.col(
|
135
|
+
table.col("head", class: "left") { |e| link_to e, "/" }
|
136
136
|
table.attrs :upcase, :size
|
137
137
|
table.col { |e| "Never #{e}" }
|
138
138
|
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "test_helper"
|
2
|
+
require "support/crud_test_model"
|
3
|
+
require "support/crud_test_helper"
|
4
4
|
|
5
5
|
# Test FormHelper
|
6
6
|
class FormHelperTest < ActionView::TestCase
|
7
|
-
|
8
7
|
include UtilityHelper
|
9
8
|
include FormatHelper
|
10
9
|
include I18nHelper
|
@@ -13,11 +12,11 @@ class FormHelperTest < ActionView::TestCase
|
|
13
12
|
setup :reset_db, :setup_db, :create_test_data
|
14
13
|
teardown :reset_db
|
15
14
|
|
16
|
-
test
|
17
|
-
e = crud_test_models(
|
15
|
+
test "plain form for existing entry" do
|
16
|
+
e = crud_test_models("AAAAA")
|
18
17
|
f = with_test_routing do
|
19
18
|
capture do
|
20
|
-
plain_form(e, html: { class:
|
19
|
+
plain_form(e, html: { class: "special" }) do |form|
|
21
20
|
form.labeled_input_fields :name, :birthdate
|
22
21
|
end
|
23
22
|
end
|
@@ -34,14 +33,14 @@ class FormHelperTest < ActionView::TestCase
|
|
34
33
|
.*?name="crud_test_model\[name\]"/x, f)
|
35
34
|
end
|
36
35
|
|
37
|
-
test
|
38
|
-
e = crud_test_models(
|
36
|
+
test "standard form" do
|
37
|
+
e = crud_test_models("AAAAA")
|
39
38
|
f = with_test_routing do
|
40
39
|
capture do
|
41
40
|
standard_form(e,
|
42
41
|
:name, :children, :birthdate, :human,
|
43
|
-
cancel_url:
|
44
|
-
html: { class:
|
42
|
+
cancel_url: "/somewhere",
|
43
|
+
html: { class: "special" })
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
@@ -57,20 +56,20 @@ class FormHelperTest < ActionView::TestCase
|
|
57
56
|
assert_match(/input .*?type="date"
|
58
57
|
.*?name="crud_test_model\[birthdate\]"/x, f)
|
59
58
|
assert_match(/input .*?type="number"
|
60
|
-
.*?value
|
59
|
+
.*?value="9"
|
61
60
|
.*?name="crud_test_model\[children\]"/x, f)
|
62
61
|
assert_match(/input .*?type="checkbox"
|
63
62
|
.*?name="crud_test_model\[human\]"/x, f)
|
64
|
-
assert_match(/button\ .*?type="submit"
|
63
|
+
assert_match(/button\ .*?type="submit".*>
|
65
64
|
#{t('global.button.save')}
|
66
|
-
|
67
|
-
assert_match(
|
65
|
+
<\/button>/x, f)
|
66
|
+
assert_match(/<a\ .*href="\/somewhere".*>
|
68
67
|
#{t('global.button.cancel')}
|
69
|
-
|
68
|
+
<\/a>/x, f)
|
70
69
|
end
|
71
70
|
|
72
|
-
test
|
73
|
-
e = crud_test_models(
|
71
|
+
test "standard form with errors" do
|
72
|
+
e = crud_test_models("AAAAA")
|
74
73
|
e.name = nil
|
75
74
|
assert_not e.valid?
|
76
75
|
|
@@ -88,15 +87,15 @@ class FormHelperTest < ActionView::TestCase
|
|
88
87
|
.*?name="_method"
|
89
88
|
.*?value="(patch|put)"/x, f)
|
90
89
|
assert_match(/div[^>]* id='error_explanation'/, f)
|
91
|
-
assert_match(/
|
92
|
-
|
93
|
-
|
90
|
+
assert_match(/input .*?class="is-invalid\ form-control"
|
91
|
+
.*?type="text"
|
92
|
+
.*?name="crud_test_model\[name\]"/x, f)
|
94
93
|
assert_match(/input .*?value="1910-01-01"
|
95
94
|
.*?type="date"
|
96
95
|
.*?name="crud_test_model\[birthdate\]"/x, f)
|
97
96
|
end
|
98
97
|
|
99
|
-
test
|
98
|
+
test "crud form" do
|
100
99
|
f = with_test_routing do
|
101
100
|
capture { crud_form }
|
102
101
|
end
|
@@ -129,5 +128,4 @@ class FormHelperTest < ActionView::TestCase
|
|
129
128
|
def entry
|
130
129
|
@entry ||= CrudTestModel.first
|
131
130
|
end
|
132
|
-
|
133
131
|
end
|