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
|
1
|
+
require "rails_helper"
|
2
2
|
|
3
3
|
describe FormatHelper do
|
4
|
-
|
5
4
|
include UtilityHelper
|
6
5
|
include I18nHelper
|
7
6
|
include CrudTestHelper
|
@@ -23,9 +22,9 @@ describe FormatHelper do
|
|
23
22
|
"#{f(obj.size)} chars"
|
24
23
|
end
|
25
24
|
|
26
|
-
describe
|
27
|
-
context
|
28
|
-
subject { labeled(
|
25
|
+
describe "#labeled" do
|
26
|
+
context "regular" do
|
27
|
+
subject { labeled("label") { "value" } }
|
29
28
|
|
30
29
|
it { is_expected.to be_html_safe }
|
31
30
|
it do
|
@@ -36,8 +35,8 @@ describe FormatHelper do
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
context
|
40
|
-
subject { labeled(
|
38
|
+
context "with empty value" do
|
39
|
+
subject { labeled("label") { "" } }
|
41
40
|
|
42
41
|
it { is_expected.to be_html_safe }
|
43
42
|
it do
|
@@ -45,13 +44,13 @@ describe FormatHelper do
|
|
45
44
|
/<dt>label<\/dt>
|
46
45
|
\ <dd\ class=['"]value['"]>
|
47
46
|
#{UtilityHelper::EMPTY_STRING}
|
48
|
-
<\/dd>$/
|
47
|
+
<\/dd>$/xo
|
49
48
|
)
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
|
-
context
|
54
|
-
subject { labeled(
|
52
|
+
context "with unsafe value" do
|
53
|
+
subject { labeled("label") { "value <unsafe>" } }
|
55
54
|
|
56
55
|
it { is_expected.to be_html_safe }
|
57
56
|
it do
|
@@ -65,8 +64,8 @@ describe FormatHelper do
|
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
68
|
-
describe
|
69
|
-
subject { labeled_attr(
|
67
|
+
describe "#labeled_attr" do
|
68
|
+
subject { labeled_attr("foo", :size) }
|
70
69
|
|
71
70
|
it { is_expected.to be_html_safe }
|
72
71
|
it do
|
@@ -77,110 +76,108 @@ describe FormatHelper do
|
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
|
-
describe
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
expect(f(1.0)).to eq('1.000')
|
79
|
+
describe "#f" do
|
80
|
+
unless ENV["NON_LOCALIZED"] # localization dependent tests
|
81
|
+
context "Floats" do
|
82
|
+
it "adds two digits" do
|
83
|
+
expect(f(1.0)).to eq("1.000")
|
86
84
|
end
|
87
85
|
|
88
|
-
it
|
89
|
-
expect(f(3.14159)).to eq(
|
86
|
+
it "truncates to two digits" do
|
87
|
+
expect(f(3.14159)).to eq("3.142")
|
90
88
|
end
|
91
89
|
|
92
|
-
it
|
93
|
-
expect(f(12_345.6789)).to eq(
|
90
|
+
it "adds delimiters" do
|
91
|
+
expect(f(12_345.6789)).to eq("12,345.679")
|
94
92
|
end
|
95
93
|
end
|
96
94
|
|
97
|
-
context
|
98
|
-
it
|
99
|
-
expect(f(true)).to eq(
|
95
|
+
context "Booleans" do
|
96
|
+
it "true is_expected.to print yes" do
|
97
|
+
expect(f(true)).to eq("yes")
|
100
98
|
end
|
101
99
|
|
102
|
-
it
|
103
|
-
expect(f(false)).to eq(
|
100
|
+
it "false is_expected.to print no" do
|
101
|
+
expect(f(false)).to eq("no")
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
107
|
-
context
|
108
|
-
it
|
109
|
-
expect(f(Date.new(2013, 6, 9))).to eq(
|
105
|
+
context "Dates" do
|
106
|
+
it "prints regular date" do
|
107
|
+
expect(f(Date.new(2013, 6, 9))).to eq("2013-06-09")
|
110
108
|
end
|
111
109
|
end
|
112
110
|
|
113
|
-
context
|
114
|
-
it
|
115
|
-
expect(f(Time.utc(2013, 6, 9, 21, 25))).to eq(
|
111
|
+
context "Times" do
|
112
|
+
it "prints regular date" do
|
113
|
+
expect(f(Time.utc(2013, 6, 9, 21, 25))).to eq("2013-06-09 21:25")
|
116
114
|
end
|
117
115
|
end
|
118
116
|
end
|
119
117
|
|
120
|
-
context
|
121
|
-
it
|
118
|
+
context "nil" do
|
119
|
+
it "prints an empty string" do
|
122
120
|
expect(f(nil)).to eq(UtilityHelper::EMPTY_STRING)
|
123
121
|
end
|
124
122
|
end
|
125
123
|
|
126
|
-
context
|
127
|
-
it
|
128
|
-
expect(f(
|
124
|
+
context "Strings" do
|
125
|
+
it "prints regular strings unchanged" do
|
126
|
+
expect(f("blah blah")).to eq("blah blah")
|
129
127
|
end
|
130
128
|
|
131
|
-
it
|
132
|
-
expect(f(
|
129
|
+
it "is not html safe" do
|
130
|
+
expect(f("<injection>")).not_to be_html_safe
|
133
131
|
end
|
134
132
|
end
|
135
|
-
|
136
133
|
end
|
137
134
|
|
138
|
-
describe
|
139
|
-
it
|
140
|
-
expect(format_attr(
|
135
|
+
describe "#format_attr" do
|
136
|
+
it "uses #f" do
|
137
|
+
expect(format_attr("12.342", :to_f)).to eq(f(12.342))
|
141
138
|
end
|
142
139
|
|
143
|
-
it
|
144
|
-
expect(format_attr(
|
140
|
+
it "uses object attr format method if it exists" do
|
141
|
+
expect(format_attr("abcd", :size)).to eq("4 chars")
|
145
142
|
end
|
146
143
|
|
147
|
-
it
|
148
|
-
expect(format_attr([1, 2], :size)).to eq(
|
144
|
+
it "uses general attr format method if it exists" do
|
145
|
+
expect(format_attr([ 1, 2 ], :size)).to eq("2 items")
|
149
146
|
end
|
150
147
|
|
151
|
-
it
|
148
|
+
it "formats empty belongs_to" do
|
152
149
|
expect(format_attr(crud_test_models(:AAAAA), :companion)).to eq(
|
153
|
-
t(
|
150
|
+
t("global.associations.no_entry")
|
154
151
|
)
|
155
152
|
end
|
156
153
|
|
157
|
-
it
|
154
|
+
it "formats existing belongs_to" do
|
158
155
|
string = format_attr(crud_test_models(:BBBBB), :companion)
|
159
|
-
expect(string).to eq(
|
156
|
+
expect(string).to eq("AAAAA")
|
160
157
|
end
|
161
158
|
|
162
|
-
it
|
159
|
+
it "formats empty has_one" do
|
163
160
|
expect(format_attr(crud_test_models(:FFFFF), :comrad)).to eq(
|
164
|
-
t(
|
161
|
+
t("global.associations.no_entry")
|
165
162
|
)
|
166
163
|
end
|
167
164
|
|
168
|
-
it
|
165
|
+
it "formats existing has_one" do
|
169
166
|
string = format_attr(crud_test_models(:AAAAA), :comrad)
|
170
|
-
expect(string).to eq(
|
167
|
+
expect(string).to eq("BBBBB")
|
171
168
|
end
|
172
169
|
|
173
|
-
it
|
170
|
+
it "formats existing has_many" do
|
174
171
|
string = format_attr(crud_test_models(:CCCCC), :others)
|
175
172
|
expect(string).to be_html_safe
|
176
|
-
expect(string).to eq(
|
173
|
+
expect(string).to eq("<ul><li>AAAAA</li><li>BBBBB</li></ul>")
|
177
174
|
end
|
178
175
|
end
|
179
176
|
|
180
|
-
describe
|
177
|
+
describe "#column_type" do
|
181
178
|
let(:model) { crud_test_models(:AAAAA) }
|
182
179
|
|
183
|
-
it
|
180
|
+
it "recognizes types" do
|
184
181
|
expect(column_type(model, :name)).to eq(:string)
|
185
182
|
expect(column_type(model, :children)).to eq(:integer)
|
186
183
|
expect(column_type(model, :companion_id)).to eq(:integer)
|
@@ -195,47 +192,47 @@ describe FormatHelper do
|
|
195
192
|
end
|
196
193
|
end
|
197
194
|
|
198
|
-
describe
|
195
|
+
describe "#format_type" do
|
199
196
|
let(:model) { crud_test_models(:AAAAA) }
|
200
197
|
|
201
|
-
it
|
198
|
+
it "formats integers" do
|
202
199
|
model.children = 10_000
|
203
|
-
expect(format_type(model, :children)).to eq(
|
200
|
+
expect(format_type(model, :children)).to eq("10,000")
|
204
201
|
end
|
205
202
|
|
206
|
-
unless ENV[
|
207
|
-
it
|
208
|
-
expect(format_type(model, :rating)).to eq(
|
203
|
+
unless ENV["NON_LOCALIZED"] # localization dependent tests
|
204
|
+
it "formats floats" do
|
205
|
+
expect(format_type(model, :rating)).to eq("1.100")
|
209
206
|
end
|
210
207
|
|
211
|
-
it
|
212
|
-
expect(format_type(model, :income)).to eq(
|
208
|
+
it "formata decimals" do
|
209
|
+
expect(format_type(model, :income)).to eq("10,000,000.1111")
|
213
210
|
end
|
214
211
|
|
215
|
-
it
|
216
|
-
expect(format_type(model, :birthdate)).to eq(
|
212
|
+
it "formats dates" do
|
213
|
+
expect(format_type(model, :birthdate)).to eq("1910-01-01")
|
217
214
|
end
|
218
215
|
|
219
|
-
it
|
220
|
-
expect(format_type(model, :gets_up_at)).to eq(
|
216
|
+
it "formats times" do
|
217
|
+
expect(format_type(model, :gets_up_at)).to eq("01:01")
|
221
218
|
end
|
222
219
|
|
223
|
-
it
|
224
|
-
expect(format_type(model, :last_seen)).to eq(
|
220
|
+
it "formats datetimes" do
|
221
|
+
expect(format_type(model, :last_seen)).to eq("2010-01-01 11:21")
|
225
222
|
end
|
226
223
|
|
227
|
-
it
|
224
|
+
it "formats boolean false" do
|
228
225
|
model.human = false
|
229
|
-
expect(format_type(model, :human)).to eq(
|
226
|
+
expect(format_type(model, :human)).to eq("no")
|
230
227
|
end
|
231
228
|
|
232
|
-
it
|
229
|
+
it "formats boolean true" do
|
233
230
|
model.human = true
|
234
|
-
expect(format_type(model, :human)).to eq(
|
231
|
+
expect(format_type(model, :human)).to eq("yes")
|
235
232
|
end
|
236
233
|
end
|
237
234
|
|
238
|
-
it
|
235
|
+
it "formats texts" do
|
239
236
|
string = format_type(model, :remarks)
|
240
237
|
expect(string).to be_html_safe
|
241
238
|
expect(string).to eq(
|
@@ -243,33 +240,32 @@ describe FormatHelper do
|
|
243
240
|
)
|
244
241
|
end
|
245
242
|
|
246
|
-
it
|
247
|
-
model.remarks =
|
243
|
+
it "escapes texts" do
|
244
|
+
model.remarks = "<unsecure>bla"
|
248
245
|
string = format_type(model, :remarks)
|
249
246
|
expect(string).to be_html_safe
|
250
|
-
expect(string).to eq(
|
247
|
+
expect(string).to eq("<p><unsecure>bla</p>")
|
251
248
|
end
|
252
249
|
|
253
|
-
it
|
254
|
-
model.remarks =
|
250
|
+
it "formats empty texts" do
|
251
|
+
model.remarks = " "
|
255
252
|
string = format_type(model, :remarks)
|
256
253
|
expect(string).to be_html_safe
|
257
254
|
expect(string).to eq(UtilityHelper::EMPTY_STRING)
|
258
255
|
end
|
259
256
|
end
|
260
257
|
|
261
|
-
describe
|
262
|
-
it
|
263
|
-
expect(captionize(:camel_case)).to eq(
|
258
|
+
describe "#captionize" do
|
259
|
+
it "handles symbols" do
|
260
|
+
expect(captionize(:camel_case)).to eq("Camel Case")
|
264
261
|
end
|
265
262
|
|
266
|
-
it
|
267
|
-
expect(captionize(
|
263
|
+
it "renders all upper case" do
|
264
|
+
expect(captionize("all upper case")).to eq("All Upper Case")
|
268
265
|
end
|
269
266
|
|
270
|
-
it
|
271
|
-
expect(captionize(:gets_up_at, CrudTestModel)).to eq(
|
267
|
+
it "renders human attribute name" do
|
268
|
+
expect(captionize(:gets_up_at, CrudTestModel)).to eq("Gets up at")
|
272
269
|
end
|
273
270
|
end
|
274
|
-
|
275
271
|
end
|
@@ -1,101 +1,100 @@
|
|
1
|
-
require
|
1
|
+
require "rails_helper"
|
2
2
|
|
3
3
|
describe I18nHelper do
|
4
|
-
|
5
4
|
include CrudTestHelper
|
6
5
|
|
7
|
-
describe
|
6
|
+
describe "#translate_inheritable" do
|
8
7
|
before { @controller = CrudTestModelsController.new }
|
9
8
|
|
10
9
|
before do
|
11
10
|
I18n.backend.store_translations(
|
12
11
|
I18n.locale,
|
13
12
|
global: {
|
14
|
-
test_key:
|
13
|
+
test_key: "global"
|
15
14
|
}
|
16
15
|
)
|
17
16
|
end
|
18
17
|
subject { ti(:test_key) }
|
19
18
|
|
20
|
-
it { is_expected.to eq(
|
19
|
+
it { is_expected.to eq("global") }
|
21
20
|
|
22
|
-
context
|
21
|
+
context "with list key" do
|
23
22
|
before do
|
24
23
|
I18n.backend.store_translations(
|
25
24
|
I18n.locale,
|
26
25
|
list: {
|
27
26
|
global: {
|
28
|
-
test_key:
|
27
|
+
test_key: "list global"
|
29
28
|
}
|
30
29
|
}
|
31
30
|
)
|
32
31
|
end
|
33
|
-
it { is_expected.to eq(
|
32
|
+
it { is_expected.to eq("list global") }
|
34
33
|
|
35
|
-
context
|
34
|
+
context "and list action key" do
|
36
35
|
before do
|
37
36
|
I18n.backend.store_translations(
|
38
37
|
I18n.locale,
|
39
38
|
list: {
|
40
39
|
index: {
|
41
|
-
test_key:
|
40
|
+
test_key: "list index"
|
42
41
|
}
|
43
42
|
}
|
44
43
|
)
|
45
44
|
end
|
46
|
-
it { is_expected.to eq(
|
45
|
+
it { is_expected.to eq("list index") }
|
47
46
|
|
48
|
-
context
|
47
|
+
context "and crud global key" do
|
49
48
|
before do
|
50
49
|
I18n.backend.store_translations(
|
51
50
|
I18n.locale,
|
52
51
|
crud: {
|
53
52
|
global: {
|
54
|
-
test_key:
|
53
|
+
test_key: "crud global"
|
55
54
|
}
|
56
55
|
}
|
57
56
|
)
|
58
57
|
end
|
59
|
-
it { is_expected.to eq(
|
58
|
+
it { is_expected.to eq("crud global") }
|
60
59
|
|
61
|
-
context
|
60
|
+
context "and crud action key" do
|
62
61
|
before do
|
63
62
|
I18n.backend.store_translations(
|
64
63
|
I18n.locale,
|
65
64
|
crud: {
|
66
65
|
index: {
|
67
|
-
test_key:
|
66
|
+
test_key: "crud index"
|
68
67
|
}
|
69
68
|
}
|
70
69
|
)
|
71
70
|
end
|
72
|
-
it { is_expected.to eq(
|
71
|
+
it { is_expected.to eq("crud index") }
|
73
72
|
|
74
|
-
context
|
73
|
+
context "and controller global key" do
|
75
74
|
before do
|
76
75
|
I18n.backend.store_translations(
|
77
76
|
I18n.locale,
|
78
77
|
crud_test_models: {
|
79
78
|
global: {
|
80
|
-
test_key:
|
79
|
+
test_key: "test global"
|
81
80
|
}
|
82
81
|
}
|
83
82
|
)
|
84
83
|
end
|
85
|
-
it { is_expected.to eq(
|
84
|
+
it { is_expected.to eq("test global") }
|
86
85
|
|
87
|
-
context
|
86
|
+
context "and controller action key" do
|
88
87
|
before do
|
89
88
|
I18n.backend.store_translations(
|
90
89
|
I18n.locale,
|
91
90
|
crud_test_models: {
|
92
91
|
index: {
|
93
|
-
test_key:
|
92
|
+
test_key: "test index"
|
94
93
|
}
|
95
94
|
}
|
96
95
|
)
|
97
96
|
end
|
98
|
-
it { is_expected.to eq(
|
97
|
+
it { is_expected.to eq("test index") }
|
99
98
|
end
|
100
99
|
end
|
101
100
|
end
|
@@ -104,7 +103,7 @@ describe I18nHelper do
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
107
|
-
describe
|
106
|
+
describe "#translate_association" do
|
108
107
|
let(:assoc) { CrudTestModel.reflect_on_association(:companion) }
|
109
108
|
subject { ta(:test_key, assoc) }
|
110
109
|
|
@@ -113,30 +112,30 @@ describe I18nHelper do
|
|
113
112
|
I18n.locale,
|
114
113
|
global: {
|
115
114
|
associations: {
|
116
|
-
test_key:
|
115
|
+
test_key: "global"
|
117
116
|
}
|
118
117
|
}
|
119
118
|
)
|
120
119
|
end
|
121
|
-
it { is_expected.to eq(
|
120
|
+
it { is_expected.to eq("global") }
|
122
121
|
|
123
|
-
context
|
122
|
+
context "with model key" do
|
124
123
|
before do
|
125
124
|
I18n.backend.store_translations(
|
126
125
|
I18n.locale,
|
127
126
|
activerecord: {
|
128
127
|
associations: {
|
129
128
|
crud_test_model: {
|
130
|
-
test_key:
|
129
|
+
test_key: "model"
|
131
130
|
}
|
132
131
|
}
|
133
132
|
}
|
134
133
|
)
|
135
134
|
end
|
136
135
|
|
137
|
-
it { is_expected.to eq(
|
136
|
+
it { is_expected.to eq("model") }
|
138
137
|
|
139
|
-
context
|
138
|
+
context "and assoc key" do
|
140
139
|
before do
|
141
140
|
I18n.backend.store_translations(
|
142
141
|
I18n.locale,
|
@@ -145,7 +144,7 @@ describe I18nHelper do
|
|
145
144
|
models: {
|
146
145
|
crud_test_model: {
|
147
146
|
companion: {
|
148
|
-
test_key:
|
147
|
+
test_key: "companion"
|
149
148
|
}
|
150
149
|
}
|
151
150
|
}
|
@@ -154,9 +153,9 @@ describe I18nHelper do
|
|
154
153
|
)
|
155
154
|
end
|
156
155
|
|
157
|
-
it { is_expected.to eq(
|
158
|
-
it
|
159
|
-
expect(ta(:test_key)).to eq(
|
156
|
+
it { is_expected.to eq("companion") }
|
157
|
+
it "uses global without assoc" do
|
158
|
+
expect(ta(:test_key)).to eq("global")
|
160
159
|
end
|
161
160
|
end
|
162
161
|
end
|