dry_crud 2.1.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.rdoc +1 -2
- data/VERSION +1 -1
- data/app/controllers/crud_controller.rb +96 -61
- data/app/controllers/dry_crud/generic_model.rb +1 -5
- data/app/controllers/dry_crud/rememberable.rb +1 -1
- data/app/controllers/dry_crud/render_callbacks.rb +2 -4
- data/app/controllers/list_controller.rb +4 -5
- data/app/helpers/dry_crud/form/builder.rb +4 -30
- data/app/helpers/format_helper.rb +2 -0
- data/app/helpers/utility_helper.rb +2 -3
- data/app/views/crud/show.json.jbuilder +1 -0
- data/app/views/layouts/_flash.html.erb +1 -1
- data/app/views/layouts/_flash.html.haml +1 -1
- data/app/views/list/index.json.jbuilder +4 -0
- data/config/locales/crud.de.yml +1 -1
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +141 -139
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +47 -48
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +6 -6
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +66 -66
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +62 -61
- data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +13 -13
- data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +42 -38
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +22 -22
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +72 -72
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +54 -45
- data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +8 -11
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +1 -6
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +47 -46
- data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +1 -1
- data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +9 -3
- data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +2 -2
- data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +1 -1
- data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +0 -4
- data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +5 -10
- metadata +15 -18
- data/app/controllers/dry_crud/responder.rb +0 -34
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require '
|
2
|
+
require 'rails_helper'
|
3
3
|
|
4
4
|
describe 'DryCrud::Form::Builder' do
|
5
5
|
|
@@ -18,24 +18,18 @@ describe 'DryCrud::Form::Builder' do
|
|
18
18
|
after(:all) { reset_db }
|
19
19
|
|
20
20
|
let(:entry) { CrudTestModel.first }
|
21
|
-
|
22
|
-
let(:form) do
|
23
|
-
DryCrud::Form::Builder.new(:entry, entry, self, {}, ->(form) { form })
|
24
|
-
end
|
25
|
-
else
|
26
|
-
let(:form) { DryCrud::Form::Builder.new(:entry, entry, self, {}) }
|
27
|
-
end
|
21
|
+
let(:form) { DryCrud::Form::Builder.new(:entry, entry, self, {}) }
|
28
22
|
|
29
23
|
describe '#input_field' do
|
30
24
|
|
31
25
|
it 'dispatches name attr to string field' do
|
32
|
-
form.
|
33
|
-
|
34
|
-
|
26
|
+
expect(form).to receive(:string_field)
|
27
|
+
.with(:name, required: 'required')
|
28
|
+
.and_return('<input>')
|
35
29
|
form.input_field(:name)
|
36
30
|
end
|
37
31
|
|
38
|
-
it { form.input_field(:name).
|
32
|
+
it { expect(form.input_field(:name)).to be_html_safe }
|
39
33
|
|
40
34
|
{ password: :password_field,
|
41
35
|
email: :email_field,
|
@@ -50,11 +44,11 @@ describe 'DryCrud::Form::Builder' do
|
|
50
44
|
more_ids: :has_many_field
|
51
45
|
}.each do |attr, method|
|
52
46
|
it 'dispatches #{attr} attr to #{method}' do
|
53
|
-
form.
|
47
|
+
expect(form).to receive(method).with(attr, {})
|
54
48
|
form.input_field(attr)
|
55
49
|
end
|
56
50
|
|
57
|
-
it { form.input_field(attr).
|
51
|
+
it { expect(form.input_field(attr)).to be_html_safe }
|
58
52
|
end
|
59
53
|
|
60
54
|
end
|
@@ -62,48 +56,48 @@ describe 'DryCrud::Form::Builder' do
|
|
62
56
|
describe '#labeled_input_fields' do
|
63
57
|
subject { form.labeled_input_fields(:name, :remarks, :children) }
|
64
58
|
|
65
|
-
it {
|
66
|
-
it {
|
67
|
-
it {
|
68
|
-
it {
|
59
|
+
it { is_expected.to be_html_safe }
|
60
|
+
it { is_expected.to include(form.input_field(:name, required: 'required')) }
|
61
|
+
it { is_expected.to include(form.input_field(:remarks)) }
|
62
|
+
it { is_expected.to include(form.input_field(:children)) }
|
69
63
|
end
|
70
64
|
|
71
65
|
describe '#labeled_input_field' do
|
72
66
|
context 'when required' do
|
73
67
|
subject { form.labeled_input_field(:name) }
|
74
|
-
it {
|
68
|
+
it { is_expected.to include('input-group-addon') }
|
75
69
|
end
|
76
70
|
|
77
71
|
context 'when not required' do
|
78
72
|
subject { form.labeled_input_field(:remarks) }
|
79
|
-
it {
|
73
|
+
it { is_expected.not_to include('input-group-addon') }
|
80
74
|
end
|
81
75
|
|
82
76
|
context 'with help text' do
|
83
77
|
subject { form.labeled_input_field(:name, help: 'Some Help') }
|
84
|
-
it {
|
78
|
+
it { is_expected.to include(form.help_block('Some Help')) }
|
85
79
|
end
|
86
80
|
end
|
87
81
|
|
88
82
|
describe '#belongs_to_field' do
|
89
83
|
it 'has all options by default' do
|
90
84
|
f = form.belongs_to_field(:companion_id)
|
91
|
-
f
|
85
|
+
expect_n_options(f, 7)
|
92
86
|
end
|
93
87
|
|
94
88
|
it 'with has options from :list option' do
|
95
89
|
list = CrudTestModel.all
|
96
90
|
f = form.belongs_to_field(:companion_id,
|
97
91
|
list: [list.first, list.second])
|
98
|
-
f
|
92
|
+
expect_n_options(f, 3)
|
99
93
|
end
|
100
94
|
|
101
95
|
it 'with empty instance list has no select' do
|
102
96
|
assign(:companions, [])
|
103
97
|
@companions = []
|
104
98
|
f = form.belongs_to_field(:companion_id)
|
105
|
-
f.
|
106
|
-
f
|
99
|
+
expect(f).to match t('global.associations.none_available')
|
100
|
+
expect_n_options(f, 0)
|
107
101
|
end
|
108
102
|
end
|
109
103
|
|
@@ -112,32 +106,32 @@ describe 'DryCrud::Form::Builder' do
|
|
112
106
|
|
113
107
|
it 'has all options by default' do
|
114
108
|
f = form.has_many_field(:other_ids)
|
115
|
-
f
|
109
|
+
expect_n_options(f, 6)
|
116
110
|
end
|
117
111
|
|
118
112
|
it 'uses options from :list option if given' do
|
119
113
|
f = form.has_many_field(:other_ids, list: others)
|
120
|
-
f
|
114
|
+
expect_n_options(f, 2)
|
121
115
|
end
|
122
116
|
|
123
117
|
it 'uses options form instance variable if given' do
|
124
118
|
assign(:others, others)
|
125
119
|
@others = others
|
126
120
|
f = form.has_many_field(:other_ids)
|
127
|
-
f
|
121
|
+
expect_n_options(f, 2)
|
128
122
|
end
|
129
123
|
|
130
124
|
it 'displays a message for an empty list' do
|
131
125
|
@others = []
|
132
126
|
f = form.has_many_field(:other_ids)
|
133
|
-
f.
|
134
|
-
f
|
127
|
+
expect(f).to match t('global.associations.none_available')
|
128
|
+
expect_n_options(f, 0)
|
135
129
|
end
|
136
130
|
end
|
137
131
|
|
138
132
|
describe '#string_field' do
|
139
133
|
it 'sets maxlength if attr has a limit' do
|
140
|
-
form.string_field(:name).
|
134
|
+
expect(form.string_field(:name)).to match(/maxlength="50"/)
|
141
135
|
end
|
142
136
|
end
|
143
137
|
|
@@ -145,18 +139,18 @@ describe 'DryCrud::Form::Builder' do
|
|
145
139
|
context 'only with attr' do
|
146
140
|
subject { form.label(:gugus_dada) }
|
147
141
|
|
148
|
-
it {
|
142
|
+
it { is_expected.to be_html_safe }
|
149
143
|
it 'provides the same interface as rails' do
|
150
|
-
|
144
|
+
is_expected.to match(/label [^>]*for.+Gugus dada/)
|
151
145
|
end
|
152
146
|
end
|
153
147
|
|
154
148
|
context 'with attr and text' do
|
155
149
|
subject { form.label(:gugus_dada, 'hoho') }
|
156
150
|
|
157
|
-
it {
|
151
|
+
it { is_expected.to be_html_safe }
|
158
152
|
it 'provides the same interface as rails' do
|
159
|
-
|
153
|
+
is_expected.to match(/label [^>]*for.+hoho/)
|
160
154
|
end
|
161
155
|
end
|
162
156
|
|
@@ -166,9 +160,9 @@ describe 'DryCrud::Form::Builder' do
|
|
166
160
|
context 'in labeled_ method' do
|
167
161
|
subject { form.labeled_string_field(:name) }
|
168
162
|
|
169
|
-
it {
|
163
|
+
it { is_expected.to be_html_safe }
|
170
164
|
it 'provides the same interface as rails' do
|
171
|
-
|
165
|
+
is_expected.to match(/label [^>]*for.+input/m)
|
172
166
|
end
|
173
167
|
end
|
174
168
|
|
@@ -177,8 +171,8 @@ describe 'DryCrud::Form::Builder' do
|
|
177
171
|
form.labeled('gugus', "<input type='text' name='gugus' />".html_safe)
|
178
172
|
end
|
179
173
|
|
180
|
-
it {
|
181
|
-
it {
|
174
|
+
it { is_expected.to be_html_safe }
|
175
|
+
it { is_expected.to match(/label [^>]*for.+<input/m) }
|
182
176
|
end
|
183
177
|
|
184
178
|
context 'with custom content in block' do
|
@@ -188,8 +182,8 @@ describe 'DryCrud::Form::Builder' do
|
|
188
182
|
end
|
189
183
|
end
|
190
184
|
|
191
|
-
it {
|
192
|
-
it {
|
185
|
+
it { is_expected.to be_html_safe }
|
186
|
+
it { is_expected.to match(/label [^>]*for.+<input/m) }
|
193
187
|
end
|
194
188
|
|
195
189
|
context 'with caption and content in argument' do
|
@@ -199,8 +193,8 @@ describe 'DryCrud::Form::Builder' do
|
|
199
193
|
caption: 'Caption')
|
200
194
|
end
|
201
195
|
|
202
|
-
it {
|
203
|
-
it {
|
196
|
+
it { is_expected.to be_html_safe }
|
197
|
+
it { is_expected.to match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
|
204
198
|
end
|
205
199
|
|
206
200
|
context 'with caption and content in block' do
|
@@ -210,8 +204,8 @@ describe 'DryCrud::Form::Builder' do
|
|
210
204
|
end
|
211
205
|
end
|
212
206
|
|
213
|
-
it {
|
214
|
-
it {
|
207
|
+
it { is_expected.to be_html_safe }
|
208
|
+
it { is_expected.to match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
|
215
209
|
end
|
216
210
|
end
|
217
211
|
|
@@ -221,15 +215,20 @@ describe 'DryCrud::Form::Builder' do
|
|
221
215
|
|
222
216
|
context '#respond_to?' do
|
223
217
|
it 'returns false for non existing methods' do
|
224
|
-
form.respond_to?(:blabla).
|
218
|
+
expect(form.respond_to?(:blabla)).to be false
|
225
219
|
end
|
226
220
|
|
227
221
|
it 'returns true for existing methods' do
|
228
|
-
form.respond_to?(:text_field).
|
222
|
+
expect(form.respond_to?(:text_field)).to be true
|
229
223
|
end
|
230
224
|
|
231
225
|
it 'returns true for labeled_ methods' do
|
232
|
-
form.respond_to?(:labeled_text_field).
|
226
|
+
expect(form.respond_to?(:labeled_text_field)).to be true
|
233
227
|
end
|
234
228
|
end
|
229
|
+
|
230
|
+
def expect_n_options(f, n)
|
231
|
+
expect(f.scan('</option>').size).to eq(n)
|
232
|
+
end
|
233
|
+
|
235
234
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require '
|
2
|
+
require 'rails_helper'
|
3
3
|
|
4
|
-
describe 'DryCrud::
|
4
|
+
describe 'DryCrud::Table::Builder' do
|
5
5
|
|
6
6
|
include FormatHelper
|
7
7
|
include UtilityHelper
|
@@ -37,15 +37,15 @@ describe 'DryCrud::TableBuilder' do
|
|
37
37
|
context 'output' do
|
38
38
|
before { table.attrs :upcase }
|
39
39
|
|
40
|
-
it { col.html_header.
|
41
|
-
it { col.content('foo').
|
42
|
-
it { col.html_cell('foo').
|
40
|
+
it { expect(col.html_header).to eq('<th>Upcase</th>') }
|
41
|
+
it { expect(col.content('foo')).to eq('FOO') }
|
42
|
+
it { expect(col.html_cell('foo')).to eq('<td>FOO</td>') }
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'content with custom format_size method' do
|
46
46
|
before { table.attrs :size }
|
47
47
|
|
48
|
-
it { col.content('abcd').
|
48
|
+
it { expect(col.content('abcd')).to eq('4 chars') }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require '
|
2
|
+
require 'rails_helper'
|
3
3
|
|
4
4
|
describe FormHelper do
|
5
5
|
|
@@ -31,27 +31,27 @@ describe FormHelper do
|
|
31
31
|
let(:entry) { crud_test_models(:AAAAA) }
|
32
32
|
|
33
33
|
it do
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
is_expected.to match(/form .*?class="special\ form-horizontal"
|
35
|
+
.*?action="\/crud_test_models\/#{entry.id}"
|
36
|
+
.*?method="post"/x)
|
37
37
|
end
|
38
38
|
|
39
39
|
it do
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
is_expected.to match(/input .*?type="hidden"
|
41
|
+
.*?name="_method"
|
42
|
+
.*?value="(put|patch)"/x)
|
43
43
|
end
|
44
44
|
|
45
45
|
it do
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
is_expected.to match(/input .*?type="text"
|
47
|
+
.*?value="AAAAA"
|
48
|
+
.*?name="crud_test_model\[name\]"/x)
|
49
49
|
end
|
50
50
|
|
51
51
|
it do
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
is_expected.to match(/input .*?value="1910-01-01"
|
53
|
+
.*?type="date"
|
54
|
+
.*?name="crud_test_model\[birthdate\]"/x)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -73,50 +73,50 @@ describe FormHelper do
|
|
73
73
|
let(:entry) { crud_test_models(:AAAAA) }
|
74
74
|
|
75
75
|
it do
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
is_expected.to match(/form .*?class="special\ form-horizontal"
|
77
|
+
.*?action="\/crud_test_models\/#{entry.id}"
|
78
|
+
.*?method="post"/x)
|
79
79
|
end
|
80
80
|
|
81
81
|
it do
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
is_expected.to match(/input .*?type="hidden"
|
83
|
+
.*?name="_method"
|
84
|
+
.*?value="(put|patch)"/x)
|
85
85
|
end
|
86
86
|
|
87
87
|
it do
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
is_expected.to match(/input .*?type="text"
|
89
|
+
.*?value="AAAAA"
|
90
|
+
.*?name="crud_test_model\[name\]"/x)
|
91
91
|
end
|
92
92
|
|
93
93
|
it do
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
is_expected.to match(/input .*?value="1910-01-01"
|
95
|
+
.*?type="date"
|
96
|
+
.*?name="crud_test_model\[birthdate\]"/x)
|
97
97
|
end
|
98
98
|
|
99
99
|
it do
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
is_expected.to match(/input .*?type="number"
|
101
|
+
.*?value=\"9\"
|
102
|
+
.*?name="crud_test_model\[children\]"/x)
|
103
103
|
end
|
104
104
|
|
105
105
|
it do
|
106
|
-
|
107
|
-
|
106
|
+
is_expected.to match(/input .*?type="checkbox"
|
107
|
+
.*?name="crud_test_model\[human\]"/x)
|
108
108
|
end
|
109
109
|
|
110
110
|
it do
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
is_expected.to match(/button\ .*?type="submit".*>
|
112
|
+
#{t('global.button.save')}
|
113
|
+
<\/button>/x)
|
114
114
|
end
|
115
115
|
|
116
116
|
it do
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
is_expected.to match(/a\ .*href="\/somewhere".*>
|
118
|
+
#{t('global.button.cancel')}
|
119
|
+
<\/a>/x)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -129,19 +129,19 @@ describe FormHelper do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it do
|
132
|
-
|
132
|
+
is_expected.to match(/div[^>]* id='error_explanation'/)
|
133
133
|
end
|
134
134
|
|
135
135
|
it do
|
136
|
-
|
137
|
-
|
138
|
-
|
136
|
+
is_expected.to match(/div\ class="form-group\ has-error"\>.*?
|
137
|
+
\<input .*?type="text"
|
138
|
+
.*?name="crud_test_model\[name\]"/x)
|
139
139
|
end
|
140
140
|
|
141
141
|
it do
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
is_expected.to match(/input .*?type="hidden"
|
143
|
+
.*?name="_method"
|
144
|
+
.*?value="(put|patch)"/x)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
@@ -153,66 +153,66 @@ describe FormHelper do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
it do
|
156
|
-
|
156
|
+
is_expected.to match(/form .*?action="\/crud_test_models\/#{entry.id}"/)
|
157
157
|
end
|
158
158
|
|
159
159
|
it do
|
160
|
-
|
161
|
-
|
160
|
+
is_expected.to match(/input .*?type="text"
|
161
|
+
.*?name="crud_test_model\[name\]"/x)
|
162
162
|
end
|
163
163
|
|
164
164
|
it do
|
165
|
-
|
166
|
-
|
165
|
+
is_expected.to match(/input .*?type="text"
|
166
|
+
.*?name="crud_test_model\[whatever\]"/x)
|
167
167
|
end
|
168
168
|
|
169
169
|
it do
|
170
|
-
|
171
|
-
|
170
|
+
is_expected.to match(/input .*?type="number"
|
171
|
+
.*?name="crud_test_model\[children\]"/x)
|
172
172
|
end
|
173
173
|
|
174
174
|
it do
|
175
|
-
|
176
|
-
|
175
|
+
is_expected.to match(/input .*?type="number"
|
176
|
+
.*?name="crud_test_model\[rating\]"/x)
|
177
177
|
end
|
178
178
|
|
179
179
|
it do
|
180
|
-
|
181
|
-
|
180
|
+
is_expected.to match(/input .*?type="number"
|
181
|
+
.*?name="crud_test_model\[income\]"/x)
|
182
182
|
end
|
183
183
|
|
184
184
|
it do
|
185
|
-
|
186
|
-
|
185
|
+
is_expected.to match(/input .*?type="date"
|
186
|
+
.*?name="crud_test_model\[birthdate\]"/x)
|
187
187
|
end
|
188
188
|
|
189
189
|
it do
|
190
|
-
|
191
|
-
|
190
|
+
is_expected.to match(/input .*?type="time"
|
191
|
+
.*?name="crud_test_model\[gets_up_at\]"/x)
|
192
192
|
end
|
193
193
|
|
194
194
|
it do
|
195
|
-
|
196
|
-
|
195
|
+
is_expected.to match(/input .*?type="datetime"
|
196
|
+
.*?name="crud_test_model\[last_seen\]"/x)
|
197
197
|
end
|
198
198
|
|
199
199
|
it do
|
200
|
-
|
201
|
-
|
200
|
+
is_expected.to match(/input .*?type="checkbox"
|
201
|
+
.*?name="crud_test_model\[human\]"/x)
|
202
202
|
end
|
203
203
|
|
204
204
|
it do
|
205
|
-
|
205
|
+
is_expected.to match(/select .*?name="crud_test_model\[companion_id\]"/)
|
206
206
|
end
|
207
207
|
|
208
208
|
it do
|
209
|
-
|
209
|
+
is_expected.to match(/textarea .*?name="crud_test_model\[remarks\]"/)
|
210
210
|
end
|
211
211
|
|
212
212
|
it do
|
213
|
-
|
213
|
+
is_expected.to match(/a\ .*href="\/crud_test_models\/#{entry.id}
|
214
214
|
\?returning=true".*>
|
215
|
-
|
215
|
+
#{t('global.button.cancel')}<\/a>/x)
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|