rails_ops 1.1.25 → 1.1.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop.yml +17 -0
- data/.github/workflows/ruby.yml +37 -7
- data/.gitignore +1 -0
- data/Appraisals +19 -0
- data/CHANGELOG.md +18 -0
- data/README.md +56 -12
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/gemfiles/rails_5.1.gemfile +7 -0
- data/gemfiles/rails_5.2.gemfile +7 -0
- data/gemfiles/rails_6.0.gemfile +7 -0
- data/gemfiles/rails_6.1.gemfile +7 -0
- data/gemfiles/rails_7.0.gemfile +7 -0
- data/lib/generators/operation/operation_generator.rb +21 -3
- data/lib/generators/operation/templates/controller.erb +24 -7
- data/lib/generators/operation/templates/create.erb +4 -0
- data/lib/generators/operation/templates/destroy.erb +4 -0
- data/lib/generators/operation/templates/load.erb +8 -0
- data/lib/generators/operation/templates/update.erb +4 -0
- data/lib/rails_ops/mixins/model/authorization.rb +1 -3
- data/lib/rails_ops/model_mixins/sti_fixes.rb +2 -6
- data/lib/rails_ops/model_mixins/virtual_attributes/virtual_column_wrapper.rb +4 -0
- data/lib/rails_ops/operation/model.rb +5 -0
- data/lib/rails_ops.rb +1 -13
- data/rails_ops.gemspec +7 -5
- data/test/dummy/config/application.rb +1 -1
- data/test/unit/rails_ops/generators/operation_generator_test.rb +84 -0
- data/test/unit/rails_ops/operation/model/create_test.rb +16 -0
- data/test/unit/rails_ops/operation/model/sti_test.rb +56 -0
- data/test/unit/rails_ops/operation/model/update_test.rb +45 -0
- metadata +30 -11
- data/lib/rails_ops/model_casting.rb +0 -17
- data/lib/rails_ops/patches/active_type_patch.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f12f6449ae4bdcbe6509a31d3cb0fa3539611a1dea21a94ff2bc21c2764ab609
|
4
|
+
data.tar.gz: 0a222457b0adada36f507b56ca3dbca67ddd8f9ca1852fe22cdd0b899d8663f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5ed687a7bb61559bbac689e6dfa7957d8f0d7a442ac44b5e80de1b318467361949e3fe2490c2daa38e0e75b026d46d57c785bb9e63436d5603c167f916d5973
|
7
|
+
data.tar.gz: 8ce961274235ad11ded68887ecae99cd623f100a5f8facf3332f7a21b516555c7b8651a8e75aa30188579dfe9a7f8e384b41a01744feb08099f3eb31b001ebbf
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: Rubocop check
|
2
|
+
on: push
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
verify:
|
6
|
+
name: Test
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v1
|
11
|
+
- name: Set up Ruby
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 3.0.1
|
15
|
+
bundler-cache: true
|
16
|
+
- name: Run rubocop
|
17
|
+
run: bundle exec rubocop
|
data/.github/workflows/ruby.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
name:
|
1
|
+
name: Unit tests
|
2
2
|
|
3
3
|
on:
|
4
4
|
push:
|
@@ -12,16 +12,46 @@ jobs:
|
|
12
12
|
strategy:
|
13
13
|
fail-fast: false
|
14
14
|
matrix:
|
15
|
-
|
16
|
-
|
15
|
+
include:
|
16
|
+
- rails-version: '5.1'
|
17
|
+
ruby-version: '2.3.0'
|
18
|
+
- rails-version: '5.1'
|
19
|
+
ruby-version: '2.5.1'
|
20
|
+
- rails-version: '5.2'
|
21
|
+
ruby-version: '2.3.0'
|
22
|
+
- rails-version: '5.2'
|
23
|
+
ruby-version: '2.5.1'
|
24
|
+
- rails-version: '5.2'
|
25
|
+
ruby-version: '2.6.2'
|
26
|
+
- rails-version: '6.0'
|
27
|
+
ruby-version: '2.5.1'
|
28
|
+
- rails-version: '6.0'
|
29
|
+
ruby-version: '2.6.2'
|
30
|
+
- rails-version: '6.0'
|
31
|
+
ruby-version: '2.7.1'
|
32
|
+
- rails-version: '6.1'
|
33
|
+
ruby-version: '2.5.1'
|
34
|
+
- rails-version: '6.1'
|
35
|
+
ruby-version: '2.6.2'
|
36
|
+
- rails-version: '6.1'
|
37
|
+
ruby-version: '2.7.1'
|
38
|
+
- rails-version: '6.1'
|
39
|
+
ruby-version: '3.0.1'
|
40
|
+
- rails-version: '7.0'
|
41
|
+
ruby-version: '2.7.1'
|
42
|
+
- rails-version: '7.0'
|
43
|
+
ruby-version: '3.0.1'
|
44
|
+
- rails-version: '7.0'
|
45
|
+
ruby-version: '3.1.0'
|
46
|
+
name: Test against Ruby ${{ matrix.ruby-version }} / Rails ${{ matrix.rails-version }}
|
47
|
+
env:
|
48
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails-version }}.gemfile
|
17
49
|
steps:
|
18
50
|
- uses: actions/checkout@v2
|
19
|
-
- name: Set up Ruby
|
51
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
20
52
|
uses: ruby/setup-ruby@v1
|
21
53
|
with:
|
22
54
|
ruby-version: ${{ matrix.ruby-version }}
|
23
55
|
bundler-cache: true
|
24
56
|
- name: Run rake tests
|
25
|
-
run: bundle exec rake
|
26
|
-
- name: Run rubocop
|
27
|
-
run: bundle exec rubocop
|
57
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
appraise "rails-7.0" do
|
2
|
+
gem "rails", "~> 7.0.1"
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "rails-6.1" do
|
6
|
+
gem "rails", "~> 6.1.4"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "rails-6.0" do
|
10
|
+
gem "rails", "~> 6.0.4"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "rails-5.2" do
|
14
|
+
gem "rails", "~> 5.2.6"
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "rails-5.1" do
|
18
|
+
gem "rails", "~> 5.1.7"
|
19
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.1.29 (2022-02-17)
|
4
|
+
|
5
|
+
* Fix sti type not correct on creating of record
|
6
|
+
|
7
|
+
## 1.1.28 (2022-02-16)
|
8
|
+
|
9
|
+
* [#22](https://github.com/sitrox/rails_ops/issues/22): Fix error with active_type `>= 2`
|
10
|
+
|
11
|
+
## 1.1.27 (2022-02-15)
|
12
|
+
|
13
|
+
* Add `module` option to `operation` generator
|
14
|
+
|
15
|
+
## 1.1.26 (2022-01-18)
|
16
|
+
|
17
|
+
* #25: Add test matrix for unit tests
|
18
|
+
|
19
|
+
* Add compatibility for Rails 7 and Ruby 3.1.0
|
20
|
+
|
3
21
|
## 1.1.25 (2022-01-17)
|
4
22
|
|
5
23
|
* #24: Add generator `operation` that generates a controller, operations and empty
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
[![
|
1
|
+
[![Unit tests](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml/badge.svg)](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml)
|
2
|
+
[![Rubocop check](https://github.com/sitrox/rails_ops/actions/workflows/rubocop.yml/badge.svg)](https://github.com/sitrox/rails_ops/actions/workflows/rubocop.yml)
|
2
3
|
[![Gem Version](https://badge.fury.io/rb/rails_ops.svg)](https://badge.fury.io/rb/rails_ops)
|
3
4
|
|
4
5
|
rails_ops
|
@@ -22,9 +23,21 @@ Requirements & Installation
|
|
22
23
|
|
23
24
|
### Requirements
|
24
25
|
|
25
|
-
- RailsOps only works with Rails applications
|
26
|
-
|
27
|
-
|
26
|
+
- RailsOps only works with Rails applications, with the following Rails versions being tested in the CI:
|
27
|
+
* Rails 5.1.x
|
28
|
+
* Rails 5.2.x
|
29
|
+
* Rails 6.0.x
|
30
|
+
* Rails 6.1.x
|
31
|
+
* Rails 7.0.x
|
32
|
+
- Additionally, the following Ruby versions are covered by our unit tests:
|
33
|
+
* 2.3.0
|
34
|
+
* 2.5.1
|
35
|
+
* 2.6.2
|
36
|
+
* 2.7.1
|
37
|
+
* 3.0.1
|
38
|
+
* 3.1.0
|
39
|
+
- Please see the [unit test workflow](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml) for the combinations of the Rails & Ruby versions, as only compatible versions are tested with each other.
|
40
|
+
- Prior Rails and Ruby versions may be supported but they are not tested in the CI.
|
28
41
|
- Rails Ops' model operations require ActiveRecord but are database / adapter
|
29
42
|
agnostic
|
30
43
|
|
@@ -54,15 +67,16 @@ Requirements & Installation
|
|
54
67
|
following inside of the `Application` class within your
|
55
68
|
`config/application.rb`:
|
56
69
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
70
|
+
```ruby
|
71
|
+
app_operations = "#{Rails.root}/app/operations"
|
72
|
+
ActiveSupport::Dependencies.autoload_paths.delete(app_operations)
|
73
|
+
|
74
|
+
module Operations; end
|
75
|
+
loader = Rails.autoloaders.main
|
76
|
+
loader.push_dir(app_operations, namespace: Operations)
|
77
|
+
```
|
61
78
|
|
62
|
-
|
63
|
-
# that will run when loaded.
|
64
|
-
config.paths.add 'lib', eager_load: true
|
65
|
-
```
|
79
|
+
Taken from [this github issues comment](https://github.com/rails/rails/issues/40126#issuecomment-816275285).
|
66
80
|
|
67
81
|
Operation Basics
|
68
82
|
----------------
|
@@ -1533,6 +1547,36 @@ flags:
|
|
1533
1547
|
|
1534
1548
|
Or if you want to skip them all: `--only-operations`.
|
1535
1549
|
|
1550
|
+
You can also add a module as a namespace, all generated files will be put in
|
1551
|
+
the proper subfolders and modules by using the `--module` option.
|
1552
|
+
|
1553
|
+
As an example:
|
1554
|
+
|
1555
|
+
```ruby
|
1556
|
+
rails g operation User --module Admin
|
1557
|
+
```
|
1558
|
+
|
1559
|
+
This will generate the following operations:
|
1560
|
+
|
1561
|
+
* `app/operations/admin/user/load.rb`
|
1562
|
+
* `app/operations/admin/user/create.rb`
|
1563
|
+
* `app/operations/admin/user/update.rb`
|
1564
|
+
* `app/operations/admin/user/destroy.rb`
|
1565
|
+
|
1566
|
+
These operations will be namespaced in the `Admin` module, e.g. `app/operations/admin/user/load.rb` will define `Operations::Admin::User::Load`.
|
1567
|
+
|
1568
|
+
It will also generate the controller `app/controllers/admin/users_controller.rb` and the following
|
1569
|
+
empty view files:
|
1570
|
+
|
1571
|
+
* `app/views/admin/users/index.html.haml`
|
1572
|
+
* `app/views/admin/users/show.html.haml`
|
1573
|
+
* `app/views/admin/users/new.html.haml`
|
1574
|
+
* `app/views/admin/users/edit.html.haml`
|
1575
|
+
|
1576
|
+
Both lower- and uppercase will generate the same files (i.e. `--module Admin` and `--module admin` are equal).
|
1577
|
+
|
1578
|
+
You can even nest the generated files deeper, `--module Admin::Foo` and `--module admin/foo` will both work.
|
1579
|
+
|
1536
1580
|
Of course, at this point, the operations will need some adaptions, especially the
|
1537
1581
|
[parameter schemas](#validating-params), and the controllers need the logic for the
|
1538
1582
|
success and failure cases, as this depends on your application.
|
data/Rakefile
CHANGED
@@ -15,6 +15,7 @@ task :gemspec do
|
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
16
|
spec.require_paths = ['lib']
|
17
17
|
|
18
|
+
spec.add_development_dependency 'appraisal'
|
18
19
|
spec.add_development_dependency 'bundler'
|
19
20
|
spec.add_development_dependency 'rake'
|
20
21
|
spec.add_development_dependency 'sqlite3'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.29
|
@@ -5,13 +5,23 @@ class OperationGenerator < Rails::Generators::NamedBase
|
|
5
5
|
class_option :skip_views, type: :boolean, desc: "Don't add the views."
|
6
6
|
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
7
7
|
class_option :only_operations, type: :boolean, desc: 'Only add the operations. This is equal to specifying --skip-controller --skip-routes --skip-views'
|
8
|
+
class_option :module, type: :string, desc: 'Add the operations in a module, e.g. "Admin" results in namespacing everything in the Admin module'
|
8
9
|
|
9
10
|
def add_operations
|
10
11
|
@class_name = name.classify
|
11
12
|
@underscored_name = name.underscore
|
12
13
|
@underscored_pluralized_name = name.underscore.pluralize
|
13
14
|
|
14
|
-
operations_path =
|
15
|
+
operations_path = 'app/operations/'
|
16
|
+
|
17
|
+
if options[:module].present?
|
18
|
+
@module_name = options[:module].classify
|
19
|
+
@module_underscored_name = @module_name.underscore
|
20
|
+
|
21
|
+
operations_path += "#{@module_underscored_name}/"
|
22
|
+
end
|
23
|
+
|
24
|
+
operations_path += @underscored_name.to_s
|
15
25
|
|
16
26
|
template 'load.erb', "#{operations_path}/load.rb"
|
17
27
|
template 'create.erb', "#{operations_path}/create.rb"
|
@@ -22,7 +32,11 @@ class OperationGenerator < Rails::Generators::NamedBase
|
|
22
32
|
def add_controller
|
23
33
|
return if options[:skip_controller] || options[:only_operations]
|
24
34
|
|
25
|
-
controller_file_path =
|
35
|
+
controller_file_path = 'app/controllers/'
|
36
|
+
if @module_underscored_name.present?
|
37
|
+
controller_file_path += "#{@module_underscored_name}/"
|
38
|
+
end
|
39
|
+
controller_file_path += "#{@underscored_pluralized_name}_controller.rb"
|
26
40
|
@controller_name = "#{@class_name.pluralize}Controller"
|
27
41
|
|
28
42
|
template 'controller.erb', controller_file_path
|
@@ -31,7 +45,11 @@ class OperationGenerator < Rails::Generators::NamedBase
|
|
31
45
|
def add_views
|
32
46
|
return if options[:skip_views] || options[:only_operations]
|
33
47
|
|
34
|
-
views_folder =
|
48
|
+
views_folder = 'app/views/'
|
49
|
+
if @module_underscored_name.present?
|
50
|
+
views_folder += "#{@module_underscored_name}/"
|
51
|
+
end
|
52
|
+
views_folder += @underscored_pluralized_name.to_s
|
35
53
|
|
36
54
|
%w(index show new edit).each do |view|
|
37
55
|
template 'view.erb', "#{views_folder}/#{view}.html.haml"
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
1
|
+
<%
|
2
|
+
controller_code = <<-RUBY
|
3
|
+
class #{@controller_name} < ApplicationController
|
2
4
|
def index; end
|
3
5
|
|
4
6
|
def show
|
5
|
-
op Operations
|
7
|
+
op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Load
|
6
8
|
end
|
7
9
|
|
8
10
|
def new
|
9
|
-
op Operations
|
11
|
+
op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Create
|
10
12
|
end
|
11
13
|
|
12
14
|
def create
|
13
|
-
if run Operations
|
15
|
+
if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Create
|
14
16
|
# handle successful case
|
15
17
|
else
|
16
18
|
# handle error case
|
@@ -18,11 +20,11 @@ class <%= @controller_name %> < ApplicationController
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def edit
|
21
|
-
op Operations
|
23
|
+
op Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Update
|
22
24
|
end
|
23
25
|
|
24
26
|
def update
|
25
|
-
if run Operations
|
27
|
+
if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Update
|
26
28
|
# handle successful case
|
27
29
|
else
|
28
30
|
# handle error case
|
@@ -30,10 +32,25 @@ class <%= @controller_name %> < ApplicationController
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def destroy
|
33
|
-
if run Operations
|
35
|
+
if run Operations#{ "::#{@module_name}" if @module_name.present? }::#{@class_name}::Destroy
|
34
36
|
# handle successful case
|
35
37
|
else
|
36
38
|
# handle error case
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
42
|
+
RUBY
|
43
|
+
-%>
|
44
|
+
<% if @module_name.present? -%>
|
45
|
+
module <%= @module_name %>
|
46
|
+
<% controller_code.split("\n").each do |line| -%>
|
47
|
+
<% if line.blank? -%>
|
48
|
+
|
49
|
+
<% else -%>
|
50
|
+
<%= line %>
|
51
|
+
<% end -%>
|
52
|
+
<% end -%>
|
53
|
+
end
|
54
|
+
<% else -%>
|
55
|
+
<%= controller_code -%>
|
56
|
+
<% end -%>
|
@@ -1,5 +1,13 @@
|
|
1
|
+
<% if @module_name.present? -%>
|
2
|
+
module Operations::<%= @module_name %>::<%= @class_name %>
|
3
|
+
<% else -%>
|
1
4
|
module Operations::<%= @class_name %>
|
5
|
+
<% end -%>
|
2
6
|
class Load < RailsOps::Operation::Model::Load
|
7
|
+
schema3 do
|
8
|
+
str! :id
|
9
|
+
end
|
10
|
+
|
3
11
|
model ::<%= @class_name %>
|
4
12
|
end
|
5
13
|
end
|
@@ -70,8 +70,6 @@ module RailsOps::Mixins::Model::Authorization
|
|
70
70
|
# Cast {ActiveType::Record} classes or instances to regular AR models in order
|
71
71
|
# for cancan(can) to work properly. Classes and instances that are no active
|
72
72
|
# type records will be returned as-is.
|
73
|
-
#
|
74
|
-
# TODO: Use ModelCasting module instead?
|
75
73
|
def cast_model_for_authorization(model_class_or_instance)
|
76
74
|
if model_class_or_instance.is_a?(Class)
|
77
75
|
if model_class_or_instance.respond_to?(:extended_record_base_class)
|
@@ -80,7 +78,7 @@ module RailsOps::Mixins::Model::Authorization
|
|
80
78
|
return model_class_or_instance
|
81
79
|
end
|
82
80
|
elsif model_class_or_instance.class.respond_to?(:extended_record_base_class)
|
83
|
-
|
81
|
+
model_class_or_instance.becomes(model_class_or_instance.class.extended_record_base_class)
|
84
82
|
else
|
85
83
|
model_class_or_instance
|
86
84
|
end
|
@@ -5,15 +5,11 @@ module RailsOps
|
|
5
5
|
|
6
6
|
class_methods do
|
7
7
|
def finder_needs_type_condition?
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def descendants
|
12
|
-
superclass.descendants
|
8
|
+
base_class.finder_needs_type_condition?
|
13
9
|
end
|
14
10
|
|
15
11
|
def name
|
16
|
-
|
12
|
+
base_class.name
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
@@ -134,6 +134,11 @@ class RailsOps::Operation::Model < RailsOps::Operation
|
|
134
134
|
attributes = attributes.except(*self.class.nested_model_param_keys)
|
135
135
|
end
|
136
136
|
|
137
|
+
# Assign the "type" attribute if we need it
|
138
|
+
if _model_class.superclass.finder_needs_type_condition?
|
139
|
+
attributes[_model_class.inheritance_column] ||= _model_class.superclass.name
|
140
|
+
end
|
141
|
+
|
137
142
|
# Do nothing if there are no attributes to assign
|
138
143
|
return if attributes.nil? || attributes.empty?
|
139
144
|
|
data/lib/rails_ops.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_type'
|
1
2
|
require 'schemacop'
|
2
3
|
require 'request_store'
|
3
4
|
|
@@ -46,18 +47,6 @@ module RailsOps
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
# ---------------------------------------------------------------
|
50
|
-
# Require Gem active_type and monkey patch
|
51
|
-
# ---------------------------------------------------------------
|
52
|
-
require 'active_type'
|
53
|
-
require 'active_type/type_caster'
|
54
|
-
require 'rails_ops/patches/active_type_patch'
|
55
|
-
|
56
|
-
# ---------------------------------------------------------------
|
57
|
-
# Require Schemacop
|
58
|
-
# ---------------------------------------------------------------
|
59
|
-
require 'schemacop'
|
60
|
-
|
61
50
|
# ---------------------------------------------------------------
|
62
51
|
# Require RailsOps
|
63
52
|
# ---------------------------------------------------------------
|
@@ -84,7 +73,6 @@ require 'rails_ops/mixins/require_context.rb'
|
|
84
73
|
require 'rails_ops/mixins/routes.rb'
|
85
74
|
require 'rails_ops/mixins/schema_validation.rb'
|
86
75
|
require 'rails_ops/mixins/sub_ops.rb'
|
87
|
-
require 'rails_ops/model_casting.rb'
|
88
76
|
require 'rails_ops/model_mixins.rb'
|
89
77
|
require 'rails_ops/model_mixins/ar_extension.rb'
|
90
78
|
require 'rails_ops/model_mixins/parent_op.rb'
|
data/rails_ops.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: rails_ops 1.1.
|
2
|
+
# stub: rails_ops 1.1.29 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rails_ops".freeze
|
6
|
-
s.version = "1.1.
|
6
|
+
s.version = "1.1.29"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Sitrox".freeze]
|
11
|
-
s.date = "2022-
|
12
|
-
s.files = [".github/workflows/ruby.yml".freeze, ".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/generators/operation/USAGE".freeze, "lib/generators/operation/operation_generator.rb".freeze, "lib/generators/operation/templates/controller.erb".freeze, "lib/generators/operation/templates/create.erb".freeze, "lib/generators/operation/templates/destroy.erb".freeze, "lib/generators/operation/templates/load.erb".freeze, "lib/generators/operation/templates/update.erb".freeze, "lib/generators/operation/templates/view.erb".freeze, "lib/rails_ops.rb".freeze, "lib/rails_ops/authorization_backend/abstract.rb".freeze, "lib/rails_ops/authorization_backend/can_can_can.rb".freeze, "lib/rails_ops/configuration.rb".freeze, "lib/rails_ops/context.rb".freeze, "lib/rails_ops/controller_mixin.rb".freeze, "lib/rails_ops/exceptions.rb".freeze, "lib/rails_ops/hooked_job.rb".freeze, "lib/rails_ops/hookup.rb".freeze, "lib/rails_ops/hookup/dsl.rb".freeze, "lib/rails_ops/hookup/dsl_validator.rb".freeze, "lib/rails_ops/hookup/hook.rb".freeze, "lib/rails_ops/log_subscriber.rb".freeze, "lib/rails_ops/mixins.rb".freeze, "lib/rails_ops/mixins/authorization.rb".freeze, "lib/rails_ops/mixins/log_settings.rb".freeze, "lib/rails_ops/mixins/model.rb".freeze, "lib/rails_ops/mixins/model/authorization.rb".freeze, "lib/rails_ops/mixins/model/nesting.rb".freeze, "lib/rails_ops/mixins/param_authorization.rb".freeze, "lib/rails_ops/mixins/policies.rb".freeze, "lib/rails_ops/mixins/require_context.rb".freeze, "lib/rails_ops/mixins/routes.rb".freeze, "lib/rails_ops/mixins/schema_validation.rb".freeze, "lib/rails_ops/mixins/sub_ops.rb".freeze, "lib/rails_ops/
|
13
|
-
s.rubygems_version = "3.2
|
11
|
+
s.date = "2022-02-17"
|
12
|
+
s.files = [".github/workflows/rubocop.yml".freeze, ".github/workflows/ruby.yml".freeze, ".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, "Appraisals".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "gemfiles/rails_5.1.gemfile".freeze, "gemfiles/rails_5.2.gemfile".freeze, "gemfiles/rails_6.0.gemfile".freeze, "gemfiles/rails_6.1.gemfile".freeze, "gemfiles/rails_7.0.gemfile".freeze, "lib/generators/operation/USAGE".freeze, "lib/generators/operation/operation_generator.rb".freeze, "lib/generators/operation/templates/controller.erb".freeze, "lib/generators/operation/templates/create.erb".freeze, "lib/generators/operation/templates/destroy.erb".freeze, "lib/generators/operation/templates/load.erb".freeze, "lib/generators/operation/templates/update.erb".freeze, "lib/generators/operation/templates/view.erb".freeze, "lib/rails_ops.rb".freeze, "lib/rails_ops/authorization_backend/abstract.rb".freeze, "lib/rails_ops/authorization_backend/can_can_can.rb".freeze, "lib/rails_ops/configuration.rb".freeze, "lib/rails_ops/context.rb".freeze, "lib/rails_ops/controller_mixin.rb".freeze, "lib/rails_ops/exceptions.rb".freeze, "lib/rails_ops/hooked_job.rb".freeze, "lib/rails_ops/hookup.rb".freeze, "lib/rails_ops/hookup/dsl.rb".freeze, "lib/rails_ops/hookup/dsl_validator.rb".freeze, "lib/rails_ops/hookup/hook.rb".freeze, "lib/rails_ops/log_subscriber.rb".freeze, "lib/rails_ops/mixins.rb".freeze, "lib/rails_ops/mixins/authorization.rb".freeze, "lib/rails_ops/mixins/log_settings.rb".freeze, "lib/rails_ops/mixins/model.rb".freeze, "lib/rails_ops/mixins/model/authorization.rb".freeze, "lib/rails_ops/mixins/model/nesting.rb".freeze, "lib/rails_ops/mixins/param_authorization.rb".freeze, "lib/rails_ops/mixins/policies.rb".freeze, "lib/rails_ops/mixins/require_context.rb".freeze, "lib/rails_ops/mixins/routes.rb".freeze, "lib/rails_ops/mixins/schema_validation.rb".freeze, "lib/rails_ops/mixins/sub_ops.rb".freeze, "lib/rails_ops/model_mixins.rb".freeze, "lib/rails_ops/model_mixins/ar_extension.rb".freeze, "lib/rails_ops/model_mixins/parent_op.rb".freeze, "lib/rails_ops/model_mixins/sti_fixes.rb".freeze, "lib/rails_ops/model_mixins/virtual_attributes.rb".freeze, "lib/rails_ops/model_mixins/virtual_attributes/virtual_column_wrapper.rb".freeze, "lib/rails_ops/model_mixins/virtual_has_one.rb".freeze, "lib/rails_ops/model_mixins/virtual_model_name.rb".freeze, "lib/rails_ops/operation.rb".freeze, "lib/rails_ops/operation/model.rb".freeze, "lib/rails_ops/operation/model/create.rb".freeze, "lib/rails_ops/operation/model/destroy.rb".freeze, "lib/rails_ops/operation/model/load.rb".freeze, "lib/rails_ops/operation/model/update.rb".freeze, "lib/rails_ops/profiler.rb".freeze, "lib/rails_ops/profiler/node.rb".freeze, "lib/rails_ops/railtie.rb".freeze, "lib/rails_ops/scoped_env.rb".freeze, "lib/rails_ops/virtual_model.rb".freeze, "rails_ops.gemspec".freeze, "test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/assets/config/manifest.js".freeze, "test/dummy/app/assets/images/.keep".freeze, "test/dummy/app/assets/javascripts/application.js".freeze, "test/dummy/app/assets/javascripts/cable.js".freeze, "test/dummy/app/assets/javascripts/channels/.keep".freeze, "test/dummy/app/assets/stylesheets/application.css".freeze, "test/dummy/app/channels/application_cable/channel.rb".freeze, "test/dummy/app/channels/application_cable/connection.rb".freeze, "test/dummy/app/controllers/application_controller.rb".freeze, "test/dummy/app/controllers/concerns/.keep".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/jobs/application_job.rb".freeze, "test/dummy/app/mailers/application_mailer.rb".freeze, "test/dummy/app/models/animal.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/bird.rb".freeze, "test/dummy/app/models/cat.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/dog.rb".freeze, "test/dummy/app/models/flower.rb".freeze, "test/dummy/app/models/group.rb".freeze, "test/dummy/app/models/nightingale.rb".freeze, "test/dummy/app/models/phoenix.rb".freeze, "test/dummy/app/models/user.rb".freeze, "test/dummy/app/views/layouts/application.html.erb".freeze, "test/dummy/app/views/layouts/mailer.html.erb".freeze, "test/dummy/app/views/layouts/mailer.text.erb".freeze, "test/dummy/bin/bundle".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/bin/update".freeze, "test/dummy/bin/yarn".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/cable.yml".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/development.rb".freeze, "test/dummy/config/environments/production.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/application_controller_renderer.rb".freeze, "test/dummy/config/initializers/assets.rb".freeze, "test/dummy/config/initializers/backtrace_silencers.rb".freeze, "test/dummy/config/initializers/cookies_serializer.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/mime_types.rb".freeze, "test/dummy/config/initializers/rails_ops.rb".freeze, "test/dummy/config/initializers/wrap_parameters.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/config/secrets.yml".freeze, "test/dummy/config/spring.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/lib/assets/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/package.json".freeze, "test/dummy/public/404.html".freeze, "test/dummy/public/422.html".freeze, "test/dummy/public/500.html".freeze, "test/dummy/public/apple-touch-icon-precomposed.png".freeze, "test/dummy/public/apple-touch-icon.png".freeze, "test/dummy/public/favicon.ico".freeze, "test/dummy/tmp/.keep".freeze, "test/test_helper.rb".freeze, "test/unit/rails_ops/generators/operation_generator_test.rb".freeze, "test/unit/rails_ops/mixins/model/nesting.rb".freeze, "test/unit/rails_ops/mixins/policies_test.rb".freeze, "test/unit/rails_ops/operation/model/create_test.rb".freeze, "test/unit/rails_ops/operation/model/load_test.rb".freeze, "test/unit/rails_ops/operation/model/sti_test.rb".freeze, "test/unit/rails_ops/operation/model/update_test.rb".freeze, "test/unit/rails_ops/operation/model_test.rb".freeze, "test/unit/rails_ops/operation/update_auth_test.rb".freeze, "test/unit/rails_ops/operation/update_lazy_auth_test.rb".freeze, "test/unit/rails_ops/operation_test.rb".freeze]
|
13
|
+
s.rubygems_version = "3.1.2".freeze
|
14
14
|
s.summary = "An operations service layer for rails projects.".freeze
|
15
15
|
s.test_files = ["test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/assets/config/manifest.js".freeze, "test/dummy/app/assets/images/.keep".freeze, "test/dummy/app/assets/javascripts/application.js".freeze, "test/dummy/app/assets/javascripts/cable.js".freeze, "test/dummy/app/assets/javascripts/channels/.keep".freeze, "test/dummy/app/assets/stylesheets/application.css".freeze, "test/dummy/app/channels/application_cable/channel.rb".freeze, "test/dummy/app/channels/application_cable/connection.rb".freeze, "test/dummy/app/controllers/application_controller.rb".freeze, "test/dummy/app/controllers/concerns/.keep".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/jobs/application_job.rb".freeze, "test/dummy/app/mailers/application_mailer.rb".freeze, "test/dummy/app/models/animal.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/bird.rb".freeze, "test/dummy/app/models/cat.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/dog.rb".freeze, "test/dummy/app/models/flower.rb".freeze, "test/dummy/app/models/group.rb".freeze, "test/dummy/app/models/nightingale.rb".freeze, "test/dummy/app/models/phoenix.rb".freeze, "test/dummy/app/models/user.rb".freeze, "test/dummy/app/views/layouts/application.html.erb".freeze, "test/dummy/app/views/layouts/mailer.html.erb".freeze, "test/dummy/app/views/layouts/mailer.text.erb".freeze, "test/dummy/bin/bundle".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/bin/update".freeze, "test/dummy/bin/yarn".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/cable.yml".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/development.rb".freeze, "test/dummy/config/environments/production.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/application_controller_renderer.rb".freeze, "test/dummy/config/initializers/assets.rb".freeze, "test/dummy/config/initializers/backtrace_silencers.rb".freeze, "test/dummy/config/initializers/cookies_serializer.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/mime_types.rb".freeze, "test/dummy/config/initializers/rails_ops.rb".freeze, "test/dummy/config/initializers/wrap_parameters.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/config/secrets.yml".freeze, "test/dummy/config/spring.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/lib/assets/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/package.json".freeze, "test/dummy/public/404.html".freeze, "test/dummy/public/422.html".freeze, "test/dummy/public/500.html".freeze, "test/dummy/public/apple-touch-icon-precomposed.png".freeze, "test/dummy/public/apple-touch-icon.png".freeze, "test/dummy/public/favicon.ico".freeze, "test/dummy/tmp/.keep".freeze, "test/test_helper.rb".freeze, "test/unit/rails_ops/generators/operation_generator_test.rb".freeze, "test/unit/rails_ops/mixins/model/nesting.rb".freeze, "test/unit/rails_ops/mixins/policies_test.rb".freeze, "test/unit/rails_ops/operation/model/create_test.rb".freeze, "test/unit/rails_ops/operation/model/load_test.rb".freeze, "test/unit/rails_ops/operation/model/sti_test.rb".freeze, "test/unit/rails_ops/operation/model/update_test.rb".freeze, "test/unit/rails_ops/operation/model_test.rb".freeze, "test/unit/rails_ops/operation/update_auth_test.rb".freeze, "test/unit/rails_ops/operation/update_lazy_auth_test.rb".freeze, "test/unit/rails_ops/operation_test.rb".freeze]
|
16
16
|
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
if s.respond_to? :add_runtime_dependency then
|
22
|
+
s.add_development_dependency(%q<appraisal>.freeze, [">= 0"])
|
22
23
|
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
23
24
|
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
24
25
|
s.add_development_dependency(%q<sqlite3>.freeze, [">= 0"])
|
@@ -33,6 +34,7 @@ Gem::Specification.new do |s|
|
|
33
34
|
s.add_runtime_dependency(%q<request_store>.freeze, [">= 0"])
|
34
35
|
s.add_runtime_dependency(%q<schemacop>.freeze, [">= 2.4.2", "<= 3.1"])
|
35
36
|
else
|
37
|
+
s.add_dependency(%q<appraisal>.freeze, [">= 0"])
|
36
38
|
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
37
39
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
38
40
|
s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
|
@@ -19,7 +19,7 @@ require 'rails_ops'
|
|
19
19
|
module Dummy
|
20
20
|
class Application < Rails::Application
|
21
21
|
# Initialize configuration defaults for originally generated Rails version.
|
22
|
-
config.load_defaults
|
22
|
+
config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
|
23
23
|
|
24
24
|
# Settings in config/environments/* take precedence over those specified here.
|
25
25
|
# Application configuration should go into files in config/initializers
|
@@ -125,6 +125,90 @@ class OperationGeneratorTest < Rails::Generators::TestCase
|
|
125
125
|
assert_routes
|
126
126
|
end
|
127
127
|
|
128
|
+
def test_module_name
|
129
|
+
optiongroups = [['User', '--module=Admin'], ['User', '--module=admin']]
|
130
|
+
|
131
|
+
optiongroups.each do |optiongroup|
|
132
|
+
run_generator optiongroup
|
133
|
+
|
134
|
+
# Check that namespaced operations are generated
|
135
|
+
assert_file 'app/operations/admin/user/create.rb' do |operation|
|
136
|
+
assert_match(/module Operations::Admin::User/, operation)
|
137
|
+
assert_match(/class Create < RailsOps::Operation::Model::Create/, operation)
|
138
|
+
assert_match(/model ::User/, operation)
|
139
|
+
end
|
140
|
+
assert_file 'app/operations/admin/user/destroy.rb' do |operation|
|
141
|
+
assert_match(/module Operations::Admin::User/, operation)
|
142
|
+
assert_match(/class Destroy < RailsOps::Operation::Model::Destroy/, operation)
|
143
|
+
assert_match(/model ::User/, operation)
|
144
|
+
end
|
145
|
+
assert_file 'app/operations/admin/user/load.rb' do |operation|
|
146
|
+
assert_match(/module Operations::Admin::User/, operation)
|
147
|
+
assert_match(/class Load < RailsOps::Operation::Model::Load/, operation)
|
148
|
+
assert_match(/model ::User/, operation)
|
149
|
+
end
|
150
|
+
assert_file 'app/operations/admin/user/update.rb' do |operation|
|
151
|
+
assert_match(/module Operations::Admin::User/, operation)
|
152
|
+
assert_match(/class Update < RailsOps::Operation::Model::Update/, operation)
|
153
|
+
assert_match(/model ::User/, operation)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Check that views are generated
|
157
|
+
%w(index show new edit).each do |view|
|
158
|
+
assert_file "app/views/admin/users/#{view}.html.haml"
|
159
|
+
end
|
160
|
+
|
161
|
+
# Check that the controller is generated
|
162
|
+
assert_file 'app/controllers/admin/users_controller.rb' do |controller|
|
163
|
+
assert_match(/module Admin/, controller)
|
164
|
+
assert_match(/class UsersController < ApplicationController/, controller)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Check that the routes entry is added
|
168
|
+
assert_routes
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_nested_module_name
|
173
|
+
run_generator ['User', '--module=admin/foo']
|
174
|
+
|
175
|
+
# Check that namespaced operations are generated
|
176
|
+
assert_file 'app/operations/admin/foo/user/create.rb' do |operation|
|
177
|
+
assert_match(/module Operations::Admin::Foo::User/, operation)
|
178
|
+
assert_match(/class Create < RailsOps::Operation::Model::Create/, operation)
|
179
|
+
assert_match(/model ::User/, operation)
|
180
|
+
end
|
181
|
+
assert_file 'app/operations/admin/foo/user/destroy.rb' do |operation|
|
182
|
+
assert_match(/module Operations::Admin::Foo::User/, operation)
|
183
|
+
assert_match(/class Destroy < RailsOps::Operation::Model::Destroy/, operation)
|
184
|
+
assert_match(/model ::User/, operation)
|
185
|
+
end
|
186
|
+
assert_file 'app/operations/admin/foo/user/load.rb' do |operation|
|
187
|
+
assert_match(/module Operations::Admin::Foo::User/, operation)
|
188
|
+
assert_match(/class Load < RailsOps::Operation::Model::Load/, operation)
|
189
|
+
assert_match(/model ::User/, operation)
|
190
|
+
end
|
191
|
+
assert_file 'app/operations/admin/foo/user/update.rb' do |operation|
|
192
|
+
assert_match(/module Operations::Admin::Foo::User/, operation)
|
193
|
+
assert_match(/class Update < RailsOps::Operation::Model::Update/, operation)
|
194
|
+
assert_match(/model ::User/, operation)
|
195
|
+
end
|
196
|
+
|
197
|
+
# Check that views are generated
|
198
|
+
%w(index show new edit).each do |view|
|
199
|
+
assert_file "app/views/admin/foo/users/#{view}.html.haml"
|
200
|
+
end
|
201
|
+
|
202
|
+
# Check that the controller is generated
|
203
|
+
assert_file 'app/controllers/admin/foo/users_controller.rb' do |controller|
|
204
|
+
assert_match(/module Admin::Foo/, controller)
|
205
|
+
assert_match(/class UsersController < ApplicationController/, controller)
|
206
|
+
end
|
207
|
+
|
208
|
+
# Check that the routes entry is added
|
209
|
+
assert_routes
|
210
|
+
end
|
211
|
+
|
128
212
|
private
|
129
213
|
|
130
214
|
def assert_operations
|
@@ -7,6 +7,22 @@ class RailsOps::Operation::Model::CreateTest < ActiveSupport::TestCase
|
|
7
7
|
model Group
|
8
8
|
end
|
9
9
|
|
10
|
+
ATTR_OP = Class.new(RailsOps::Operation::Model::Create) do
|
11
|
+
model ::Group do
|
12
|
+
attribute :long_group_name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_attribute
|
17
|
+
op = ATTR_OP.run!(group: { name: 'Test', color: 'red', long_group_name: 'Testgroup for extended testing' })
|
18
|
+
|
19
|
+
assert_equal 'Test', op.model.name
|
20
|
+
assert_equal 'red', op.model.color
|
21
|
+
assert_equal 'Testgroup for extended testing', op.model.long_group_name
|
22
|
+
assert op.model.persisted?
|
23
|
+
refute op.model.changed?
|
24
|
+
end
|
25
|
+
|
10
26
|
def test_basic
|
11
27
|
op = BASIC_OP.run!(group: { name: 'test', color: 'red' })
|
12
28
|
|
@@ -34,6 +34,30 @@ class RailsOps::Operation::Model::StiTest < ActiveSupport::TestCase
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
UPDATE_DOG_OP = Class.new(RailsOps::Operation::Model::Update) do
|
38
|
+
model Dog do
|
39
|
+
attribute :my_virtual_dog_name
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
CREATE_DOG_OP = Class.new(RailsOps::Operation::Model::Create) do
|
44
|
+
model Dog do
|
45
|
+
attribute :my_virtual_dog_name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
UPDATE_PHOENIX_OP = Class.new(RailsOps::Operation::Model::Update) do
|
50
|
+
model Phoenix do
|
51
|
+
attribute :my_virtual_phoenix_name
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
CREATE_PHOENIX_OP = Class.new(RailsOps::Operation::Model::Create) do
|
56
|
+
model Phoenix do
|
57
|
+
attribute :my_virtual_phoenix_name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
37
61
|
def test_load_animal
|
38
62
|
model = LOAD_ANIMAL_OP.new(id: @dog.id).model
|
39
63
|
assert_equal 'Dog', model.type
|
@@ -67,4 +91,36 @@ class RailsOps::Operation::Model::StiTest < ActiveSupport::TestCase
|
|
67
91
|
assert model.is_a?(LOAD_PHOENIX_OP.model)
|
68
92
|
assert_nothing_raised { model.my_virtual_phoenix_name = 'Lenny' }
|
69
93
|
end
|
94
|
+
|
95
|
+
def test_create_dog
|
96
|
+
op = CREATE_DOG_OP.new.run!
|
97
|
+
|
98
|
+
assert_equal 'Dog', op.model.type
|
99
|
+
assert op.model.is_a?(CREATE_DOG_OP.model)
|
100
|
+
assert_nothing_raised { op.model.my_virtual_dog_name = 'Lenny' }
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_update_dog
|
104
|
+
op = UPDATE_DOG_OP.new(id: @dog.id).run!
|
105
|
+
|
106
|
+
assert_equal 'Dog', op.model.type
|
107
|
+
assert op.model.is_a?(UPDATE_DOG_OP.model)
|
108
|
+
assert_nothing_raised { op.model.my_virtual_dog_name = 'Lenny' }
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_create_phoenix
|
112
|
+
op = CREATE_PHOENIX_OP.new.run!
|
113
|
+
|
114
|
+
assert_equal 'Phoenix', op.model.type
|
115
|
+
assert op.model.is_a?(CREATE_PHOENIX_OP.model)
|
116
|
+
assert_nothing_raised { op.model.my_virtual_phoenix_name = 'Lenny' }
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_update_phoenix
|
120
|
+
op = UPDATE_PHOENIX_OP.new(id: @phoenix.id).run!
|
121
|
+
|
122
|
+
assert_equal 'Phoenix', op.model.type
|
123
|
+
assert op.model.is_a?(UPDATE_PHOENIX_OP.model)
|
124
|
+
assert_nothing_raised { op.model.my_virtual_phoenix_name = 'Lenny' }
|
125
|
+
end
|
70
126
|
end
|
@@ -10,6 +10,29 @@ class RailsOps::Operation::Model::UpdateTest < ActiveSupport::TestCase
|
|
10
10
|
FLOWER_OP = Class.new(RailsOps::Operation::Model::Update) do
|
11
11
|
model Flower do
|
12
12
|
attribute :color
|
13
|
+
|
14
|
+
def optimal_bpm
|
15
|
+
174
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
SECOND_FLOWER_OP = Class.new(RailsOps::Operation::Model::Update) do
|
21
|
+
model Flower do
|
22
|
+
validate :planted_is_true
|
23
|
+
before_update :do_calculation
|
24
|
+
|
25
|
+
def response_to_everything
|
26
|
+
42
|
27
|
+
end
|
28
|
+
|
29
|
+
def planted_is_true
|
30
|
+
errors.add(:planted, 'Needs to be true') unless planted?
|
31
|
+
end
|
32
|
+
|
33
|
+
def do_calculation
|
34
|
+
1 + 1
|
35
|
+
end
|
13
36
|
end
|
14
37
|
end
|
15
38
|
|
@@ -45,4 +68,26 @@ class RailsOps::Operation::Model::UpdateTest < ActiveSupport::TestCase
|
|
45
68
|
op.model
|
46
69
|
end
|
47
70
|
end
|
71
|
+
|
72
|
+
def test_validation
|
73
|
+
flower = Flower.create!(planted: true)
|
74
|
+
assert flower.planted
|
75
|
+
|
76
|
+
# This works fine
|
77
|
+
op1 = SECOND_FLOWER_OP.run!(id: flower.id, flower: { planted: true })
|
78
|
+
assert_equal 42, op1.model.response_to_everything
|
79
|
+
assert op1.model.respond_to?(:response_to_everything)
|
80
|
+
assert op1.model.respond_to?(:planted_is_true)
|
81
|
+
refute op1.model.respond_to?(:optimal_bpm)
|
82
|
+
|
83
|
+
# This fails in Rails 7 and ruby 3.1.0, as the validation seems to be triggered
|
84
|
+
# in this as well, even though the validation is not defined here
|
85
|
+
# More interesting, it seems that only the validation and the before_update
|
86
|
+
# are handled incorrectly, the other methods work fine
|
87
|
+
op2 = FLOWER_OP.run!(id: flower.id, flower: { planted: true })
|
88
|
+
assert_equal 174, op2.model.optimal_bpm
|
89
|
+
assert op2.model.respond_to?(:optimal_bpm)
|
90
|
+
refute op2.model.respond_to?(:planted_is_true)
|
91
|
+
refute op2.model.respond_to?(:response_to_everything)
|
92
|
+
end
|
48
93
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_ops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,22 +212,29 @@ dependencies:
|
|
198
212
|
- - "<="
|
199
213
|
- !ruby/object:Gem::Version
|
200
214
|
version: '3.1'
|
201
|
-
description:
|
202
|
-
email:
|
215
|
+
description:
|
216
|
+
email:
|
203
217
|
executables: []
|
204
218
|
extensions: []
|
205
219
|
extra_rdoc_files: []
|
206
220
|
files:
|
221
|
+
- ".github/workflows/rubocop.yml"
|
207
222
|
- ".github/workflows/ruby.yml"
|
208
223
|
- ".gitignore"
|
209
224
|
- ".releaser_config"
|
210
225
|
- ".rubocop.yml"
|
226
|
+
- Appraisals
|
211
227
|
- CHANGELOG.md
|
212
228
|
- Gemfile
|
213
229
|
- LICENSE
|
214
230
|
- README.md
|
215
231
|
- Rakefile
|
216
232
|
- VERSION
|
233
|
+
- gemfiles/rails_5.1.gemfile
|
234
|
+
- gemfiles/rails_5.2.gemfile
|
235
|
+
- gemfiles/rails_6.0.gemfile
|
236
|
+
- gemfiles/rails_6.1.gemfile
|
237
|
+
- gemfiles/rails_7.0.gemfile
|
217
238
|
- lib/generators/operation/USAGE
|
218
239
|
- lib/generators/operation/operation_generator.rb
|
219
240
|
- lib/generators/operation/templates/controller.erb
|
@@ -247,7 +268,6 @@ files:
|
|
247
268
|
- lib/rails_ops/mixins/routes.rb
|
248
269
|
- lib/rails_ops/mixins/schema_validation.rb
|
249
270
|
- lib/rails_ops/mixins/sub_ops.rb
|
250
|
-
- lib/rails_ops/model_casting.rb
|
251
271
|
- lib/rails_ops/model_mixins.rb
|
252
272
|
- lib/rails_ops/model_mixins/ar_extension.rb
|
253
273
|
- lib/rails_ops/model_mixins/parent_op.rb
|
@@ -262,7 +282,6 @@ files:
|
|
262
282
|
- lib/rails_ops/operation/model/destroy.rb
|
263
283
|
- lib/rails_ops/operation/model/load.rb
|
264
284
|
- lib/rails_ops/operation/model/update.rb
|
265
|
-
- lib/rails_ops/patches/active_type_patch.rb
|
266
285
|
- lib/rails_ops/profiler.rb
|
267
286
|
- lib/rails_ops/profiler/node.rb
|
268
287
|
- lib/rails_ops/railtie.rb
|
@@ -351,10 +370,10 @@ files:
|
|
351
370
|
- test/unit/rails_ops/operation/update_auth_test.rb
|
352
371
|
- test/unit/rails_ops/operation/update_lazy_auth_test.rb
|
353
372
|
- test/unit/rails_ops/operation_test.rb
|
354
|
-
homepage:
|
373
|
+
homepage:
|
355
374
|
licenses: []
|
356
375
|
metadata: {}
|
357
|
-
post_install_message:
|
376
|
+
post_install_message:
|
358
377
|
rdoc_options: []
|
359
378
|
require_paths:
|
360
379
|
- lib
|
@@ -369,8 +388,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
369
388
|
- !ruby/object:Gem::Version
|
370
389
|
version: '0'
|
371
390
|
requirements: []
|
372
|
-
rubygems_version: 3.2
|
373
|
-
signing_key:
|
391
|
+
rubygems_version: 3.1.2
|
392
|
+
signing_key:
|
374
393
|
specification_version: 4
|
375
394
|
summary: An operations service layer for rails projects.
|
376
395
|
test_files:
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module RailsOps::ModelCasting
|
2
|
-
def self.cast(model)
|
3
|
-
if model.class.respond_to?(:extended_record_base_class)
|
4
|
-
return ActiveType.cast(model, model.class.extended_record_base_class)
|
5
|
-
else
|
6
|
-
return model
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.original_class_for(model_class)
|
11
|
-
if model_class.respond_to?(:extended_record_base_class)
|
12
|
-
return model_class.extended_record_base_class
|
13
|
-
else
|
14
|
-
return model_class
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# Internal reference: #25564
|
2
|
-
module ActiveType
|
3
|
-
class TypeCaster
|
4
|
-
def type_cast_from_user(value)
|
5
|
-
# For some reason, Rails defines additional type casting logic
|
6
|
-
# outside the classes that have that responsibility.
|
7
|
-
case @type
|
8
|
-
when :integer
|
9
|
-
if value == ''
|
10
|
-
nil
|
11
|
-
else
|
12
|
-
native_type_cast_from_user(value)
|
13
|
-
end
|
14
|
-
when :timestamp, :datetime
|
15
|
-
time = native_type_cast_from_user(value)
|
16
|
-
if time && ActiveRecord::Base.time_zone_aware_attributes
|
17
|
-
time = ActiveSupport::TimeWithZone.new(nil, Time.zone, time)
|
18
|
-
end
|
19
|
-
time
|
20
|
-
when Integer.class
|
21
|
-
if value == ''
|
22
|
-
nil
|
23
|
-
else
|
24
|
-
value.to_i
|
25
|
-
end
|
26
|
-
else
|
27
|
-
native_type_cast_from_user(value)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
module NativeCasters
|
32
|
-
class DelegateToType
|
33
|
-
def initialize(type, connection)
|
34
|
-
# The specified type (e.g. "string") may not necessary match the
|
35
|
-
# native type ("varchar") expected by the connection adapter.
|
36
|
-
# PostgreSQL is one of these. Perform a translation if the adapter
|
37
|
-
# supports it (but don't turn a mysql boolean into a tinyint).
|
38
|
-
if !type.nil? && !(type == :boolean) && type.respond_to?(:to_sym) && connection.respond_to?(:native_database_types)
|
39
|
-
native_type = connection.native_database_types[type.try(:to_sym)]
|
40
|
-
if native_type && native_type[:name]
|
41
|
-
type = native_type[:name]
|
42
|
-
else
|
43
|
-
# unknown type, we just dont cast
|
44
|
-
type = nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
@active_record_type = connection.lookup_cast_type(type)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|