dry_crud 7.1.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/VERSION +1 -1
- data/app/controllers/crud_controller.rb +5 -7
- data/app/controllers/dry_crud/generic_model.rb +4 -8
- 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 +2 -10
- data/app/controllers/dry_crud/searchable.rb +3 -10
- data/app/controllers/dry_crud/sortable.rb +3 -10
- data/app/controllers/list_controller.rb +0 -2
- data/app/helpers/actions_helper.rb +8 -10
- data/app/helpers/dry_crud/form/builder.rb +23 -26
- data/app/helpers/dry_crud/form/control.rb +7 -11
- data/app/helpers/dry_crud/table/actions.rb +8 -13
- data/app/helpers/dry_crud/table/builder.rb +3 -6
- data/app/helpers/dry_crud/table/col.rb +1 -4
- data/app/helpers/dry_crud/table/sorting.rb +3 -6
- data/app/helpers/form_helper.rb +5 -7
- data/app/helpers/format_helper.rb +11 -13
- data/app/helpers/i18n_helper.rb +8 -10
- data/app/helpers/table_helper.rb +2 -4
- data/app/helpers/utility_helper.rb +9 -11
- data/app/views/layouts/application.html.erb +1 -1
- data/app/views/layouts/application.html.haml +1 -1
- data/lib/dry_crud/engine.rb +1 -3
- data/lib/dry_crud.rb +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +17 -17
- 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 +119 -119
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +54 -59
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +23 -25
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +10 -13
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +88 -92
- 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 +57 -59
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +18 -21
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +62 -62
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +8 -10
- 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 +20 -22
- 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 +13 -15
- 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 +25 -27
- data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +15 -17
- 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 +9 -13
- data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +7 -11
- data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +13 -15
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +2 -4
- metadata +5 -5
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe 'DryCrud::Form::Builder' do
|
1
|
+
require "rails_helper"
|
4
2
|
|
3
|
+
describe "DryCrud::Form::Builder" do
|
5
4
|
include FormatHelper
|
6
5
|
include FormHelper
|
7
6
|
include UtilityHelper
|
@@ -19,12 +18,11 @@ describe 'DryCrud::Form::Builder' do
|
|
19
18
|
let(:entry) { CrudTestModel.first }
|
20
19
|
let(:form) { DryCrud::Form::Builder.new(:entry, entry, self, {}) }
|
21
20
|
|
22
|
-
describe
|
23
|
-
|
24
|
-
it 'dispatches name attr to string field' do
|
21
|
+
describe "#input_field" do
|
22
|
+
it "dispatches name attr to string field" do
|
25
23
|
expect(form).to receive(:string_field)
|
26
|
-
.with(:name, required:
|
27
|
-
.and_return(
|
24
|
+
.with(:name, required: "required")
|
25
|
+
.and_return("<input>")
|
28
26
|
form.input_field(:name)
|
29
27
|
end
|
30
28
|
|
@@ -48,134 +46,132 @@ describe 'DryCrud::Form::Builder' do
|
|
48
46
|
|
49
47
|
it { expect(form.input_field(attr)).to be_html_safe }
|
50
48
|
end
|
51
|
-
|
52
49
|
end
|
53
50
|
|
54
|
-
describe
|
51
|
+
describe "#labeled_input_fields" do
|
55
52
|
subject { form.labeled_input_fields(:name, :remarks, :children) }
|
56
53
|
|
57
54
|
it { is_expected.to be_html_safe }
|
58
|
-
it { is_expected.to include(form.input_field(:name, required:
|
55
|
+
it { is_expected.to include(form.input_field(:name, required: "required")) }
|
59
56
|
it { is_expected.to include(form.input_field(:remarks)) }
|
60
57
|
it { is_expected.to include(form.input_field(:children)) }
|
61
58
|
end
|
62
59
|
|
63
|
-
describe
|
64
|
-
context
|
60
|
+
describe "#labeled_input_field" do
|
61
|
+
context "when required" do
|
65
62
|
subject { form.labeled_input_field(:name) }
|
66
|
-
it { is_expected.to include(
|
63
|
+
it { is_expected.to include("input-group-text") }
|
67
64
|
end
|
68
65
|
|
69
|
-
context
|
66
|
+
context "when not required" do
|
70
67
|
subject { form.labeled_input_field(:remarks) }
|
71
|
-
it { is_expected.not_to include(
|
68
|
+
it { is_expected.not_to include("input-group-text") }
|
72
69
|
end
|
73
70
|
|
74
|
-
context
|
75
|
-
subject { form.labeled_input_field(:name, help:
|
76
|
-
it { is_expected.to include(form.help_block(
|
71
|
+
context "with help text" do
|
72
|
+
subject { form.labeled_input_field(:name, help: "Some Help") }
|
73
|
+
it { is_expected.to include(form.help_block("Some Help")) }
|
77
74
|
end
|
78
75
|
end
|
79
76
|
|
80
|
-
describe
|
81
|
-
it
|
77
|
+
describe "#belongs_to_field" do
|
78
|
+
it "has all options by default" do
|
82
79
|
f = form.belongs_to_field(:companion_id)
|
83
80
|
expect_n_options(f, 7)
|
84
81
|
end
|
85
82
|
|
86
|
-
it
|
83
|
+
it "with has options from :list option" do
|
87
84
|
list = CrudTestModel.all
|
88
85
|
f = form.belongs_to_field(:companion_id,
|
89
|
-
list: [list.first, list.second])
|
86
|
+
list: [ list.first, list.second ])
|
90
87
|
expect_n_options(f, 3)
|
91
88
|
end
|
92
89
|
|
93
|
-
it
|
90
|
+
it "with empty instance list has no select" do
|
94
91
|
assign(:companions, [])
|
95
92
|
@companions = []
|
96
93
|
f = form.belongs_to_field(:companion_id)
|
97
|
-
expect(f).to match t(
|
94
|
+
expect(f).to match t("global.associations.none_available")
|
98
95
|
expect_n_options(f, 0)
|
99
96
|
end
|
100
97
|
end
|
101
98
|
|
102
|
-
describe
|
99
|
+
describe "#has_and_belongs_to_many_field" do
|
103
100
|
let(:others) { OtherCrudTestModel.all[0..1] }
|
104
101
|
|
105
|
-
it
|
102
|
+
it "has all options by default" do
|
106
103
|
f = form.has_many_field(:other_ids)
|
107
104
|
expect_n_options(f, 6)
|
108
105
|
end
|
109
106
|
|
110
|
-
it
|
107
|
+
it "uses options from :list option if given" do
|
111
108
|
f = form.has_many_field(:other_ids, list: others)
|
112
109
|
expect_n_options(f, 2)
|
113
110
|
end
|
114
111
|
|
115
|
-
it
|
112
|
+
it "uses options form instance variable if given" do
|
116
113
|
assign(:others, others)
|
117
114
|
@others = others
|
118
115
|
f = form.has_many_field(:other_ids)
|
119
116
|
expect_n_options(f, 2)
|
120
117
|
end
|
121
118
|
|
122
|
-
it
|
119
|
+
it "displays a message for an empty list" do
|
123
120
|
@others = []
|
124
121
|
f = form.has_many_field(:other_ids)
|
125
|
-
expect(f).to match t(
|
122
|
+
expect(f).to match t("global.associations.none_available")
|
126
123
|
expect_n_options(f, 0)
|
127
124
|
end
|
128
125
|
end
|
129
126
|
|
130
|
-
describe
|
131
|
-
it
|
127
|
+
describe "#string_field" do
|
128
|
+
it "sets maxlength if attr has a limit" do
|
132
129
|
expect(form.string_field(:name)).to match(/maxlength="50"/)
|
133
130
|
end
|
134
131
|
end
|
135
132
|
|
136
|
-
describe
|
137
|
-
context
|
133
|
+
describe "#label" do
|
134
|
+
context "only with attr" do
|
138
135
|
subject { form.label(:gugus_dada) }
|
139
136
|
|
140
137
|
it { is_expected.to be_html_safe }
|
141
|
-
it
|
138
|
+
it "provides the same interface as rails" do
|
142
139
|
is_expected.to match(/label [^>]*for.+Gugus dada/)
|
143
140
|
end
|
144
141
|
end
|
145
142
|
|
146
|
-
context
|
147
|
-
subject { form.label(:gugus_dada,
|
143
|
+
context "with attr and text" do
|
144
|
+
subject { form.label(:gugus_dada, "hoho") }
|
148
145
|
|
149
146
|
it { is_expected.to be_html_safe }
|
150
|
-
it
|
147
|
+
it "provides the same interface as rails" do
|
151
148
|
is_expected.to match(/label [^>]*for.+hoho/)
|
152
149
|
end
|
153
150
|
end
|
154
|
-
|
155
151
|
end
|
156
152
|
|
157
|
-
describe
|
158
|
-
context
|
153
|
+
describe "#labeled" do
|
154
|
+
context "in labeled_ method" do
|
159
155
|
subject { form.labeled_string_field(:name) }
|
160
156
|
|
161
157
|
it { is_expected.to be_html_safe }
|
162
|
-
it
|
158
|
+
it "provides the same interface as rails" do
|
163
159
|
is_expected.to match(/label [^>]*for.+input/m)
|
164
160
|
end
|
165
161
|
end
|
166
162
|
|
167
|
-
context
|
163
|
+
context "with custom content in argument" do
|
168
164
|
subject do
|
169
|
-
form.labeled(
|
165
|
+
form.labeled("gugus", "<input type='text' name='gugus' />".html_safe)
|
170
166
|
end
|
171
167
|
|
172
168
|
it { is_expected.to be_html_safe }
|
173
169
|
it { is_expected.to match(/label [^>]*for.+<input/m) }
|
174
170
|
end
|
175
171
|
|
176
|
-
context
|
172
|
+
context "with custom content in block" do
|
177
173
|
subject do
|
178
|
-
form.labeled(
|
174
|
+
form.labeled("gugus") do
|
179
175
|
"<input type='text' name='gugus' />".html_safe
|
180
176
|
end
|
181
177
|
end
|
@@ -184,20 +180,20 @@ describe 'DryCrud::Form::Builder' do
|
|
184
180
|
it { is_expected.to match(/label [^>]*for.+<input/m) }
|
185
181
|
end
|
186
182
|
|
187
|
-
context
|
183
|
+
context "with caption and content in argument" do
|
188
184
|
subject do
|
189
|
-
form.labeled(
|
185
|
+
form.labeled("gugus",
|
190
186
|
"<input type='text' name='gugus' />".html_safe,
|
191
|
-
caption:
|
187
|
+
caption: "Caption")
|
192
188
|
end
|
193
189
|
|
194
190
|
it { is_expected.to be_html_safe }
|
195
191
|
it { is_expected.to match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
|
196
192
|
end
|
197
193
|
|
198
|
-
context
|
194
|
+
context "with caption and content in block" do
|
199
195
|
subject do
|
200
|
-
form.labeled(
|
196
|
+
form.labeled("gugus", caption: "Caption") do
|
201
197
|
"<input type='text' name='gugus' />".html_safe
|
202
198
|
end
|
203
199
|
end
|
@@ -207,26 +203,25 @@ describe 'DryCrud::Form::Builder' do
|
|
207
203
|
end
|
208
204
|
end
|
209
205
|
|
210
|
-
it
|
206
|
+
it "handles missing methods" do
|
211
207
|
expect { form.blabla }.to raise_error(NoMethodError)
|
212
208
|
end
|
213
209
|
|
214
|
-
context
|
215
|
-
it
|
210
|
+
context "#respond_to?" do
|
211
|
+
it "returns false for non existing methods" do
|
216
212
|
expect(form.respond_to?(:blabla)).to be false
|
217
213
|
end
|
218
214
|
|
219
|
-
it
|
215
|
+
it "returns true for existing methods" do
|
220
216
|
expect(form.respond_to?(:text_field)).to be true
|
221
217
|
end
|
222
218
|
|
223
|
-
it
|
219
|
+
it "returns true for labeled_ methods" do
|
224
220
|
expect(form.respond_to?(:labeled_text_field)).to be true
|
225
221
|
end
|
226
222
|
end
|
227
223
|
|
228
224
|
def expect_n_options(form, count)
|
229
|
-
expect(form.scan(
|
225
|
+
expect(form.scan("</option>").size).to eq(count)
|
230
226
|
end
|
231
|
-
|
232
227
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe 'DryCrud::Table::Builder' do
|
1
|
+
require "rails_helper"
|
4
2
|
|
3
|
+
describe "DryCrud::Table::Builder" do
|
5
4
|
include FormatHelper
|
6
5
|
include UtilityHelper
|
7
6
|
|
@@ -12,43 +11,43 @@ describe 'DryCrud::Table::Builder' do
|
|
12
11
|
"#{obj.size} chars"
|
13
12
|
end
|
14
13
|
|
15
|
-
specify
|
14
|
+
specify "#html_header" do
|
16
15
|
table.attrs :upcase, :size
|
17
|
-
dom =
|
16
|
+
dom = "<tr><th>Upcase</th><th>Size</th></tr>"
|
18
17
|
assert_dom_equal dom, table.send(:html_header)
|
19
18
|
end
|
20
19
|
|
21
|
-
specify
|
20
|
+
specify "single attr row" do
|
22
21
|
table.attrs :upcase, :size
|
23
|
-
dom =
|
22
|
+
dom = "<tr><td>FOO</td><td>3 chars</td></tr>"
|
24
23
|
assert_dom_equal dom, table.send(:html_row, entries.first)
|
25
24
|
end
|
26
25
|
|
27
|
-
specify
|
28
|
-
table.col(
|
26
|
+
specify "custom row" do
|
27
|
+
table.col("Header", class: "hula") { |e| "Weights #{e.size} kg" }
|
29
28
|
dom = '<tr><td class="hula">Weights 3 kg</td></tr>'
|
30
29
|
assert_dom_equal dom, table.send(:html_row, entries.first)
|
31
30
|
end
|
32
31
|
|
33
|
-
context
|
32
|
+
context "attr col" do
|
34
33
|
let(:col) { table.cols.first }
|
35
34
|
|
36
|
-
context
|
35
|
+
context "output" do
|
37
36
|
before { table.attrs :upcase }
|
38
37
|
|
39
|
-
it { expect(col.html_header).to eq(
|
40
|
-
it { expect(col.content(
|
41
|
-
it { expect(col.html_cell(
|
38
|
+
it { expect(col.html_header).to eq("<th>Upcase</th>") }
|
39
|
+
it { expect(col.content("foo")).to eq("FOO") }
|
40
|
+
it { expect(col.html_cell("foo")).to eq("<td>FOO</td>") }
|
42
41
|
end
|
43
42
|
|
44
|
-
context
|
43
|
+
context "content with custom format_size method" do
|
45
44
|
before { table.attrs :size }
|
46
45
|
|
47
|
-
it { expect(col.content(
|
46
|
+
it { expect(col.content("abcd")).to eq("4 chars") }
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
|
-
specify
|
50
|
+
specify "two x two table" do
|
52
51
|
dom = <<-FIN
|
53
52
|
<table>
|
54
53
|
<thead>
|
@@ -60,14 +59,14 @@ describe 'DryCrud::Table::Builder' do
|
|
60
59
|
</tbody>
|
61
60
|
</table>
|
62
61
|
FIN
|
63
|
-
dom.gsub!(/[\n\t]/,
|
62
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
64
63
|
|
65
64
|
table.attrs :upcase, :size
|
66
65
|
|
67
66
|
assert_dom_equal dom, table.to_html
|
68
67
|
end
|
69
68
|
|
70
|
-
specify
|
69
|
+
specify "table with before and after cells" do
|
71
70
|
dom = <<-FIN
|
72
71
|
<table>
|
73
72
|
<thead>
|
@@ -89,16 +88,16 @@ describe 'DryCrud::Table::Builder' do
|
|
89
88
|
</tbody>
|
90
89
|
</table>
|
91
90
|
FIN
|
92
|
-
dom.gsub!(/[\n\t]/,
|
91
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
93
92
|
|
94
|
-
table.col(
|
93
|
+
table.col("head", class: "left") { |e| link_to e, "/" }
|
95
94
|
table.attrs :upcase, :size
|
96
95
|
table.col { |e| "Never #{e}" }
|
97
96
|
|
98
97
|
assert_dom_equal dom, table.to_html
|
99
98
|
end
|
100
99
|
|
101
|
-
specify
|
100
|
+
specify "empty entries collection renders empty table" do
|
102
101
|
dom = <<-FIN
|
103
102
|
<table>
|
104
103
|
<thead>
|
@@ -108,14 +107,13 @@ describe 'DryCrud::Table::Builder' do
|
|
108
107
|
</tbody>
|
109
108
|
</table>
|
110
109
|
FIN
|
111
|
-
dom.gsub!(/[\n\t]/,
|
110
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
112
111
|
|
113
112
|
table = DryCrud::Table::Builder.new([], self)
|
114
|
-
table.col(
|
113
|
+
table.col("head", class: "left") { |e| link_to e, "/" }
|
115
114
|
table.attrs :upcase, :size
|
116
115
|
table.col { |e| "Never #{e}" }
|
117
116
|
|
118
117
|
assert_dom_equal dom, table.to_html
|
119
118
|
end
|
120
|
-
|
121
119
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "rails_helper"
|
2
2
|
|
3
3
|
describe FormHelper do
|
4
|
-
|
5
4
|
include UtilityHelper
|
6
5
|
include FormatHelper
|
7
6
|
include I18nHelper
|
@@ -15,18 +14,18 @@ describe FormHelper do
|
|
15
14
|
|
16
15
|
after(:all) { reset_db }
|
17
16
|
|
18
|
-
describe
|
17
|
+
describe "#plain_form" do
|
19
18
|
subject do
|
20
19
|
with_test_routing do
|
21
20
|
capture do
|
22
|
-
plain_form(entry, html: { class:
|
21
|
+
plain_form(entry, html: { class: "special" }) do |f|
|
23
22
|
f.labeled_input_fields :name, :birthdate
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
context
|
28
|
+
context "for existing entry" do
|
30
29
|
let(:entry) { crud_test_models(:AAAAA) }
|
31
30
|
|
32
31
|
it do
|
@@ -55,20 +54,19 @@ describe FormHelper do
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
describe
|
59
|
-
|
57
|
+
describe "#standard_form" do
|
60
58
|
subject do
|
61
59
|
with_test_routing do
|
62
60
|
capture do
|
63
61
|
standard_form(entry,
|
64
62
|
:name, :children, :birthdate, :human,
|
65
|
-
cancel_url:
|
66
|
-
html: { class:
|
63
|
+
cancel_url: "/somewhere",
|
64
|
+
html: { class: "special" })
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
|
-
context
|
69
|
+
context "for existing entry" do
|
72
70
|
let(:entry) { crud_test_models(:AAAAA) }
|
73
71
|
|
74
72
|
it do
|
@@ -119,7 +117,7 @@ describe FormHelper do
|
|
119
117
|
end
|
120
118
|
end
|
121
119
|
|
122
|
-
context
|
120
|
+
context "for invalid entry" do
|
123
121
|
let(:entry) do
|
124
122
|
e = crud_test_models(:AAAAA)
|
125
123
|
e.name = nil
|
@@ -146,7 +144,7 @@ describe FormHelper do
|
|
146
144
|
end
|
147
145
|
end
|
148
146
|
|
149
|
-
describe
|
147
|
+
describe "#crud_form" do
|
150
148
|
let(:entry) { CrudTestModel.first }
|
151
149
|
subject do
|
152
150
|
with_test_routing { crud_form }
|
@@ -215,5 +213,4 @@ describe FormHelper do
|
|
215
213
|
#{t('global.button.cancel')}<\/a>/x)
|
216
214
|
end
|
217
215
|
end
|
218
|
-
|
219
216
|
end
|