dry_crud 2.1.1 → 2.1.2
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 +9 -9
- data/VERSION +1 -1
- data/app/assets/stylesheets/sample.scss +1 -1
- data/app/controllers/crud_controller.rb +1 -1
- data/app/controllers/dry_crud/generic_model.rb +45 -45
- data/app/controllers/dry_crud/nestable.rb +1 -1
- data/app/controllers/dry_crud/render_callbacks.rb +2 -0
- data/app/controllers/dry_crud/responder.rb +3 -0
- data/app/controllers/list_controller.rb +1 -1
- data/app/helpers/dry_crud/form/builder.rb +286 -261
- data/app/helpers/dry_crud/form/control.rb +156 -153
- data/app/helpers/dry_crud/table/actions.rb +69 -67
- data/app/helpers/dry_crud/table/builder.rb +96 -95
- data/app/helpers/dry_crud/table/col.rb +17 -16
- data/app/helpers/dry_crud/table/sorting.rb +48 -46
- data/app/helpers/format_helper.rb +2 -2
- data/app/helpers/table_helper.rb +2 -2
- data/lib/generators/dry_crud/file_generator.rb +2 -2
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +4 -6
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +11 -11
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +21 -21
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +21 -17
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +8 -8
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +11 -1
- data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +6 -6
- data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +1 -0
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +250 -245
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +141 -128
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +54 -54
- data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +4 -4
- data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +1 -1
- data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +3 -2
- data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +8 -8
- data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +0 -2
- data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +7 -7
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +3 -3
- metadata +6 -6
@@ -30,7 +30,7 @@ describe 'DryCrud::Form::Builder' do
|
|
30
30
|
|
31
31
|
it 'dispatches name attr to string field' do
|
32
32
|
form.should_receive(:string_field)
|
33
|
-
.with(:name,
|
33
|
+
.with(:name, required: 'required')
|
34
34
|
.and_return('<input>')
|
35
35
|
form.input_field(:name)
|
36
36
|
end
|
@@ -47,10 +47,10 @@ describe 'DryCrud::Form::Builder' do
|
|
47
47
|
last_seen: :datetime_field,
|
48
48
|
companion_id: :belongs_to_field,
|
49
49
|
other_ids: :has_many_field,
|
50
|
-
more_ids: :has_many_field
|
50
|
+
more_ids: :has_many_field
|
51
51
|
}.each do |attr, method|
|
52
52
|
it 'dispatches #{attr} attr to #{method}' do
|
53
|
-
form.should_receive(method).with(attr,
|
53
|
+
form.should_receive(method).with(attr, {})
|
54
54
|
form.input_field(attr)
|
55
55
|
end
|
56
56
|
|
@@ -137,7 +137,7 @@ describe 'DryCrud::Form::Builder' do
|
|
137
137
|
|
138
138
|
describe '#string_field' do
|
139
139
|
it 'sets maxlength if attr has a limit' do
|
140
|
-
form.string_field(:name).should match
|
140
|
+
form.string_field(:name).should match(/maxlength="50"/)
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -147,7 +147,7 @@ describe 'DryCrud::Form::Builder' do
|
|
147
147
|
|
148
148
|
it { should be_html_safe }
|
149
149
|
it 'provides the same interface as rails' do
|
150
|
-
should match
|
150
|
+
should match(/label [^>]*for.+Gugus dada/)
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -156,7 +156,7 @@ describe 'DryCrud::Form::Builder' do
|
|
156
156
|
|
157
157
|
it { should be_html_safe }
|
158
158
|
it 'provides the same interface as rails' do
|
159
|
-
should match
|
159
|
+
should match(/label [^>]*for.+hoho/)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -168,7 +168,7 @@ describe 'DryCrud::Form::Builder' do
|
|
168
168
|
|
169
169
|
it { should be_html_safe }
|
170
170
|
it 'provides the same interface as rails' do
|
171
|
-
should match
|
171
|
+
should match(/label [^>]*for.+input/m)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
@@ -178,7 +178,7 @@ describe 'DryCrud::Form::Builder' do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
it { should be_html_safe }
|
181
|
-
it { should match
|
181
|
+
it { should match(/label [^>]*for.+<input/m) }
|
182
182
|
end
|
183
183
|
|
184
184
|
context 'with custom content in block' do
|
@@ -189,7 +189,7 @@ describe 'DryCrud::Form::Builder' do
|
|
189
189
|
end
|
190
190
|
|
191
191
|
it { should be_html_safe }
|
192
|
-
it { should match
|
192
|
+
it { should match(/label [^>]*for.+<input/m) }
|
193
193
|
end
|
194
194
|
|
195
195
|
context 'with caption and content in argument' do
|
@@ -200,7 +200,7 @@ describe 'DryCrud::Form::Builder' do
|
|
200
200
|
end
|
201
201
|
|
202
202
|
it { should be_html_safe }
|
203
|
-
it { should match
|
203
|
+
it { should match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
|
204
204
|
end
|
205
205
|
|
206
206
|
context 'with caption and content in block' do
|
@@ -211,7 +211,7 @@ describe 'DryCrud::Form::Builder' do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
it { should be_html_safe }
|
214
|
-
it { should match
|
214
|
+
it { should match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -153,60 +153,60 @@ describe FormHelper do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
it do
|
156
|
-
should match
|
156
|
+
should match(/form .*?action="\/crud_test_models\/#{entry.id}"/)
|
157
157
|
end
|
158
158
|
|
159
159
|
it do
|
160
|
-
should match
|
161
|
-
.*?type="text"/x
|
160
|
+
should match(/input .*?name="crud_test_model\[name\]"
|
161
|
+
.*?type="text"/x)
|
162
162
|
end
|
163
163
|
|
164
164
|
it do
|
165
|
-
should match
|
166
|
-
.*?type="text"/x
|
165
|
+
should match(/input .*?name="crud_test_model\[whatever\]"
|
166
|
+
.*?type="text"/x)
|
167
167
|
end
|
168
168
|
|
169
169
|
it do
|
170
|
-
should match
|
171
|
-
.*?type="number"/x
|
170
|
+
should match(/input .*?name="crud_test_model\[children\]"
|
171
|
+
.*?type="number"/x)
|
172
172
|
end
|
173
173
|
|
174
174
|
it do
|
175
|
-
should match
|
176
|
-
.*?type="number"/x
|
175
|
+
should match(/input .*?name="crud_test_model\[rating\]"
|
176
|
+
.*?type="number"/x)
|
177
177
|
end
|
178
178
|
|
179
179
|
it do
|
180
|
-
should match
|
181
|
-
.*?type="number"/x
|
180
|
+
should match(/input .*?name="crud_test_model\[income\]"
|
181
|
+
.*?type="number"/x)
|
182
182
|
end
|
183
183
|
|
184
184
|
it do
|
185
|
-
should match
|
186
|
-
.*?type="date"/x
|
185
|
+
should match(/input .*?name="crud_test_model\[birthdate\]"
|
186
|
+
.*?type="date"/x)
|
187
187
|
end
|
188
188
|
|
189
189
|
it do
|
190
|
-
should match
|
191
|
-
.*?type="time"/x
|
190
|
+
should match(/input .*?name="crud_test_model\[gets_up_at\]"
|
191
|
+
.*?type="time"/x)
|
192
192
|
end
|
193
193
|
|
194
194
|
it do
|
195
|
-
should match
|
196
|
-
.*?type="datetime"/x
|
195
|
+
should match(/input .*?name="crud_test_model\[last_seen\]"
|
196
|
+
.*?type="datetime"/x)
|
197
197
|
end
|
198
198
|
|
199
199
|
it do
|
200
|
-
should match
|
201
|
-
.*?type="checkbox"/x
|
200
|
+
should match(/input .*?name="crud_test_model\[human\]"
|
201
|
+
.*?type="checkbox"/x)
|
202
202
|
end
|
203
203
|
|
204
204
|
it do
|
205
|
-
should match
|
205
|
+
should match(/select .*?name="crud_test_model\[companion_id\]"/)
|
206
206
|
end
|
207
207
|
|
208
208
|
it do
|
209
|
-
should match
|
209
|
+
should match(/textarea .*?name="crud_test_model\[remarks\]"/)
|
210
210
|
end
|
211
211
|
|
212
212
|
it do
|
@@ -29,9 +29,10 @@ describe FormatHelper do
|
|
29
29
|
subject { labeled('label') { 'value' } }
|
30
30
|
|
31
31
|
it { should be_html_safe }
|
32
|
-
|
33
|
-
should =~
|
34
|
-
|
32
|
+
it do
|
33
|
+
subject.squish.should =~
|
34
|
+
/^<dt>label<\/dt>
|
35
|
+
\ <dd\ class=['"]value['"]>value<\/dd>$/x
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -39,11 +40,12 @@ describe FormatHelper do
|
|
39
40
|
subject { labeled('label') { '' } }
|
40
41
|
|
41
42
|
it { should be_html_safe }
|
42
|
-
|
43
|
-
should =~
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
it do
|
44
|
+
subject.squish.should =~
|
45
|
+
/<dt>label<\/dt>
|
46
|
+
\ <dd\ class=['"]value['"]>
|
47
|
+
#{UtilityHelper::EMPTY_STRING}
|
48
|
+
<\/dd>$/x
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
@@ -51,11 +53,12 @@ describe FormatHelper do
|
|
51
53
|
subject { labeled('label') { 'value <unsafe>' } }
|
52
54
|
|
53
55
|
it { should be_html_safe }
|
54
|
-
|
55
|
-
should =~
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
it do
|
57
|
+
subject.squish.should =~
|
58
|
+
/<dt>label<\/dt>
|
59
|
+
\ <dd\ class=['"]value['"]>
|
60
|
+
value\ <unsafe>
|
61
|
+
<\/dd>$/x
|
59
62
|
end
|
60
63
|
end
|
61
64
|
end
|
@@ -64,9 +67,10 @@ describe FormatHelper do
|
|
64
67
|
subject { labeled_attr('foo', :size) }
|
65
68
|
|
66
69
|
it { should be_html_safe }
|
67
|
-
|
68
|
-
should =~
|
69
|
-
|
70
|
+
it do
|
71
|
+
subject.squish.should =~
|
72
|
+
/<dt>Size<\/dt>
|
73
|
+
\ <dd\ class=['"]value['"]>3\ chars<\/dd>$/x
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
@@ -83,7 +87,7 @@ describe FormatHelper do
|
|
83
87
|
end
|
84
88
|
|
85
89
|
it 'adds delimiters' do
|
86
|
-
f(
|
90
|
+
f(12_345.6789).should == '12,345.679'
|
87
91
|
end
|
88
92
|
end
|
89
93
|
|
@@ -107,7 +107,7 @@ shared_examples 'crud controller' do |options|
|
|
107
107
|
combine: 'ij' do
|
108
108
|
it_should_respond
|
109
109
|
it_should_assign_entries
|
110
|
-
|
110
|
+
it { response.body.should start_with('[{') }
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -145,7 +145,7 @@ shared_examples 'crud controller' do |options|
|
|
145
145
|
combine: 'sj' do
|
146
146
|
it_should_respond
|
147
147
|
it_should_assign_entry
|
148
|
-
|
148
|
+
it_should_render_json
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -208,7 +208,7 @@ shared_examples 'crud controller' do |options|
|
|
208
208
|
combine: 'cjv' do
|
209
209
|
it_should_respond(201)
|
210
210
|
it_should_set_attrs(:new)
|
211
|
-
|
211
|
+
it_should_render_json
|
212
212
|
end
|
213
213
|
|
214
214
|
context 'with invalid params',
|
@@ -217,7 +217,7 @@ shared_examples 'crud controller' do |options|
|
|
217
217
|
combine: 'cji' do
|
218
218
|
it_should_respond(422)
|
219
219
|
it_should_set_attrs(:new)
|
220
|
-
|
220
|
+
it_should_render_error_json
|
221
221
|
it_should_persist_entry(false)
|
222
222
|
end
|
223
223
|
end
|
@@ -272,7 +272,7 @@ shared_examples 'crud controller' do |options|
|
|
272
272
|
combine: 'ujv' do
|
273
273
|
it_should_respond(204)
|
274
274
|
it_should_set_attrs(:edit)
|
275
|
-
|
275
|
+
it { response.body.should be_blank }
|
276
276
|
it_should_persist_entry
|
277
277
|
end
|
278
278
|
|
@@ -282,7 +282,7 @@ shared_examples 'crud controller' do |options|
|
|
282
282
|
combine: 'uji' do
|
283
283
|
it_should_respond(422)
|
284
284
|
it_should_set_attrs(:edit)
|
285
|
-
|
285
|
+
it_should_render_error_json
|
286
286
|
end
|
287
287
|
end
|
288
288
|
end
|
@@ -316,12 +316,12 @@ shared_examples 'crud controller' do |options|
|
|
316
316
|
|
317
317
|
context 'successfull', combine: 'djs' do
|
318
318
|
it_should_respond(204)
|
319
|
-
|
319
|
+
it { response.body.should be_blank }
|
320
320
|
end
|
321
321
|
|
322
322
|
context 'with failure', failing: true, combine: 'djf' do
|
323
323
|
it_should_respond(422)
|
324
|
-
|
324
|
+
it_should_render_error_json
|
325
325
|
end
|
326
326
|
end
|
327
327
|
end
|
@@ -89,7 +89,7 @@ module CrudControllerTestHelper
|
|
89
89
|
|
90
90
|
# Test the response status, default 200.
|
91
91
|
def it_should_respond(status = 200)
|
92
|
-
|
92
|
+
it { response.status.should == status }
|
93
93
|
end
|
94
94
|
|
95
95
|
# Test that entries are assigned.
|
@@ -112,6 +112,16 @@ module CrudControllerTestHelper
|
|
112
112
|
it { should render_template(template || example.metadata[:action]) }
|
113
113
|
end
|
114
114
|
|
115
|
+
# Test that a json response is rendered.
|
116
|
+
def it_should_render_json
|
117
|
+
it { response.body.should start_with('{') }
|
118
|
+
end
|
119
|
+
|
120
|
+
# Test that a json response containing the error is rendered.
|
121
|
+
def it_should_render_error_json
|
122
|
+
it { response.body.should match(/"errors":\{/) }
|
123
|
+
end
|
124
|
+
|
115
125
|
# Test that test_entry_attrs are set on entry.
|
116
126
|
def it_should_set_attrs(action = nil)
|
117
127
|
it 'should set params as entry attributes' do
|
@@ -149,7 +149,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
149
149
|
|
150
150
|
def test_create
|
151
151
|
super
|
152
|
-
assert_match
|
152
|
+
assert_match(/model got created/, flash[:notice])
|
153
153
|
assert flash[:alert].blank?
|
154
154
|
assert_equal [:before_create, :before_save, :after_save, :after_create],
|
155
155
|
@controller.called_callbacks
|
@@ -234,7 +234,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
234
234
|
end
|
235
235
|
assert_response :unprocessable_entity
|
236
236
|
assert entry.new_record?
|
237
|
-
assert_match
|
237
|
+
assert_match(/errors/, @response.body)
|
238
238
|
assert_equal [:before_create, :before_save], @controller.called_callbacks
|
239
239
|
end
|
240
240
|
|
@@ -257,7 +257,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
257
257
|
format: 'json'
|
258
258
|
assert_response :unprocessable_entity
|
259
259
|
assert entry.changed?
|
260
|
-
assert_match
|
260
|
+
assert_match(/errors/, @response.body)
|
261
261
|
assert flash[:notice].blank?
|
262
262
|
assert_equal 20, entry.rating
|
263
263
|
assert_equal [:before_update, :before_save], @controller.called_callbacks
|
@@ -270,7 +270,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
270
270
|
delete :destroy, test_params(id: crud_test_models(:BBBBB).id)
|
271
271
|
end
|
272
272
|
assert_redirected_to_show(entry)
|
273
|
-
assert_match
|
273
|
+
assert_match(/companion/, flash[:alert])
|
274
274
|
assert flash[:notice].blank?
|
275
275
|
end
|
276
276
|
|
@@ -281,7 +281,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
281
281
|
delete :destroy, test_params(id: e.id)
|
282
282
|
end
|
283
283
|
assert_redirected_to_index
|
284
|
-
assert_match
|
284
|
+
assert_match(/illegal name/, flash[:alert])
|
285
285
|
assert flash[:notice].blank?
|
286
286
|
end
|
287
287
|
|
@@ -291,7 +291,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
291
291
|
format: 'json')
|
292
292
|
end
|
293
293
|
assert_response :unprocessable_entity
|
294
|
-
assert_match
|
294
|
+
assert_match(/errors/, @response.body)
|
295
295
|
assert flash[:notice].blank?
|
296
296
|
end
|
297
297
|
|
@@ -2,251 +2,256 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
require 'support/crud_test_model'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
5
|
+
module DryCrud
|
6
|
+
module Form
|
7
|
+
# Test DryCrud::Form::Builder
|
8
|
+
class BuilderTest < ActionView::TestCase
|
9
|
+
|
10
|
+
include FormatHelper
|
11
|
+
include I18nHelper
|
12
|
+
include CrudTestHelper
|
13
|
+
|
14
|
+
# set dummy helper class for ActionView::TestCase
|
15
|
+
self.helper_class = UtilityHelper
|
16
|
+
|
17
|
+
attr_reader :form, :entry
|
18
|
+
|
19
|
+
setup :reset_db, :setup_db, :create_test_data, :create_form
|
20
|
+
teardown :reset_db
|
21
|
+
|
22
|
+
def create_form
|
23
|
+
@entry = CrudTestModel.first
|
24
|
+
if Rails.version < '4.0'
|
25
|
+
@form = DryCrud::Form::Builder.new(:entry, @entry, self, {},
|
26
|
+
->(form) { form })
|
27
|
+
else
|
28
|
+
@form = DryCrud::Form::Builder.new(:entry, @entry, self, {})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'input_field dispatches string attr to string_field' do
|
33
|
+
assert_equal form.with_addon(
|
34
|
+
form.string_field(:name,
|
35
|
+
required: 'required'),
|
36
|
+
'*'),
|
37
|
+
form.input_field(:name)
|
38
|
+
assert form.string_field(:name).html_safe?
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'input_field dispatches password attr to password_field' do
|
42
|
+
assert_equal form.password_field(:password),
|
43
|
+
form.input_field(:password)
|
44
|
+
assert form.password_field(:name).html_safe?
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'input_field dispatches email attr to email_field' do
|
48
|
+
assert_equal form.email_field(:email),
|
49
|
+
form.input_field(:email)
|
50
|
+
assert form.email_field(:name).html_safe?
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'input_field dispatches text attr to text_area' do
|
54
|
+
assert_equal form.text_area(:remarks),
|
55
|
+
form.input_field(:remarks)
|
56
|
+
assert form.text_area(:remarks).html_safe?
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'input_field dispatches integer attr to integer_field' do
|
60
|
+
assert_equal form.integer_field(:children),
|
61
|
+
form.input_field(:children)
|
62
|
+
assert form.integer_field(:children).html_safe?
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'input_field dispatches boolean attr to boolean_field' do
|
66
|
+
assert_equal form.boolean_field(:human),
|
67
|
+
form.input_field(:human)
|
68
|
+
assert form.boolean_field(:human).html_safe?
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'input_field dispatches date attr to date_field' do
|
72
|
+
assert_equal form.date_field(:birthdate),
|
73
|
+
form.input_field(:birthdate)
|
74
|
+
assert form.date_field(:birthdate).html_safe?
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'input_field dispatches belongs_to attr to select field' do
|
78
|
+
assert_equal form.belongs_to_field(:companion_id),
|
79
|
+
form.input_field(:companion_id)
|
80
|
+
assert form.belongs_to_field(:companion_id).html_safe?
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'input_field dispatches has_and_belongs_to_many attr to ' \
|
84
|
+
'select field' do
|
85
|
+
assert_equal form.has_many_field(:other_ids),
|
86
|
+
form.input_field(:other_ids)
|
87
|
+
assert form.has_many_field(:other_ids).html_safe?
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'input_field dispatches has_many attr to select field' do
|
91
|
+
assert_equal form.has_many_field(:more_ids),
|
92
|
+
form.input_field(:more_ids)
|
93
|
+
assert form.has_many_field(:more_ids).html_safe?
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'input_fields concats multiple fields' do
|
97
|
+
result = form.labeled_input_fields(:name, :remarks, :children)
|
98
|
+
assert result.html_safe?
|
99
|
+
assert result.include?(form.input_field(:name, required: 'required'))
|
100
|
+
assert result.include?(form.input_field(:remarks))
|
101
|
+
assert result.include?(form.input_field(:children))
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'labeld_input_field adds required mark' do
|
105
|
+
result = form.labeled_input_field(:name)
|
106
|
+
assert result.include?('input-group-addon')
|
107
|
+
result = form.labeled_input_field(:remarks)
|
108
|
+
assert !result.include?('input-group-addon')
|
109
|
+
end
|
110
|
+
|
111
|
+
test 'labeld_input_field adds help text' do
|
112
|
+
result = form.labeled_input_field(:name, help: 'Some Help')
|
113
|
+
assert result.include?(form.help_block('Some Help'))
|
114
|
+
assert result.include?('input-group-addon')
|
115
|
+
end
|
116
|
+
|
117
|
+
test 'belongs_to_field has all options by default' do
|
118
|
+
f = form.belongs_to_field(:companion_id)
|
119
|
+
assert_equal 7, f.scan('</option>').size
|
120
|
+
end
|
121
|
+
|
122
|
+
test 'belongs_to_field with :list option' do
|
123
|
+
list = CrudTestModel.all
|
124
|
+
f = form.belongs_to_field(:companion_id,
|
125
|
+
list: [list.first, list.second])
|
126
|
+
assert_equal 3, f.scan('</option>').size
|
127
|
+
end
|
128
|
+
|
129
|
+
test 'belongs_to_field with instance variable' do
|
130
|
+
list = CrudTestModel.all
|
131
|
+
@companions = [list.first, list.second]
|
132
|
+
f = form.belongs_to_field(:companion_id)
|
133
|
+
assert_equal 3, f.scan('</option>').size
|
134
|
+
end
|
135
|
+
|
136
|
+
test 'belongs_to_field with empty list' do
|
137
|
+
@companions = []
|
138
|
+
f = form.belongs_to_field(:companion_id)
|
139
|
+
assert_match t('global.associations.none_available'), f
|
140
|
+
assert_equal 0, f.scan('</option>').size
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'has_and_belongs_to_many_field has all options by default' do
|
144
|
+
f = form.has_many_field(:other_ids)
|
145
|
+
assert_equal 6, f.scan('</option>').size
|
146
|
+
end
|
147
|
+
|
148
|
+
test 'has_and_belongs_to_many_field with :list option' do
|
149
|
+
list = OtherCrudTestModel.all
|
150
|
+
f = form.has_many_field(:other_ids, list: [list.first, list.second])
|
151
|
+
assert_equal 2, f.scan('</option>').size
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'has_and_belongs_to_many_field with instance variable' do
|
155
|
+
list = OtherCrudTestModel.all
|
156
|
+
@others = [list.first, list.second]
|
157
|
+
f = form.has_many_field(:other_ids)
|
158
|
+
assert_equal 2, f.scan('</option>').size
|
159
|
+
end
|
160
|
+
|
161
|
+
test 'has_and_belongs_to_many_field with empty list' do
|
162
|
+
@others = []
|
163
|
+
f = form.has_many_field(:other_ids)
|
164
|
+
assert_match t('global.associations.none_available'), f
|
165
|
+
assert_equal 0, f.scan('</option>').size
|
166
|
+
end
|
167
|
+
|
168
|
+
test 'has_many_field has all options by default' do
|
169
|
+
f = form.has_many_field(:more_ids)
|
170
|
+
assert_equal 6, f.scan('</option>').size
|
171
|
+
end
|
172
|
+
|
173
|
+
test 'has_many_field with :list option' do
|
174
|
+
list = OtherCrudTestModel.all
|
175
|
+
f = form.has_many_field(:more_ids, list: [list.first, list.second])
|
176
|
+
assert_equal 2, f.scan('</option>').size
|
177
|
+
end
|
178
|
+
|
179
|
+
test 'has_many_field with instance variable' do
|
180
|
+
list = OtherCrudTestModel.all
|
181
|
+
@mores = [list.first, list.second]
|
182
|
+
f = form.has_many_field(:more_ids)
|
183
|
+
assert_equal 2, f.scan('</option>').size
|
184
|
+
end
|
185
|
+
|
186
|
+
test 'has_many_field with empty list' do
|
187
|
+
@mores = []
|
188
|
+
f = form.has_many_field(:more_ids)
|
189
|
+
assert_match t('global.associations.none_available'), f
|
190
|
+
assert_equal 0, f.scan('</option>').size
|
191
|
+
end
|
192
|
+
|
193
|
+
test 'string_field sets maxlength attribute if limit' do
|
194
|
+
assert_match(/maxlength="50"/, form.string_field(:name))
|
195
|
+
end
|
196
|
+
|
197
|
+
test 'label creates captionized label' do
|
198
|
+
assert_match(/label [^>]*for.+Gugus dada/, form.label(:gugus_dada))
|
199
|
+
assert form.label(:gugus_dada).html_safe?
|
200
|
+
end
|
201
|
+
|
202
|
+
test 'classic label still works' do
|
203
|
+
assert_match(/label [^>]*for.+hoho/, form.label(:gugus_dada, 'hoho'))
|
204
|
+
assert form.label(:gugus_dada, 'hoho').html_safe?
|
205
|
+
end
|
206
|
+
|
207
|
+
test 'labeled_text_field create label' do
|
208
|
+
assert_match(/label [^>]*for.+input/m,
|
209
|
+
form.labeled_string_field(:name))
|
210
|
+
assert form.labeled_string_field(:name).html_safe?
|
211
|
+
end
|
212
|
+
|
213
|
+
test 'labeled field creates label' do
|
214
|
+
result = form.labeled('gugus',
|
215
|
+
"<input type='text' name='gugus' />".html_safe)
|
216
|
+
assert result.html_safe?
|
217
|
+
assert_match(/label [^>]*for.+<input/m, result)
|
218
|
+
end
|
219
|
+
|
220
|
+
test 'labeled field creates label and block' do
|
221
|
+
result = form.labeled('gugus') do
|
222
|
+
"<input type='text' name='gugus' />".html_safe
|
223
|
+
end
|
224
|
+
assert result.html_safe?
|
225
|
+
assert_match(/label [^>]*for.+<input/m, result)
|
226
|
+
end
|
227
|
+
|
228
|
+
test 'labeled field creates label with caption' do
|
229
|
+
result = form.labeled('gugus',
|
230
|
+
"<input type='text' name='gugus' />".html_safe,
|
231
|
+
caption: 'Caption')
|
232
|
+
assert result.html_safe?
|
233
|
+
assert_match(/label [^>]*for.+>Caption<\/label>.*<input/m, result)
|
234
|
+
end
|
235
|
+
|
236
|
+
test 'labeled field creates label with caption and block' do
|
237
|
+
result = form.labeled('gugus', caption: 'Caption') do
|
238
|
+
"<input type='text' name='gugus' />".html_safe
|
239
|
+
end
|
240
|
+
assert result.html_safe?
|
241
|
+
assert_match(/label [^>]*for.+>Caption<\/label>.*<input/m, result)
|
242
|
+
end
|
243
|
+
|
244
|
+
test 'method missing still works' do
|
245
|
+
assert_raise(NoMethodError) do
|
246
|
+
form.blabla
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
test 'respond to still works' do
|
251
|
+
assert !form.respond_to?(:blalba)
|
252
|
+
assert form.respond_to?(:text_field)
|
253
|
+
assert form.respond_to?(:labeled_text_field)
|
254
|
+
end
|
220
255
|
end
|
221
|
-
assert result.html_safe?
|
222
|
-
assert_match /label [^>]*for.+<input/m, result
|
223
|
-
end
|
224
|
-
|
225
|
-
test 'labeled field creates label with caption' do
|
226
|
-
result = form.labeled('gugus',
|
227
|
-
"<input type='text' name='gugus' />".html_safe,
|
228
|
-
caption: 'Caption')
|
229
|
-
assert result.html_safe?
|
230
|
-
assert_match /label [^>]*for.+>Caption<\/label>.*<input/m, result
|
231
|
-
end
|
232
|
-
|
233
|
-
test 'labeled field creates label with caption and block' do
|
234
|
-
result = form.labeled('gugus', caption: 'Caption') do
|
235
|
-
"<input type='text' name='gugus' />".html_safe
|
236
|
-
end
|
237
|
-
assert result.html_safe?
|
238
|
-
assert_match /label [^>]*for.+>Caption<\/label>.*<input/m, result
|
239
|
-
end
|
240
|
-
|
241
|
-
test 'method missing still works' do
|
242
|
-
assert_raise(NoMethodError) do
|
243
|
-
form.blabla
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
test 'respond to still works' do
|
248
|
-
assert !form.respond_to?(:blalba)
|
249
|
-
assert form.respond_to?(:text_field)
|
250
|
-
assert form.respond_to?(:labeled_text_field)
|
251
256
|
end
|
252
257
|
end
|