rails_ops 1.4.1 → 1.4.3
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/.rubocop.yml +102 -11
- data/Appraisals +11 -11
- data/CHANGELOG.md +18 -0
- data/README.md +12 -2
- data/Rakefile +3 -5
- data/VERSION +1 -1
- data/gemfiles/rails_6.0.gemfile +3 -3
- data/gemfiles/rails_6.1.gemfile +3 -3
- data/gemfiles/rails_7.0.gemfile +3 -3
- data/lib/generators/operation/operation_generator.rb +56 -9
- data/lib/generators/operation/templates/controller.erb +34 -23
- data/lib/generators/operation/templates/controller_wrapper.erb +14 -0
- data/lib/rails_ops/authorization_backend/abstract.rb +1 -1
- data/lib/rails_ops/authorization_backend/can_can_can.rb +3 -1
- data/lib/rails_ops/controller_mixin.rb +1 -1
- data/lib/rails_ops/hookup/dsl_validator.rb +2 -1
- data/lib/rails_ops/hookup.rb +1 -1
- data/lib/rails_ops/mixins/authorization.rb +2 -2
- data/lib/rails_ops/mixins/model/nesting.rb +22 -23
- data/lib/rails_ops/mixins/policies.rb +7 -7
- data/lib/rails_ops/mixins/routes.rb +1 -1
- data/lib/rails_ops/model_mixins/marshalling.rb +1 -1
- data/lib/rails_ops/operation/model/load.rb +2 -4
- data/lib/rails_ops/operation/model/update.rb +2 -2
- data/lib/rails_ops/operation/model.rb +1 -1
- data/lib/rails_ops/operation.rb +7 -4
- data/lib/rails_ops/profiler/node.rb +1 -1
- data/lib/rails_ops/profiler.rb +1 -1
- data/lib/rails_ops.rb +43 -43
- data/rails_ops.gemspec +5 -5
- data/test/dummy/bin/bundle +1 -1
- data/test/dummy/bin/setup +1 -1
- data/test/dummy/bin/update +1 -1
- data/test/dummy/bin/yarn +5 -7
- data/test/dummy/config/environments/production.rb +1 -1
- data/test/dummy/config/spring.rb +2 -2
- data/test/test_helper.rb +5 -5
- data/test/unit/rails_ops/generators/operation_generator_test.rb +108 -12
- data/test/unit/rails_ops/mixins/model/deep_nesting_test.rb +69 -10
- data/test/unit/rails_ops/mixins/param_authorization_test.rb +3 -3
- data/test/unit/rails_ops/mixins/policies_test.rb +2 -2
- data/test/unit/rails_ops/operation/update_auth_test.rb +2 -0
- data/test/unit/rails_ops/operation/update_lazy_auth_test.rb +1 -0
- data/test/unit/rails_ops/operation_test.rb +1 -1
- metadata +12 -11
@@ -10,12 +10,10 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
10
10
|
|
11
11
|
# Add an empty routes file
|
12
12
|
Dir.mkdir(File.join(destination_root, 'config'))
|
13
|
-
File.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ROUTES
|
18
|
-
end
|
13
|
+
File.write(File.join(destination_root, 'config', 'routes.rb'), <<~ROUTES)
|
14
|
+
Rails.application.routes.draw do
|
15
|
+
end
|
16
|
+
ROUTES
|
19
17
|
end
|
20
18
|
|
21
19
|
def test_all
|
@@ -34,6 +32,104 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
34
32
|
assert_routes
|
35
33
|
end
|
36
34
|
|
35
|
+
def test_no_index_action
|
36
|
+
run_generator ['User', '--skip-index']
|
37
|
+
|
38
|
+
# Check that the index view is not created
|
39
|
+
assert_no_file 'app/views/users/index.html.haml'
|
40
|
+
|
41
|
+
# Check that the index route is not created
|
42
|
+
assert_file 'config/routes.rb' do |routes|
|
43
|
+
assert_match(/resources :users, except: \[:index\]/, routes)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Check that the controller action is not created
|
47
|
+
assert_file 'app/controllers/users_controller.rb' do |controller|
|
48
|
+
assert_no_match(/def index/, controller)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_no_show_action
|
53
|
+
run_generator ['User', '--skip-show']
|
54
|
+
|
55
|
+
# Check that the show view is not created
|
56
|
+
assert_no_file 'app/views/users/show.html.haml'
|
57
|
+
|
58
|
+
# Check that the show route is not created
|
59
|
+
assert_file 'config/routes.rb' do |routes|
|
60
|
+
assert_match(/resources :users, except: \[:show\]/, routes)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Check that the controller action is not created
|
64
|
+
assert_file 'app/controllers/users_controller.rb' do |controller|
|
65
|
+
assert_no_match(/def show/, controller)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Check that the load operation is not created
|
69
|
+
assert_no_file 'app/operations/users/load.rb'
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_no_create_action
|
73
|
+
run_generator ['User', '--skip-create']
|
74
|
+
|
75
|
+
# Check that the new and create view are not created
|
76
|
+
assert_no_file 'app/views/users/new.html.haml'
|
77
|
+
assert_no_file 'app/views/users/create.html.haml'
|
78
|
+
|
79
|
+
# Check that the new, create route is not created
|
80
|
+
assert_file 'config/routes.rb' do |routes|
|
81
|
+
assert_match(/resources :users, except: \[:new, :create\]/, routes)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Check that the controller actions are not created
|
85
|
+
assert_file 'app/controllers/users_controller.rb' do |controller|
|
86
|
+
assert_no_match(/def new/, controller)
|
87
|
+
assert_no_match(/def create/, controller)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Check that the load operation is not created
|
91
|
+
assert_no_file 'app/operations/users/create.rb'
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_no_update_action
|
95
|
+
run_generator ['User', '--skip-update']
|
96
|
+
|
97
|
+
# Check that the edit and update view are not created
|
98
|
+
assert_no_file 'app/views/users/edit.html.haml'
|
99
|
+
assert_no_file 'app/views/users/update.html.haml'
|
100
|
+
|
101
|
+
# Check that the edit, update route is not created
|
102
|
+
assert_file 'config/routes.rb' do |routes|
|
103
|
+
assert_match(/resources :users, except: \[:edit, :update\]/, routes)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Check that the controller actions are not created
|
107
|
+
assert_file 'app/controllers/users_controller.rb' do |controller|
|
108
|
+
assert_no_match(/def edit/, controller)
|
109
|
+
assert_no_match(/def update/, controller)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Check that the load operation is not created
|
113
|
+
assert_no_file 'app/operations/users/update.rb'
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_no_destory_action
|
117
|
+
run_generator ['User', '--skip-destroy']
|
118
|
+
|
119
|
+
# Check that the destroy view is not created
|
120
|
+
assert_no_file 'app/views/users/destroy.html.haml'
|
121
|
+
|
122
|
+
# Check that the destroy route is not created
|
123
|
+
assert_file 'config/routes.rb' do |routes|
|
124
|
+
assert_match(/resources :users, except: \[:destroy\]/, routes)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Check that the controller action is not created
|
128
|
+
assert_file 'app/controllers/users_controller.rb' do |controller|
|
129
|
+
assert_no_match(/def destroy/, controller)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
37
133
|
def test_no_views
|
38
134
|
run_generator ['User', '--skip-views']
|
39
135
|
|
@@ -42,7 +138,7 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
42
138
|
assert_routes
|
43
139
|
|
44
140
|
# Check that the views were skipped
|
45
|
-
%w
|
141
|
+
%w[index show new edit].each do |view|
|
46
142
|
assert_no_file "app/views/users/#{view}.html.haml"
|
47
143
|
end
|
48
144
|
end
|
@@ -85,7 +181,7 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
85
181
|
end
|
86
182
|
|
87
183
|
# Check that the views were skipped
|
88
|
-
%w
|
184
|
+
%w[index show new edit].each do |view|
|
89
185
|
assert_no_file "app/views/users/#{view}.html.haml"
|
90
186
|
end
|
91
187
|
end
|
@@ -104,7 +200,7 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
104
200
|
end
|
105
201
|
|
106
202
|
# Check that the views were skipped
|
107
|
-
%w
|
203
|
+
%w[index show new edit].each do |view|
|
108
204
|
assert_no_file "app/views/users/#{view}.html.haml"
|
109
205
|
end
|
110
206
|
end
|
@@ -154,7 +250,7 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
154
250
|
end
|
155
251
|
|
156
252
|
# Check that views are generated
|
157
|
-
%w
|
253
|
+
%w[index show new edit].each do |view|
|
158
254
|
assert_file "app/views/admin/users/#{view}.html.haml"
|
159
255
|
end
|
160
256
|
|
@@ -195,7 +291,7 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
195
291
|
end
|
196
292
|
|
197
293
|
# Check that views are generated
|
198
|
-
%w
|
294
|
+
%w[index show new edit].each do |view|
|
199
295
|
assert_file "app/views/admin/foo/users/#{view}.html.haml"
|
200
296
|
end
|
201
297
|
|
@@ -235,7 +331,7 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
235
331
|
end
|
236
332
|
|
237
333
|
def assert_views
|
238
|
-
%w
|
334
|
+
%w[index show new edit].each do |view|
|
239
335
|
assert_file "app/views/users/#{view}.html.haml"
|
240
336
|
end
|
241
337
|
end
|
@@ -25,6 +25,28 @@ class RailsOps::Mixins::Model::DeepNestingTest < ActiveSupport::TestCase
|
|
25
25
|
nest_model_op :mainboard, MAINBOARD_CREATION_OP
|
26
26
|
end
|
27
27
|
|
28
|
+
CPU_UPDATE_OP = Class.new(RailsOps::Operation::Model::Update) do
|
29
|
+
model Cpu do
|
30
|
+
validates :name, presence: true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
MAINBOARD_UPDATE_OP = Class.new(RailsOps::Operation::Model::Update) do
|
35
|
+
model Mainboard do
|
36
|
+
validates :name, presence: true
|
37
|
+
end
|
38
|
+
|
39
|
+
nest_model_op :cpu, CPU_UPDATE_OP
|
40
|
+
end
|
41
|
+
|
42
|
+
COMPUTER_UPDATE_OP = Class.new(RailsOps::Operation::Model::Update) do
|
43
|
+
model Computer do
|
44
|
+
validates :name, presence: true
|
45
|
+
end
|
46
|
+
|
47
|
+
nest_model_op :mainboard, MAINBOARD_UPDATE_OP
|
48
|
+
end
|
49
|
+
|
28
50
|
def test_create_cpu
|
29
51
|
assert_nothing_raised do
|
30
52
|
CPU_CREATION_OP.run!(cpu: { name: 'CPU' })
|
@@ -35,7 +57,7 @@ class RailsOps::Mixins::Model::DeepNestingTest < ActiveSupport::TestCase
|
|
35
57
|
assert_nothing_raised do
|
36
58
|
MAINBOARD_CREATION_OP.run!(
|
37
59
|
mainboard: {
|
38
|
-
name:
|
60
|
+
name: 'Mainboard',
|
39
61
|
cpu_attributes: {
|
40
62
|
name: 'CPU'
|
41
63
|
}
|
@@ -48,10 +70,10 @@ class RailsOps::Mixins::Model::DeepNestingTest < ActiveSupport::TestCase
|
|
48
70
|
model = assert_nothing_raised do
|
49
71
|
COMPUTER_CREATION_OP.run!(
|
50
72
|
computer: {
|
51
|
-
name:
|
73
|
+
name: 'Computer',
|
52
74
|
|
53
75
|
mainboard_attributes: {
|
54
|
-
name:
|
76
|
+
name: 'Mainboard',
|
55
77
|
|
56
78
|
cpu_attributes: {
|
57
79
|
name: 'CPU'
|
@@ -74,7 +96,7 @@ class RailsOps::Mixins::Model::DeepNestingTest < ActiveSupport::TestCase
|
|
74
96
|
op = COMPUTER_CREATION_OP.new(
|
75
97
|
computer: {
|
76
98
|
mainboard_attributes: {
|
77
|
-
name:
|
99
|
+
name: 'Mainboard',
|
78
100
|
|
79
101
|
cpu_attributes: {
|
80
102
|
name: 'CPU'
|
@@ -94,7 +116,7 @@ class RailsOps::Mixins::Model::DeepNestingTest < ActiveSupport::TestCase
|
|
94
116
|
def test_create_computer_level_2_validation_error
|
95
117
|
op = COMPUTER_CREATION_OP.new(
|
96
118
|
computer: {
|
97
|
-
name:
|
119
|
+
name: 'Computer',
|
98
120
|
|
99
121
|
mainboard_attributes: {
|
100
122
|
cpu_attributes: {
|
@@ -108,7 +130,7 @@ class RailsOps::Mixins::Model::DeepNestingTest < ActiveSupport::TestCase
|
|
108
130
|
op.run!
|
109
131
|
end
|
110
132
|
|
111
|
-
assert_equal [
|
133
|
+
assert_equal ['Mainboard is invalid'], op.model.errors.full_messages
|
112
134
|
refute op.model.persisted?
|
113
135
|
|
114
136
|
assert_equal ["Name can't be blank"], op.model.mainboard.errors.full_messages
|
@@ -118,10 +140,10 @@ class RailsOps::Mixins::Model::DeepNestingTest < ActiveSupport::TestCase
|
|
118
140
|
def test_create_computer_level_3_validation_error
|
119
141
|
op = COMPUTER_CREATION_OP.new(
|
120
142
|
computer: {
|
121
|
-
name:
|
143
|
+
name: 'Computer',
|
122
144
|
|
123
145
|
mainboard_attributes: {
|
124
|
-
name:
|
146
|
+
name: 'Mainboard',
|
125
147
|
|
126
148
|
cpu_attributes: {}
|
127
149
|
}
|
@@ -132,13 +154,50 @@ class RailsOps::Mixins::Model::DeepNestingTest < ActiveSupport::TestCase
|
|
132
154
|
op.run!
|
133
155
|
end
|
134
156
|
|
135
|
-
assert_equal [
|
157
|
+
assert_equal ['Mainboard is invalid'], op.model.errors.full_messages
|
136
158
|
refute op.model.persisted?
|
137
159
|
|
138
|
-
assert_equal [
|
160
|
+
assert_equal ['Cpu is invalid'], op.model.mainboard.errors.full_messages
|
139
161
|
refute op.model.mainboard.persisted?
|
140
162
|
|
141
163
|
assert_equal ["Name can't be blank"], op.model.mainboard.cpu.errors.full_messages
|
142
164
|
refute op.model.mainboard.cpu.persisted?
|
143
165
|
end
|
166
|
+
|
167
|
+
def test_update_validation_error
|
168
|
+
create_op = COMPUTER_CREATION_OP.new(
|
169
|
+
computer: {
|
170
|
+
name: 'Computer',
|
171
|
+
|
172
|
+
mainboard_attributes: {
|
173
|
+
name: 'Mainboard',
|
174
|
+
|
175
|
+
cpu_attributes: {
|
176
|
+
name: 'CPU'
|
177
|
+
}
|
178
|
+
}
|
179
|
+
}
|
180
|
+
)
|
181
|
+
|
182
|
+
create_op.run!
|
183
|
+
|
184
|
+
update_op = COMPUTER_UPDATE_OP.new(
|
185
|
+
id: Computer.first,
|
186
|
+
computer: {
|
187
|
+
name: 'Computer',
|
188
|
+
|
189
|
+
mainboard_attributes: {
|
190
|
+
name: '',
|
191
|
+
|
192
|
+
cpu_attributes: {
|
193
|
+
name: 'CPU'
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
)
|
198
|
+
|
199
|
+
refute update_op.run
|
200
|
+
assert_equal :name, update_op.model.mainboard.errors.first.attribute
|
201
|
+
assert_equal :blank, update_op.model.mainboard.errors.first.type
|
202
|
+
end
|
144
203
|
end
|
@@ -32,9 +32,9 @@ class RailsOps::Mixins::ParamAuthorizationTest < ActiveSupport::TestCase
|
|
32
32
|
|
33
33
|
model ::Group
|
34
34
|
|
35
|
-
authorize_param %i
|
36
|
-
authorize_param %i
|
37
|
-
authorize_param %i
|
35
|
+
authorize_param %i[foo], :foo, :subject_1
|
36
|
+
authorize_param %i[bar], :bar, :subject_1
|
37
|
+
authorize_param %i[bar baz], :baz, :subject_1
|
38
38
|
|
39
39
|
def perform
|
40
40
|
# Do nothing
|
@@ -29,7 +29,7 @@ class RailsOps::Mixins::PoliciesTest < ActiveSupport::TestCase
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
assert_equal %i
|
32
|
+
assert_equal %i[on_init default before_perform perform after_perform],
|
33
33
|
op.run!.sequence
|
34
34
|
end
|
35
35
|
|
@@ -52,7 +52,7 @@ class RailsOps::Mixins::PoliciesTest < ActiveSupport::TestCase
|
|
52
52
|
def perform; end
|
53
53
|
end
|
54
54
|
|
55
|
-
assert_equal %i
|
55
|
+
assert_equal %i[before_perform_1 before_perform_2],
|
56
56
|
op.run!.sequence
|
57
57
|
end
|
58
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_ops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - '='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 1.45.1
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - '='
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 1.45.1
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: sprockets-rails
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,8 +212,8 @@ dependencies:
|
|
212
212
|
- - "<="
|
213
213
|
- !ruby/object:Gem::Version
|
214
214
|
version: '3.1'
|
215
|
-
description:
|
216
|
-
email:
|
215
|
+
description:
|
216
|
+
email:
|
217
217
|
executables: []
|
218
218
|
extensions: []
|
219
219
|
extra_rdoc_files: []
|
@@ -236,6 +236,7 @@ files:
|
|
236
236
|
- lib/generators/operation/USAGE
|
237
237
|
- lib/generators/operation/operation_generator.rb
|
238
238
|
- lib/generators/operation/templates/controller.erb
|
239
|
+
- lib/generators/operation/templates/controller_wrapper.erb
|
239
240
|
- lib/generators/operation/templates/create.erb
|
240
241
|
- lib/generators/operation/templates/destroy.erb
|
241
242
|
- lib/generators/operation/templates/load.erb
|
@@ -373,10 +374,10 @@ files:
|
|
373
374
|
- test/unit/rails_ops/operation/update_auth_test.rb
|
374
375
|
- test/unit/rails_ops/operation/update_lazy_auth_test.rb
|
375
376
|
- test/unit/rails_ops/operation_test.rb
|
376
|
-
homepage:
|
377
|
+
homepage:
|
377
378
|
licenses: []
|
378
379
|
metadata: {}
|
379
|
-
post_install_message:
|
380
|
+
post_install_message:
|
380
381
|
rdoc_options: []
|
381
382
|
require_paths:
|
382
383
|
- lib
|
@@ -391,8 +392,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
391
392
|
- !ruby/object:Gem::Version
|
392
393
|
version: '0'
|
393
394
|
requirements: []
|
394
|
-
rubygems_version: 3.
|
395
|
-
signing_key:
|
395
|
+
rubygems_version: 3.4.6
|
396
|
+
signing_key:
|
396
397
|
specification_version: 4
|
397
398
|
summary: An operations service layer for rails projects.
|
398
399
|
test_files:
|