dry_crud 3.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/app/controllers/crud_controller.rb +10 -8
- data/app/controllers/dry_crud/generic_model.rb +6 -4
- data/app/controllers/dry_crud/nestable.rb +9 -11
- data/app/controllers/dry_crud/rememberable.rb +5 -1
- data/app/controllers/dry_crud/render_callbacks.rb +40 -19
- data/app/controllers/dry_crud/searchable.rb +40 -31
- data/app/controllers/dry_crud/sortable.rb +36 -26
- data/app/controllers/list_controller.rb +2 -2
- data/app/helpers/dry_crud/form/builder.rb +21 -13
- data/app/helpers/dry_crud/form/control.rb +8 -9
- data/app/helpers/dry_crud/table/actions.rb +6 -1
- data/app/helpers/dry_crud/table/builder.rb +4 -2
- data/app/helpers/dry_crud/table/col.rb +12 -1
- data/app/helpers/dry_crud/table/sorting.rb +7 -1
- data/app/helpers/form_helper.rb +7 -7
- data/app/helpers/format_helper.rb +3 -3
- data/app/helpers/i18n_helper.rb +3 -3
- data/app/helpers/utility_helper.rb +4 -1
- data/lib/dry_crud.rb +1 -2
- data/lib/dry_crud/engine.rb +5 -7
- data/lib/generators/dry_crud/dry_crud_generator.rb +3 -4
- data/lib/generators/dry_crud/dry_crud_generator_base.rb +6 -8
- data/lib/generators/dry_crud/file_generator.rb +1 -3
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +8 -18
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +1 -1
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +4 -4
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +7 -17
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +13 -29
- data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +25 -44
- data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +0 -1
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +3 -4
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +0 -2
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +2 -1
- 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 +8 -17
- data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +3 -0
- data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +27 -30
- data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +11 -13
- data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +7 -3
- data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +5 -9
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +1 -1
- metadata +10 -11
@@ -5,7 +5,6 @@ require 'generators/dry_crud/dry_crud_generator_base'
|
|
5
5
|
module DryCrud
|
6
6
|
# Copies one file of dry_crud to the rails application.
|
7
7
|
class FileGenerator < ::DryCrudGeneratorBase
|
8
|
-
|
9
8
|
desc "Copy one file from dry_crud to the application.\nFILENAME is a part of the name of the file to copy. Must match exactly one file."
|
10
9
|
|
11
10
|
argument :filename, type: :string, desc: 'Name or part of the filename to copy. Must match exactly one file.'
|
@@ -36,6 +35,5 @@ module DryCrud
|
|
36
35
|
end
|
37
36
|
end.flatten
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
41
|
-
end
|
39
|
+
end
|
@@ -6,7 +6,6 @@ require 'rails_helper'
|
|
6
6
|
# of CrudController.
|
7
7
|
|
8
8
|
describe CrudTestModelsController do
|
9
|
-
|
10
9
|
include CrudTestHelper
|
11
10
|
|
12
11
|
before(:all) do
|
@@ -64,11 +63,10 @@ describe CrudTestModelsController do
|
|
64
63
|
end
|
65
64
|
|
66
65
|
it 'session has empty list_params' do
|
67
|
-
expect(session[:list_params]).to eq(
|
66
|
+
expect(session[:list_params]).to eq({})
|
68
67
|
end
|
69
68
|
|
70
69
|
it 'provides entries helper method' do
|
71
|
-
is_expected.to render_template('index')
|
72
70
|
expect(entries).to be(controller.send(:entries))
|
73
71
|
end
|
74
72
|
end
|
@@ -83,7 +81,7 @@ describe CrudTestModelsController do
|
|
83
81
|
|
84
82
|
it 'session has query list param' do
|
85
83
|
expect(session[:list_params]['/crud_test_models.html'])
|
86
|
-
.to eq('q' =>
|
84
|
+
.to eq('q' => 'AAAA')
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
@@ -175,7 +173,7 @@ describe CrudTestModelsController do
|
|
175
173
|
session[:list_params] = {}
|
176
174
|
session[:list_params]['/crud_test_models'] =
|
177
175
|
{ 'q' => 'DDD', 'sort' => 'chatty', 'sort_dir' => 'desc' }
|
178
|
-
get :index, returning: true
|
176
|
+
get :index, params: { returning: true }
|
179
177
|
end
|
180
178
|
|
181
179
|
it_is_expected_to_respond
|
@@ -194,7 +192,6 @@ describe CrudTestModelsController do
|
|
194
192
|
|
195
193
|
context '.js', format: :js, combine: 'ijs' do
|
196
194
|
it_is_expected_to_respond
|
197
|
-
it_is_expected_to_assign_entries
|
198
195
|
it { expect(response.body).to eq('index js') }
|
199
196
|
end
|
200
197
|
end
|
@@ -202,7 +199,7 @@ describe CrudTestModelsController do
|
|
202
199
|
describe_action :get, :new do
|
203
200
|
context 'plain', combine: 'new' do
|
204
201
|
it 'assigns companions' do
|
205
|
-
expect(
|
202
|
+
expect(ivar(:companions)).to be_present
|
206
203
|
end
|
207
204
|
|
208
205
|
it 'calls two render callbacks' do
|
@@ -221,7 +218,7 @@ describe CrudTestModelsController do
|
|
221
218
|
it { is_expected.to redirect_to(crud_test_models_path) }
|
222
219
|
|
223
220
|
it 'does not set companions' do
|
224
|
-
expect(
|
221
|
+
expect(ivar(:companions)).to be_nil
|
225
222
|
end
|
226
223
|
end
|
227
224
|
end
|
@@ -244,7 +241,6 @@ describe CrudTestModelsController do
|
|
244
241
|
|
245
242
|
context 'plain', combine: 'chcp' do
|
246
243
|
it_is_expected_to_respond
|
247
|
-
it_is_expected_to_render('new')
|
248
244
|
it_is_expected_to_persist_entry(false)
|
249
245
|
it_is_expected_to_have_flash(:alert)
|
250
246
|
|
@@ -253,7 +249,7 @@ describe CrudTestModelsController do
|
|
253
249
|
end
|
254
250
|
|
255
251
|
it 'assigns companions' do
|
256
|
-
expect(
|
252
|
+
expect(ivar(:companions)).to be_present
|
257
253
|
end
|
258
254
|
|
259
255
|
it 'calls the correct callbacks' do
|
@@ -291,13 +287,12 @@ describe CrudTestModelsController do
|
|
291
287
|
|
292
288
|
context 'plain', combine: 'chip' do
|
293
289
|
it_is_expected_to_respond
|
294
|
-
it_is_expected_to_render('new')
|
295
290
|
it_is_expected_to_persist_entry(false)
|
296
291
|
it_is_expected_to_not_have_flash(:notice)
|
297
292
|
it_is_expected_to_not_have_flash(:alert)
|
298
293
|
|
299
294
|
it 'assigns companions' do
|
300
|
-
expect(
|
295
|
+
expect(ivar(:companions)).to be_present
|
301
296
|
end
|
302
297
|
|
303
298
|
it 'calls the correct callbacks' do
|
@@ -321,7 +316,7 @@ describe CrudTestModelsController do
|
|
321
316
|
it_is_expected_to_render_json
|
322
317
|
|
323
318
|
it 'does not assign companions' do
|
324
|
-
expect(
|
319
|
+
expect(ivar(:companions)).to be_nil
|
325
320
|
end
|
326
321
|
|
327
322
|
it 'calls the correct callbacks' do
|
@@ -331,7 +326,6 @@ describe CrudTestModelsController do
|
|
331
326
|
end
|
332
327
|
end
|
333
328
|
end
|
334
|
-
|
335
329
|
end
|
336
330
|
|
337
331
|
describe_action :get, :edit, id: true do
|
@@ -354,7 +348,6 @@ describe CrudTestModelsController do
|
|
354
348
|
|
355
349
|
context '.html', combine: 'uhivp' do
|
356
350
|
it_is_expected_to_respond
|
357
|
-
it_is_expected_to_render('edit')
|
358
351
|
it_is_expected_to_not_have_flash(:notice)
|
359
352
|
|
360
353
|
it 'changes entry' do
|
@@ -383,7 +376,6 @@ describe CrudTestModelsController do
|
|
383
376
|
end
|
384
377
|
end
|
385
378
|
end
|
386
|
-
|
387
379
|
end
|
388
380
|
|
389
381
|
describe_action :delete, :destroy, id: true do
|
@@ -437,7 +429,5 @@ describe CrudTestModelsController do
|
|
437
429
|
end
|
438
430
|
end
|
439
431
|
end
|
440
|
-
|
441
432
|
end
|
442
|
-
|
443
433
|
end
|
@@ -64,10 +64,10 @@ describe UtilityHelper do
|
|
64
64
|
|
65
65
|
describe '#default_crud_attrs' do
|
66
66
|
it 'do not contain id and password' do
|
67
|
-
expect(default_crud_attrs).to eq(
|
68
|
-
:name, :email, :whatever, :children, :companion_id, :rating, :income,
|
69
|
-
|
70
|
-
|
67
|
+
expect(default_crud_attrs).to eq(
|
68
|
+
[:name, :email, :whatever, :children, :companion_id, :rating, :income,
|
69
|
+
:birthdate, :gets_up_at, :last_seen, :human, :remarks,
|
70
|
+
:created_at, :updated_at])
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -27,8 +27,9 @@ shared_examples 'crud controller' do |options|
|
|
27
27
|
let(:model_identifier) { controller.model_identifier }
|
28
28
|
let(:test_params) { scope_params }
|
29
29
|
let(:sort_column) { model_class.column_names.first }
|
30
|
-
let(:
|
31
|
-
let(:
|
30
|
+
let(:ivar_name) { controller.send(:ivar_name, model_class) }
|
31
|
+
let(:entry) { ivar(ivar_name) }
|
32
|
+
let(:entries) { ivar(ivar_name.pluralize) }
|
32
33
|
let(:search_value) do
|
33
34
|
field = controller.search_columns.first
|
34
35
|
val = test_entry[field].to_s
|
@@ -53,8 +54,6 @@ shared_examples 'crud controller' do |options|
|
|
53
54
|
unless: skip?(options, %w(index html plain)),
|
54
55
|
combine: 'ihp' do
|
55
56
|
it_is_expected_to_respond
|
56
|
-
it_is_expected_to_assign_entries
|
57
|
-
it_is_expected_to_render
|
58
57
|
end
|
59
58
|
|
60
59
|
context 'search',
|
@@ -81,7 +80,7 @@ shared_examples 'crud controller' do |options|
|
|
81
80
|
it_is_expected_to_respond
|
82
81
|
|
83
82
|
it 'has sorted entries' do
|
84
|
-
sorted = entries.sort_by(&
|
83
|
+
sorted = entries.sort_by(&sort_column.to_sym)
|
85
84
|
expect(entries).to eq(sorted)
|
86
85
|
end
|
87
86
|
end
|
@@ -94,7 +93,7 @@ shared_examples 'crud controller' do |options|
|
|
94
93
|
it_is_expected_to_respond
|
95
94
|
|
96
95
|
it 'has sorted entries' do
|
97
|
-
sorted = entries.sort_by(&
|
96
|
+
sorted = entries.sort_by(&sort_column.to_sym)
|
98
97
|
expect(entries).to eq(sorted.reverse)
|
99
98
|
end
|
100
99
|
end
|
@@ -106,7 +105,6 @@ shared_examples 'crud controller' do |options|
|
|
106
105
|
unless: skip?(options, %w(index json)),
|
107
106
|
combine: 'ij' do
|
108
107
|
it_is_expected_to_respond
|
109
|
-
it_is_expected_to_assign_entries
|
110
108
|
it { expect(response.body).to start_with('[{') }
|
111
109
|
end
|
112
110
|
end
|
@@ -123,8 +121,6 @@ shared_examples 'crud controller' do |options|
|
|
123
121
|
unless: skip?(options, %w(show html plain)),
|
124
122
|
combine: 'sh' do
|
125
123
|
it_is_expected_to_respond
|
126
|
-
it_is_expected_to_assign_entry
|
127
|
-
it_is_expected_to_render
|
128
124
|
end
|
129
125
|
|
130
126
|
context 'with non-existing id',
|
@@ -134,7 +130,7 @@ shared_examples 'crud controller' do |options|
|
|
134
130
|
|
135
131
|
it 'raises RecordNotFound', perform_request: false do
|
136
132
|
expect { perform_request }
|
137
|
-
|
133
|
+
.to raise_error(ActiveRecord::RecordNotFound)
|
138
134
|
end
|
139
135
|
end
|
140
136
|
end
|
@@ -144,7 +140,6 @@ shared_examples 'crud controller' do |options|
|
|
144
140
|
unless: skip?(options, %w(show json)),
|
145
141
|
combine: 'sj' do
|
146
142
|
it_is_expected_to_respond
|
147
|
-
it_is_expected_to_assign_entry
|
148
143
|
it_is_expected_to_render_json
|
149
144
|
end
|
150
145
|
end
|
@@ -155,7 +150,6 @@ shared_examples 'crud controller' do |options|
|
|
155
150
|
unless: skip?(options, %w(new plain)),
|
156
151
|
combine: 'new' do
|
157
152
|
it_is_expected_to_respond
|
158
|
-
it_is_expected_to_render
|
159
153
|
it_is_expected_to_persist_entry(false)
|
160
154
|
end
|
161
155
|
|
@@ -191,7 +185,6 @@ shared_examples 'crud controller' do |options|
|
|
191
185
|
failing: true,
|
192
186
|
unless: skip?(options, %w(create html invalid)),
|
193
187
|
combine: 'chi' do
|
194
|
-
it_is_expected_to_render('new')
|
195
188
|
it_is_expected_to_persist_entry(false)
|
196
189
|
it_is_expected_to_set_attrs(:new)
|
197
190
|
it_is_expected_to_not_have_flash(:notice)
|
@@ -228,8 +221,6 @@ shared_examples 'crud controller' do |options|
|
|
228
221
|
unless: skip?(options, %w(edit)),
|
229
222
|
combine: 'edit' do
|
230
223
|
it_is_expected_to_respond
|
231
|
-
it_is_expected_to_render
|
232
|
-
it_is_expected_to_assign_entry
|
233
224
|
end
|
234
225
|
|
235
226
|
describe_action :put, :update,
|
@@ -257,7 +248,6 @@ shared_examples 'crud controller' do |options|
|
|
257
248
|
failing: true,
|
258
249
|
unless: skip?(options, %w(update html invalid)),
|
259
250
|
combine: 'uhi' do
|
260
|
-
it_is_expected_to_render('edit')
|
261
251
|
it_is_expected_to_set_attrs(:edit)
|
262
252
|
it_is_expected_to_not_have_flash(:notice)
|
263
253
|
end
|
@@ -291,7 +281,7 @@ shared_examples 'crud controller' do |options|
|
|
291
281
|
id: true,
|
292
282
|
unless: skip?(options, %w(destroy)) do
|
293
283
|
|
294
|
-
it 'removes entry from database', perform_request: false
|
284
|
+
it 'removes entry from database', perform_request: false do
|
295
285
|
expect { perform_request }.to change { model_class.count }.by(-1)
|
296
286
|
end
|
297
287
|
|
@@ -9,13 +9,14 @@ module CrudControllerTestHelper
|
|
9
9
|
def perform_request
|
10
10
|
m = RSpec.current_example.metadata
|
11
11
|
example_params = respond_to?(:params) ? send(:params) : {}
|
12
|
-
params = scope_params.
|
13
|
-
params
|
12
|
+
params = scope_params.dup
|
13
|
+
params[:format] = m[:format] if m[:format]
|
14
|
+
params[:id] = test_entry.id if m[:id]
|
14
15
|
params.merge!(example_params)
|
15
16
|
if m[:method] == :get && m[:format] == :js
|
16
|
-
|
17
|
+
get m[:action], params: params, xhr: true
|
17
18
|
else
|
18
|
-
send(m[:method], m[:action], params)
|
19
|
+
send(m[:method], m[:action], params: params)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -56,6 +57,10 @@ module CrudControllerTestHelper
|
|
56
57
|
@request = @@current_request
|
57
58
|
end
|
58
59
|
|
60
|
+
def ivar(name)
|
61
|
+
controller.instance_variable_get("@#{name}")
|
62
|
+
end
|
63
|
+
|
59
64
|
# The params defining the nesting of the test entry.
|
60
65
|
def scope_params
|
61
66
|
params = {}
|
@@ -79,7 +84,8 @@ module CrudControllerTestHelper
|
|
79
84
|
# Tests whether this action is configured to be skipped.
|
80
85
|
def describe_action(method, action, metadata = {}, &block)
|
81
86
|
action_defined = described_class.instance_methods
|
82
|
-
|
87
|
+
.map(&:to_s)
|
88
|
+
.include?(action.to_s)
|
83
89
|
describe("#{method.to_s.upcase} #{action}",
|
84
90
|
{ if: action_defined,
|
85
91
|
method: method,
|
@@ -95,7 +101,7 @@ module CrudControllerTestHelper
|
|
95
101
|
skips = [skips] if skips.blank? || !skips.first.is_a?(Array)
|
96
102
|
|
97
103
|
skips.flatten.present? &&
|
98
|
-
|
104
|
+
skips.any? { |skip| skip == contexts.take(skip.size) }
|
99
105
|
end
|
100
106
|
|
101
107
|
# Test the response status, default 200.
|
@@ -103,29 +109,6 @@ module CrudControllerTestHelper
|
|
103
109
|
it { expect(response.status).to eq(status) }
|
104
110
|
end
|
105
111
|
|
106
|
-
# Test that entries are assigned.
|
107
|
-
def it_is_expected_to_assign_entries
|
108
|
-
it 'assigns entries' do
|
109
|
-
expect(entries).to be_present
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Test that entry is assigned.
|
114
|
-
def it_is_expected_to_assign_entry
|
115
|
-
it 'assigns entry' do
|
116
|
-
expect(entry).to eq(test_entry)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Test that the given template or the main template of the action under
|
121
|
-
# test is rendered.
|
122
|
-
def it_is_expected_to_render(template = nil)
|
123
|
-
it do
|
124
|
-
template ||= RSpec.current_example.metadata[:action]
|
125
|
-
is_expected.to render_template(template)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
112
|
# Test that a json response is rendered.
|
130
113
|
def it_is_expected_to_render_json
|
131
114
|
it { expect(response.body).to start_with('{') }
|
@@ -147,6 +130,7 @@ module CrudControllerTestHelper
|
|
147
130
|
def it_is_expected_to_redirect_to_index
|
148
131
|
it do
|
149
132
|
is_expected.to redirect_to scope_params.merge(action: 'index',
|
133
|
+
id: nil,
|
150
134
|
returning: true)
|
151
135
|
end
|
152
136
|
end
|
@@ -35,12 +35,10 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
35
35
|
assert_equal 6, entries.size
|
36
36
|
assert_equal entries.sort_by(&:name), entries
|
37
37
|
assert_equal({}, session[:list_params])
|
38
|
-
assert_equal entries, assigns(:crud_test_models)
|
39
|
-
assert_respond_to assigns(:crud_test_models), :klass
|
40
38
|
end
|
41
39
|
|
42
40
|
def test_index_js
|
43
|
-
|
41
|
+
get :index, params: test_params, xhr: true
|
44
42
|
assert_response :success
|
45
43
|
assert_equal 'index js', @response.body
|
46
44
|
assert entries.present?
|
@@ -53,18 +51,16 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def test_index_with_custom_options
|
56
|
-
get :index, filter: true
|
54
|
+
get :index, params: { filter: true }
|
57
55
|
assert_response :success
|
58
|
-
assert_template 'index'
|
59
56
|
assert entries.present?
|
60
57
|
assert_equal 2, entries.size
|
61
58
|
assert_equal entries.sort_by(&:children).reverse, entries
|
62
59
|
end
|
63
60
|
|
64
61
|
def test_index_search_with_custom_options
|
65
|
-
get :index, q: 'DDD', filter: true
|
62
|
+
get :index, params: { q: 'DDD', filter: true }
|
66
63
|
assert_response :success
|
67
|
-
assert_template 'index'
|
68
64
|
assert entries.present?
|
69
65
|
assert_equal 1, entries.size
|
70
66
|
assert_equal [CrudTestModel.find_by_name('BBBBB')], entries
|
@@ -72,9 +68,8 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
72
68
|
end
|
73
69
|
|
74
70
|
def test_sort_given_column
|
75
|
-
get :index, sort: 'children', sort_dir: 'asc'
|
71
|
+
get :index, params: { sort: 'children', sort_dir: 'asc' }
|
76
72
|
assert_response :success
|
77
|
-
assert_template 'index'
|
78
73
|
assert entries.present?
|
79
74
|
assert_equal 6, entries.size
|
80
75
|
assert_equal CrudTestModel.all.sort_by(&:children), entries
|
@@ -83,9 +78,8 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
83
78
|
end
|
84
79
|
|
85
80
|
def test_sort_virtual_column
|
86
|
-
get :index, sort: 'chatty', sort_dir: 'desc'
|
81
|
+
get :index, params: { sort: 'chatty', sort_dir: 'desc' }
|
87
82
|
assert_response :success
|
88
|
-
assert_template 'index'
|
89
83
|
assert entries.present?
|
90
84
|
assert_equal 6, entries.size
|
91
85
|
assert_equal({ 'sort' => 'chatty', 'sort_dir' => 'desc' },
|
@@ -102,9 +96,8 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
102
96
|
end
|
103
97
|
|
104
98
|
def test_sort_with_search
|
105
|
-
get :index, q: 'DDD', sort: 'chatty', sort_dir: 'asc'
|
99
|
+
get :index, params: { q: 'DDD', sort: 'chatty', sort_dir: 'asc' }
|
106
100
|
assert_response :success
|
107
|
-
assert_template 'index'
|
108
101
|
assert entries.present?
|
109
102
|
assert_equal 3, entries.size
|
110
103
|
assert_equal %w(CCCCC DDDDD BBBBB), entries.map(&:name)
|
@@ -117,9 +110,8 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
117
110
|
session[:list_params]['/crud_test_models'] = { 'q' => 'DDD',
|
118
111
|
'sort' => 'chatty',
|
119
112
|
'sort_dir' => 'desc' }
|
120
|
-
get :index, returning: true
|
113
|
+
get :index, params: { returning: true }
|
121
114
|
assert_response :success
|
122
|
-
assert_template 'index'
|
123
115
|
assert entries.present?
|
124
116
|
assert_equal 3, entries.size
|
125
117
|
assert_equal %w(BBBBB DDDDD CCCCC), entries.map(&:name)
|
@@ -130,19 +122,12 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
130
122
|
|
131
123
|
def test_new
|
132
124
|
super
|
133
|
-
assert assigns(:companions)
|
134
|
-
assert_equal @controller.send(:entry), assigns(:crud_test_model)
|
135
125
|
assert_equal [:before_render_new, :before_render_form],
|
136
126
|
@controller.called_callbacks
|
137
127
|
end
|
138
128
|
|
139
|
-
def test_show
|
140
|
-
super
|
141
|
-
assert_equal @controller.send(:entry), assigns(:crud_test_model)
|
142
|
-
end
|
143
|
-
|
144
129
|
def test_show_with_custom
|
145
|
-
get :show, test_params(id: crud_test_models(:BBBBB).id)
|
130
|
+
get :show, params: test_params(id: crud_test_models(:BBBBB).id)
|
146
131
|
assert_response :success
|
147
132
|
assert_equal 'custom html', @response.body
|
148
133
|
end
|
@@ -157,7 +142,6 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
157
142
|
|
158
143
|
def test_edit
|
159
144
|
super
|
160
|
-
assert_equal @controller.send(:entry), assigns(:crud_test_model)
|
161
145
|
assert_equal [:before_render_edit, :before_render_form],
|
162
146
|
@controller.called_callbacks
|
163
147
|
end
|
@@ -168,7 +152,6 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
168
152
|
model: 'Crud Test Model <i>foo</i>'),
|
169
153
|
flash[:notice]
|
170
154
|
assert flash[:alert].blank?
|
171
|
-
assert_equal @controller.send(:entry), assigns(:crud_test_model)
|
172
155
|
assert_equal [:before_update, :before_save, :after_save, :after_update],
|
173
156
|
@controller.called_callbacks
|
174
157
|
end
|
@@ -178,18 +161,17 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
178
161
|
assert_equal [:before_destroy, :after_destroy],
|
179
162
|
@controller.called_callbacks
|
180
163
|
assert_equal I18n.t('crud.destroy.flash.success',
|
181
|
-
|
164
|
+
model: 'Crud Test Model <i>AAAAA</i>'),
|
182
165
|
flash[:notice]
|
183
166
|
end
|
184
167
|
|
185
168
|
def test_create_with_before_callback
|
186
169
|
assert_no_difference('CrudTestModel.count') do
|
187
|
-
post :create,
|
170
|
+
post :create,
|
171
|
+
params: { crud_test_model: { name: 'illegal', children: 2 } }
|
188
172
|
end
|
189
173
|
assert_response :success
|
190
|
-
assert_template 'new'
|
191
174
|
assert entry.new_record?
|
192
|
-
assert assigns(:companions).present?
|
193
175
|
assert flash[:alert].present?
|
194
176
|
assert_equal 'illegal', entry.name
|
195
177
|
assert_equal [:before_render_new, :before_render_form],
|
@@ -199,7 +181,8 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
199
181
|
def test_create_with_before_callback_redirect
|
200
182
|
@controller.should_redirect = true
|
201
183
|
assert_no_difference('CrudTestModel.count') do
|
202
|
-
post :create,
|
184
|
+
post :create,
|
185
|
+
params: { crud_test_model: { name: 'illegal', children: 2 } }
|
203
186
|
end
|
204
187
|
assert_redirected_to action: 'index'
|
205
188
|
assert_nil @controller.called_callbacks
|
@@ -209,17 +192,14 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
209
192
|
@controller.should_redirect = true
|
210
193
|
get :new
|
211
194
|
assert_redirected_to action: 'index'
|
212
|
-
assert_nil assigns(:companions)
|
213
195
|
end
|
214
196
|
|
215
197
|
def test_create_with_failure
|
216
198
|
assert_no_difference('CrudTestModel.count') do
|
217
|
-
post :create, crud_test_model: { children: 2 }
|
199
|
+
post :create, params: { crud_test_model: { children: 2 } }
|
218
200
|
end
|
219
201
|
assert_response :success
|
220
|
-
assert_template 'new'
|
221
202
|
assert entry.new_record?
|
222
|
-
assert assigns(:companions)
|
223
203
|
assert flash[:notice].blank?, flash[:notice].to_s
|
224
204
|
assert flash[:alert].blank?, flash[:alert].to_s
|
225
205
|
assert entry.name.blank?
|
@@ -230,7 +210,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
230
210
|
|
231
211
|
def test_create_with_failure_json
|
232
212
|
assert_no_difference('CrudTestModel.count') do
|
233
|
-
post :create, crud_test_model: { children: 2 }, format: 'json'
|
213
|
+
post :create, params: { crud_test_model: { children: 2 }, format: 'json' }
|
234
214
|
end
|
235
215
|
assert_response :unprocessable_entity
|
236
216
|
assert entry.new_record?
|
@@ -238,9 +218,8 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
238
218
|
end
|
239
219
|
|
240
220
|
def test_update_with_failure
|
241
|
-
put :update, id: test_entry.id, crud_test_model: { rating: 20 }
|
221
|
+
put :update, params: { id: test_entry.id, crud_test_model: { rating: 20 } }
|
242
222
|
assert_response :success
|
243
|
-
assert_template 'edit'
|
244
223
|
assert entry.changed?
|
245
224
|
assert flash[:notice].blank?
|
246
225
|
assert flash[:alert].blank?
|
@@ -251,9 +230,10 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
251
230
|
end
|
252
231
|
|
253
232
|
def test_update_with_failure_json
|
254
|
-
put :update,
|
255
|
-
|
256
|
-
|
233
|
+
put :update,
|
234
|
+
params: { id: test_entry.id,
|
235
|
+
crud_test_model: { rating: 20 },
|
236
|
+
format: 'json' }
|
257
237
|
assert_response :unprocessable_entity
|
258
238
|
assert entry.changed?
|
259
239
|
assert flash[:notice].blank?
|
@@ -265,7 +245,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
265
245
|
assert_no_difference("#{model_class.name}.count") do
|
266
246
|
@request.env['HTTP_REFERER'] =
|
267
247
|
crud_test_model_url(crud_test_models(:BBBBB))
|
268
|
-
delete :destroy, test_params(id: crud_test_models(:BBBBB).id)
|
248
|
+
delete :destroy, params: test_params(id: crud_test_models(:BBBBB).id)
|
269
249
|
end
|
270
250
|
assert_redirected_to_show(entry)
|
271
251
|
assert_match(/companion/, flash[:alert])
|
@@ -276,7 +256,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
276
256
|
e = crud_test_models(:AAAAA)
|
277
257
|
e.update_attribute :name, 'illegal'
|
278
258
|
assert_no_difference("#{model_class.name}.count") do
|
279
|
-
delete :destroy, test_params(id: e.id)
|
259
|
+
delete :destroy, params: test_params(id: e.id)
|
280
260
|
end
|
281
261
|
assert_redirected_to_index
|
282
262
|
assert_match(/illegal name/, flash[:alert])
|
@@ -285,8 +265,8 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
285
265
|
|
286
266
|
def test_destroy_failure_json
|
287
267
|
assert_no_difference("#{model_class.name}.count") do
|
288
|
-
delete :destroy, test_params(id: crud_test_models(:BBBBB).id,
|
289
|
-
|
268
|
+
delete :destroy, params: test_params(id: crud_test_models(:BBBBB).id,
|
269
|
+
format: 'json')
|
290
270
|
end
|
291
271
|
assert_response :unprocessable_entity
|
292
272
|
assert flash[:notice].blank?
|
@@ -323,4 +303,5 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
323
303
|
human: true,
|
324
304
|
remarks: "some custom\n\tremarks" }
|
325
305
|
end
|
306
|
+
|
326
307
|
end
|