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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +102 -11
  3. data/Appraisals +11 -11
  4. data/CHANGELOG.md +18 -0
  5. data/README.md +12 -2
  6. data/Rakefile +3 -5
  7. data/VERSION +1 -1
  8. data/gemfiles/rails_6.0.gemfile +3 -3
  9. data/gemfiles/rails_6.1.gemfile +3 -3
  10. data/gemfiles/rails_7.0.gemfile +3 -3
  11. data/lib/generators/operation/operation_generator.rb +56 -9
  12. data/lib/generators/operation/templates/controller.erb +34 -23
  13. data/lib/generators/operation/templates/controller_wrapper.erb +14 -0
  14. data/lib/rails_ops/authorization_backend/abstract.rb +1 -1
  15. data/lib/rails_ops/authorization_backend/can_can_can.rb +3 -1
  16. data/lib/rails_ops/controller_mixin.rb +1 -1
  17. data/lib/rails_ops/hookup/dsl_validator.rb +2 -1
  18. data/lib/rails_ops/hookup.rb +1 -1
  19. data/lib/rails_ops/mixins/authorization.rb +2 -2
  20. data/lib/rails_ops/mixins/model/nesting.rb +22 -23
  21. data/lib/rails_ops/mixins/policies.rb +7 -7
  22. data/lib/rails_ops/mixins/routes.rb +1 -1
  23. data/lib/rails_ops/model_mixins/marshalling.rb +1 -1
  24. data/lib/rails_ops/operation/model/load.rb +2 -4
  25. data/lib/rails_ops/operation/model/update.rb +2 -2
  26. data/lib/rails_ops/operation/model.rb +1 -1
  27. data/lib/rails_ops/operation.rb +7 -4
  28. data/lib/rails_ops/profiler/node.rb +1 -1
  29. data/lib/rails_ops/profiler.rb +1 -1
  30. data/lib/rails_ops.rb +43 -43
  31. data/rails_ops.gemspec +5 -5
  32. data/test/dummy/bin/bundle +1 -1
  33. data/test/dummy/bin/setup +1 -1
  34. data/test/dummy/bin/update +1 -1
  35. data/test/dummy/bin/yarn +5 -7
  36. data/test/dummy/config/environments/production.rb +1 -1
  37. data/test/dummy/config/spring.rb +2 -2
  38. data/test/test_helper.rb +5 -5
  39. data/test/unit/rails_ops/generators/operation_generator_test.rb +108 -12
  40. data/test/unit/rails_ops/mixins/model/deep_nesting_test.rb +69 -10
  41. data/test/unit/rails_ops/mixins/param_authorization_test.rb +3 -3
  42. data/test/unit/rails_ops/mixins/policies_test.rb +2 -2
  43. data/test/unit/rails_ops/operation/update_auth_test.rb +2 -0
  44. data/test/unit/rails_ops/operation/update_lazy_auth_test.rb +1 -0
  45. data/test/unit/rails_ops/operation_test.rb +1 -1
  46. 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.open(File.join(destination_root, 'config', 'routes.rb'), 'w') do |f|
14
- f.write <<~ROUTES
15
- Rails.application.routes.draw do
16
- end
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(index show new edit).each do |view|
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(index show new edit).each do |view|
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(index show new edit).each do |view|
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(index show new edit).each do |view|
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(index show new edit).each do |view|
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(index show new edit).each do |view|
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: 'Mainboard',
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: 'Computer',
73
+ name: 'Computer',
52
74
 
53
75
  mainboard_attributes: {
54
- name: 'Mainboard',
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: 'Mainboard',
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: 'Computer',
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 ["Mainboard is invalid"], op.model.errors.full_messages
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: 'Computer',
143
+ name: 'Computer',
122
144
 
123
145
  mainboard_attributes: {
124
- name: 'Mainboard',
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 ["Mainboard is invalid"], op.model.errors.full_messages
157
+ assert_equal ['Mainboard is invalid'], op.model.errors.full_messages
136
158
  refute op.model.persisted?
137
159
 
138
- assert_equal ["Cpu is invalid"], op.model.mainboard.errors.full_messages
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(foo), :foo, :subject_1
36
- authorize_param %i(bar), :bar, :subject_1
37
- authorize_param %i(bar baz), :baz, :subject_1
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(on_init default before_perform perform after_perform),
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(before_perform_1 before_perform_2),
55
+ assert_equal %i[before_perform_1 before_perform_2],
56
56
  op.run!.sequence
57
57
  end
58
58
  end
@@ -20,6 +20,8 @@ class RailsOps::Operation::UpdateLazyAuthTest < ActiveSupport::TestCase
20
20
  include CanCan::Ability
21
21
 
22
22
  def initialize(read: false, update: false)
23
+ super()
24
+
23
25
  can :read, Group if read
24
26
  can :update, Group if update
25
27
  end
@@ -20,6 +20,7 @@ class RailsOps::Operation::UpdateLazyAuthTest < ActiveSupport::TestCase
20
20
  include CanCan::Ability
21
21
 
22
22
  def initialize(read: false, update: false)
23
+ super()
23
24
  can :read, Group if read
24
25
  can :update, Group if update
25
26
  end
@@ -99,7 +99,7 @@ class RailsOps::OperationTest < ActiveSupport::TestCase
99
99
  end
100
100
 
101
101
  def test_params
102
- params = { a: 1, 'b': 1 }
102
+ params = { a: 1, b: 1 }
103
103
  op = BASIC_OP.new(params)
104
104
 
105
105
  # ---------------------------------------------------------------
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.1
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-02-21 00:00:00.000000000 Z
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: 0.47.1
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: 0.47.1
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.0.3.1
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: