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,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "support/crud_controller_test_helper"
|
2
2
|
|
3
3
|
RSpec.configure do |c|
|
4
4
|
c.before failing: true do
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
# them by passing a skip parameter with context arrays:
|
15
15
|
# include_examples 'crud controller',
|
16
16
|
# skip: [%w(index html sort) %w(destroy json)]
|
17
|
-
shared_examples
|
17
|
+
shared_examples "crud controller" do |options|
|
18
18
|
include CrudControllerTestHelper
|
19
19
|
|
20
20
|
render_views
|
@@ -40,53 +40,53 @@ shared_examples 'crud controller' do |options|
|
|
40
40
|
end
|
41
41
|
|
42
42
|
describe_action :get, :index,
|
43
|
-
unless: skip?(options,
|
44
|
-
context
|
43
|
+
unless: skip?(options, "index") do
|
44
|
+
context ".html",
|
45
45
|
format: :html,
|
46
46
|
unless: skip?(options, %w[index html]) do
|
47
|
-
context
|
47
|
+
context "plain",
|
48
48
|
unless: skip?(options, %w[index html plain]),
|
49
|
-
combine:
|
49
|
+
combine: "ihp" do
|
50
50
|
it_is_expected_to_respond
|
51
51
|
end
|
52
52
|
|
53
|
-
context
|
53
|
+
context "search",
|
54
54
|
if: described_class.search_columns.present?,
|
55
55
|
unless: skip?(options, %w[index html search]),
|
56
|
-
combine:
|
56
|
+
combine: "ihse" do
|
57
57
|
let(:params) { { q: search_value } }
|
58
58
|
|
59
59
|
it_is_expected_to_respond
|
60
60
|
|
61
|
-
context
|
61
|
+
context "entries" do
|
62
62
|
subject { entries }
|
63
63
|
it { is_expected.to include(test_entry) }
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
context
|
67
|
+
context "sort",
|
68
68
|
unless: skip?(options, %w[index html sort]) do
|
69
|
-
context
|
69
|
+
context "ascending",
|
70
70
|
unless: skip?(options, %w[index html sort ascending]),
|
71
|
-
combine:
|
72
|
-
let(:params) { { sort: sort_column, sort_dir:
|
71
|
+
combine: "ihso" do
|
72
|
+
let(:params) { { sort: sort_column, sort_dir: "asc" } }
|
73
73
|
|
74
74
|
it_is_expected_to_respond
|
75
75
|
|
76
|
-
it
|
76
|
+
it "has sorted entries" do
|
77
77
|
sorted = entries.sort_by(&sort_column.to_sym)
|
78
78
|
expect(entries).to eq(sorted)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
context
|
82
|
+
context "descending",
|
83
83
|
unless: skip?(options, %w[index html sort descending]),
|
84
|
-
combine:
|
85
|
-
let(:params) { { sort: sort_column, sort_dir:
|
84
|
+
combine: "ihsd" do
|
85
|
+
let(:params) { { sort: sort_column, sort_dir: "desc" } }
|
86
86
|
|
87
87
|
it_is_expected_to_respond
|
88
88
|
|
89
|
-
it
|
89
|
+
it "has sorted entries" do
|
90
90
|
sorted = entries.sort_by(&sort_column.to_sym)
|
91
91
|
expect(entries).to eq(sorted.reverse)
|
92
92
|
end
|
@@ -94,43 +94,43 @@ shared_examples 'crud controller' do |options|
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
context
|
97
|
+
context ".json",
|
98
98
|
format: :json,
|
99
99
|
unless: skip?(options, %w[index json]),
|
100
|
-
combine:
|
100
|
+
combine: "ij" do
|
101
101
|
it_is_expected_to_respond
|
102
|
-
it { expect(response.body).to start_with(
|
102
|
+
it { expect(response.body).to start_with("[{") }
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
106
|
describe_action :get, :show,
|
107
107
|
id: true,
|
108
|
-
unless: skip?(options,
|
109
|
-
context
|
108
|
+
unless: skip?(options, "show") do
|
109
|
+
context ".html",
|
110
110
|
format: :html,
|
111
111
|
unless: skip?(options, %w[show html]) do
|
112
|
-
context
|
112
|
+
context "plain",
|
113
113
|
unless: skip?(options, %w[show html plain]),
|
114
|
-
combine:
|
114
|
+
combine: "sh" do
|
115
115
|
it_is_expected_to_respond
|
116
116
|
end
|
117
117
|
|
118
|
-
context
|
118
|
+
context "with non-existing id",
|
119
119
|
unless: skip?(options,
|
120
120
|
%w[show html with_non_existing_id]) do
|
121
121
|
let(:params) { { id: 9999 } }
|
122
122
|
|
123
|
-
it
|
123
|
+
it "raises RecordNotFound", perform_request: false do
|
124
124
|
expect { perform_request }
|
125
125
|
.to raise_error(ActiveRecord::RecordNotFound)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
context
|
130
|
+
context ".json",
|
131
131
|
format: :json,
|
132
132
|
unless: skip?(options, %w[show json]),
|
133
|
-
combine:
|
133
|
+
combine: "sj" do
|
134
134
|
it_is_expected_to_respond
|
135
135
|
it_is_expected_to_render_json
|
136
136
|
end
|
@@ -138,14 +138,14 @@ shared_examples 'crud controller' do |options|
|
|
138
138
|
|
139
139
|
describe_action :get, :new,
|
140
140
|
unless: skip?(options, %w[new]) do
|
141
|
-
context
|
141
|
+
context "plain",
|
142
142
|
unless: skip?(options, %w[new plain]),
|
143
|
-
combine:
|
143
|
+
combine: "new" do
|
144
144
|
it_is_expected_to_respond
|
145
145
|
it_is_expected_to_persist_entry(persist: false)
|
146
146
|
end
|
147
147
|
|
148
|
-
context
|
148
|
+
context "with params",
|
149
149
|
unless: skip?(options, %w[new with_params]) do
|
150
150
|
let(:params) { { model_identifier => new_entry_attrs } }
|
151
151
|
it_is_expected_to_set_attrs(:new)
|
@@ -156,50 +156,50 @@ shared_examples 'crud controller' do |options|
|
|
156
156
|
unless: skip?(options, %w[create]) do
|
157
157
|
let(:params) { { model_identifier => new_entry_attrs } }
|
158
158
|
|
159
|
-
it
|
159
|
+
it "adds entry to database", perform_request: false do
|
160
160
|
expect { perform_request }.to change { model_class.count }.by(1)
|
161
161
|
end
|
162
162
|
|
163
|
-
context
|
163
|
+
context "html",
|
164
164
|
format: :html,
|
165
165
|
unless: skip?(options, %w[create html]) do
|
166
166
|
it_is_expected_to_persist_entry # cannot combine this
|
167
167
|
|
168
|
-
context
|
168
|
+
context "with valid params",
|
169
169
|
unless: skip?(options, %w[create html valid]),
|
170
|
-
combine:
|
170
|
+
combine: "chv" do
|
171
171
|
it_is_expected_to_redirect_to_show
|
172
172
|
it_is_expected_to_set_attrs(:new)
|
173
173
|
it_is_expected_to_have_flash(:notice)
|
174
174
|
end
|
175
175
|
|
176
|
-
context
|
176
|
+
context "with invalid params",
|
177
177
|
failing: true,
|
178
178
|
unless: skip?(options, %w[create html invalid]),
|
179
|
-
combine:
|
179
|
+
combine: "chi" do
|
180
180
|
it_is_expected_to_persist_entry(persist: false)
|
181
181
|
it_is_expected_to_set_attrs(:new)
|
182
182
|
it_is_expected_to_not_have_flash(:notice)
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
-
context
|
186
|
+
context "json",
|
187
187
|
format: :json,
|
188
188
|
unless: skip?(options, %w[create json]) do
|
189
189
|
it_is_expected_to_persist_entry # cannot combine this
|
190
190
|
|
191
|
-
context
|
191
|
+
context "with valid params",
|
192
192
|
unless: skip?(options, %w[create json valid]),
|
193
|
-
combine:
|
193
|
+
combine: "cjv" do
|
194
194
|
it_is_expected_to_respond(201)
|
195
195
|
it_is_expected_to_set_attrs(:new)
|
196
196
|
it_is_expected_to_render_json
|
197
197
|
end
|
198
198
|
|
199
|
-
context
|
199
|
+
context "with invalid params",
|
200
200
|
failing: true,
|
201
201
|
unless: skip?(options, %w[create json invalid]),
|
202
|
-
combine:
|
202
|
+
combine: "cji" do
|
203
203
|
it_is_expected_to_respond(422)
|
204
204
|
it_is_expected_to_set_attrs(:new)
|
205
205
|
it_is_expected_to_render_json
|
@@ -211,7 +211,7 @@ shared_examples 'crud controller' do |options|
|
|
211
211
|
describe_action :get, :edit,
|
212
212
|
id: true,
|
213
213
|
unless: skip?(options, %w[edit]),
|
214
|
-
combine:
|
214
|
+
combine: "edit" do
|
215
215
|
it_is_expected_to_respond
|
216
216
|
end
|
217
217
|
|
@@ -220,47 +220,47 @@ shared_examples 'crud controller' do |options|
|
|
220
220
|
unless: skip?(options, %w[update]) do
|
221
221
|
let(:params) { { model_identifier => edit_entry_attrs } }
|
222
222
|
|
223
|
-
it
|
223
|
+
it "updates entry in database", perform_request: false do
|
224
224
|
expect { perform_request }.to change { model_class.count }.by(0)
|
225
225
|
end
|
226
226
|
|
227
|
-
context
|
227
|
+
context ".html",
|
228
228
|
format: :html,
|
229
229
|
unless: skip?(options, %w[update html]) do
|
230
|
-
context
|
230
|
+
context "with valid params",
|
231
231
|
unless: skip?(options, %w[update html valid]),
|
232
|
-
combine:
|
232
|
+
combine: "uhv" do
|
233
233
|
it_is_expected_to_set_attrs(:edit)
|
234
234
|
it_is_expected_to_redirect_to_show
|
235
235
|
it_is_expected_to_persist_entry
|
236
236
|
it_is_expected_to_have_flash(:notice)
|
237
237
|
end
|
238
238
|
|
239
|
-
context
|
239
|
+
context "with invalid params",
|
240
240
|
failing: true,
|
241
241
|
unless: skip?(options, %w[update html invalid]),
|
242
|
-
combine:
|
242
|
+
combine: "uhi" do
|
243
243
|
it_is_expected_to_set_attrs(:edit)
|
244
244
|
it_is_expected_to_not_have_flash(:notice)
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
248
|
-
context
|
248
|
+
context ".json",
|
249
249
|
format: :json,
|
250
250
|
unless: skip?(options, %w[update json]) do
|
251
|
-
context
|
251
|
+
context "with valid params",
|
252
252
|
unless: skip?(options, %w[update json valid]),
|
253
|
-
combine:
|
253
|
+
combine: "ujv" do
|
254
254
|
it_is_expected_to_respond(200)
|
255
255
|
it_is_expected_to_set_attrs(:edit)
|
256
256
|
it_is_expected_to_render_json
|
257
257
|
it_is_expected_to_persist_entry
|
258
258
|
end
|
259
259
|
|
260
|
-
context
|
260
|
+
context "with invalid params",
|
261
261
|
failing: true,
|
262
262
|
unless: skip?(options, %w[update json invalid]),
|
263
|
-
combine:
|
263
|
+
combine: "uji" do
|
264
264
|
it_is_expected_to_respond(422)
|
265
265
|
it_is_expected_to_set_attrs(:edit)
|
266
266
|
it_is_expected_to_render_json
|
@@ -271,33 +271,33 @@ shared_examples 'crud controller' do |options|
|
|
271
271
|
describe_action :delete, :destroy,
|
272
272
|
id: true,
|
273
273
|
unless: skip?(options, %w[destroy]) do
|
274
|
-
it
|
274
|
+
it "removes entry from database", perform_request: false do
|
275
275
|
expect { perform_request }.to change { model_class.count }.by(-1)
|
276
276
|
end
|
277
277
|
|
278
|
-
context
|
278
|
+
context ".html",
|
279
279
|
format: :html,
|
280
280
|
unless: skip?(options, %w[destroy html]) do
|
281
|
-
context
|
281
|
+
context "successfull", combine: "dhs" do
|
282
282
|
it_is_expected_to_redirect_to_index
|
283
283
|
it_is_expected_to_have_flash(:notice)
|
284
284
|
end
|
285
285
|
|
286
|
-
context
|
286
|
+
context "with failure", failing: true, combine: "dhf" do
|
287
287
|
it_is_expected_to_redirect_to_index
|
288
288
|
it_is_expected_to_have_flash(:alert)
|
289
289
|
end
|
290
290
|
end
|
291
291
|
|
292
|
-
context
|
292
|
+
context ".json",
|
293
293
|
format: :json,
|
294
294
|
unless: skip?(options, %w[destroy json]) do
|
295
|
-
context
|
295
|
+
context "successfull", combine: "djs" do
|
296
296
|
it_is_expected_to_respond(204)
|
297
297
|
it { expect(response.body).to be_blank }
|
298
298
|
end
|
299
299
|
|
300
|
-
context
|
300
|
+
context "with failure", failing: true, combine: "djf" do
|
301
301
|
it_is_expected_to_respond(422)
|
302
302
|
it_is_expected_to_render_json
|
303
303
|
end
|
@@ -56,7 +56,7 @@ module CrudControllerTestHelper
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def ivar(name)
|
59
|
-
controller.instance_variable_get("@#{name}")
|
59
|
+
controller.instance_variable_get(:"@#{name}")
|
60
60
|
end
|
61
61
|
|
62
62
|
# The params defining the nesting of the test entry.
|
@@ -77,7 +77,6 @@ module CrudControllerTestHelper
|
|
77
77
|
|
78
78
|
# Helper methods to describe contexts.
|
79
79
|
module ClassMethods
|
80
|
-
|
81
80
|
# Describe a certain action and provide some usefull metadata.
|
82
81
|
# Tests whether this action is configured to be skipped.
|
83
82
|
def describe_action(method, action, metadata = {}, &block)
|
@@ -96,7 +95,7 @@ module CrudControllerTestHelper
|
|
96
95
|
options ||= {}
|
97
96
|
contexts = Array(contexts).flatten
|
98
97
|
skips = Array(options[:skip])
|
99
|
-
skips = [skips] if skips.blank? || !skips.first.is_a?(Array)
|
98
|
+
skips = [ skips ] if skips.blank? || !skips.first.is_a?(Array)
|
100
99
|
|
101
100
|
skips.flatten.present? &&
|
102
101
|
skips.any? { |skip| skip == contexts.take(skip.size) }
|
@@ -109,13 +108,13 @@ module CrudControllerTestHelper
|
|
109
108
|
|
110
109
|
# Test that a json response is rendered.
|
111
110
|
def it_is_expected_to_render_json
|
112
|
-
it { expect(response.body).to start_with(
|
111
|
+
it { expect(response.body).to start_with("{") }
|
113
112
|
end
|
114
113
|
|
115
114
|
# Test that test_entry_attrs are set on entry.
|
116
115
|
def it_is_expected_to_set_attrs(action = nil)
|
117
|
-
it
|
118
|
-
attrs = send("#{action}_entry_attrs")
|
116
|
+
it "sets params as entry attributes" do
|
117
|
+
attrs = send(:"#{action}_entry_attrs")
|
119
118
|
actual = {}
|
120
119
|
attrs.each_key do |key|
|
121
120
|
actual[key] = entry.attributes[key.to_s]
|
@@ -127,7 +126,7 @@ module CrudControllerTestHelper
|
|
127
126
|
# Test that the response redirects to the index action.
|
128
127
|
def it_is_expected_to_redirect_to_index
|
129
128
|
it do
|
130
|
-
is_expected.to redirect_to scope_params.merge(action:
|
129
|
+
is_expected.to redirect_to scope_params.merge(action: "index",
|
131
130
|
id: nil,
|
132
131
|
returning: true)
|
133
132
|
end
|
@@ -136,7 +135,7 @@ module CrudControllerTestHelper
|
|
136
135
|
# Test that the response redirects to the show action of the current entry.
|
137
136
|
def it_is_expected_to_redirect_to_show
|
138
137
|
it do
|
139
|
-
is_expected.to redirect_to scope_params.merge(action:
|
138
|
+
is_expected.to redirect_to scope_params.merge(action: "show",
|
140
139
|
id: entry.id)
|
141
140
|
end
|
142
141
|
end
|
@@ -157,7 +156,7 @@ module CrudControllerTestHelper
|
|
157
156
|
|
158
157
|
# Test that the current entry is persistend and valid, or not.
|
159
158
|
def it_is_expected_to_persist_entry(persist: true)
|
160
|
-
context
|
159
|
+
context "entry" do
|
161
160
|
subject { entry }
|
162
161
|
|
163
162
|
if persist
|
@@ -169,5 +168,4 @@ module CrudControllerTestHelper
|
|
169
168
|
end
|
170
169
|
end
|
171
170
|
end
|
172
|
-
|
173
171
|
end
|