active_record-acts_as 5.0.3 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +40 -0
- data/.gitignore +1 -0
- data/Appraisals +5 -1
- data/CHANGELOG.md +13 -0
- data/README.md +9 -12
- data/active_record-acts_as.gemspec +2 -1
- data/gemfiles/rails_6.0.gemfile +1 -1
- data/gemfiles/rails_6.1.gemfile +1 -1
- data/gemfiles/rails_7.0.gemfile +8 -0
- data/gemfiles/rails_master.gemfile +1 -1
- data/lib/active_record/acts_as/class_methods.rb +1 -1
- data/lib/active_record/acts_as/querying.rb +21 -0
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +16 -9
- data/spec/spec_helper.rb +5 -0
- metadata +23 -8
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ed68e0f493ab0bca2e81e2a1f0fc1a37a9b97b125336e74f76c1a773794b6bc
|
4
|
+
data.tar.gz: 18934a6d17d87d3f5befeb57acdd11cbfbf0771e80ad95fafdb87819d0c1152a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '009d65fc100af5440fb62c5a9caefeaeda1c5473676d3d2a30c81450ae015780d7ad74226c3b76a0ab7b1c08b18db54edf092519a49a2cc507dc0a617cc2a093'
|
7
|
+
data.tar.gz: 9bacb126798c42cdada4db64e958425db014bbe59c9f5c3fd088472a70222b98afa20cd77816e622b8dacac61901680cb083975acfe422713d4771a0b0dada66
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ "master" ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ "master" ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
26
|
+
activerecord: ['6.0', '6.1', '7.0', 'master']
|
27
|
+
env:
|
28
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.activerecord }}.gemfile
|
29
|
+
steps:
|
30
|
+
- uses: actions/checkout@v3
|
31
|
+
- name: Set up Ruby
|
32
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
33
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
34
|
+
# uses: ruby/setup-ruby@v1
|
35
|
+
uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby-version }}
|
38
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
39
|
+
- name: Run tests
|
40
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
6
|
|
7
7
|
## [Unreleased] -
|
8
|
+
## [5.2.0] - 2023-09-03
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Add `.exists?` support to seamlessly check in both the model and super model
|
12
|
+
(@chaadow)
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
- Fix `.actables` to restrict based on type. (@Taeir)
|
16
|
+
|
17
|
+
## [5.1.0] - 2023-06-29
|
18
|
+
- Use Github actions instead of travis.yml
|
19
|
+
- Add support for ruby 2.7 3.0 and 3.1
|
20
|
+
- Add support for rails 7
|
8
21
|
|
9
22
|
## [5.0.2] - 2021-07-27
|
10
23
|
|
data/README.md
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/active_record-acts_as.svg)](http://badge.fury.io/rb/active_record-acts_as)
|
2
|
-
[![Build Status](https://travis-ci.org/chaadow/active_record-acts_as.svg)](https://travis-ci.org/chaadow/active_record-acts_as)
|
3
|
-
|
4
1
|
# ActiveRecord::ActsAs
|
5
|
-
|
6
|
-
|
2
|
+
![Gem](https://img.shields.io/gem/v/active_record-acts_as?style=for-the-badge)
|
3
|
+
![Build Status](https://img.shields.io/github/actions/workflow/status/chaadow/active_record-acts_as/ruby.yml?style=for-the-badge)
|
7
4
|
|
8
5
|
Simulates multiple-table-inheritance (MTI) for ActiveRecord models.
|
9
6
|
By default, ActiveRecord only supports single-table inheritance (STI).
|
@@ -21,8 +18,6 @@ a separate table for each product type, i.e. a `pens` table with `color` column.
|
|
21
18
|
* Ruby >= `2.5`
|
22
19
|
* ActiveSupport >= `6.0`
|
23
20
|
* ActiveRecord >= `6.0`
|
24
|
-
* Regarding ActiveRecord `5.2.x` please use version `4.0.3` of this gem. If you encounter any bug you can open an issue.
|
25
|
-
Maintenance will be stopped after the release of ActiveRecord `6.2`
|
26
21
|
|
27
22
|
## Installation
|
28
23
|
|
@@ -129,6 +124,12 @@ Pen.first.acting_as
|
|
129
124
|
# => #<Product ...>
|
130
125
|
```
|
131
126
|
|
127
|
+
Likewise, `actables` converts a relation of specific objects to their parent objects:
|
128
|
+
```ruby
|
129
|
+
Pen.where(...).actables
|
130
|
+
# => [#<Product ...>, ...]
|
131
|
+
```
|
132
|
+
|
132
133
|
In `has_many` case you can use subclasses:
|
133
134
|
|
134
135
|
```Ruby
|
@@ -174,7 +175,7 @@ Make sure you know what you are doing when overwriting `polymorphic` option.
|
|
174
175
|
|
175
176
|
If your `actable` and `acts_as` models are namespaced, you need to configure them like this:
|
176
177
|
|
177
|
-
```
|
178
|
+
```Ruby
|
178
179
|
class MyApp::Product < ApplicationRecord
|
179
180
|
actable inverse_of: :product
|
180
181
|
end
|
@@ -187,14 +188,10 @@ end
|
|
187
188
|
## Caveats
|
188
189
|
|
189
190
|
Multiple `acts_as` in the same class are not supported!
|
190
|
-
|
191
|
-
|
192
191
|
## Migrating from acts_as_relation
|
193
192
|
|
194
193
|
Replace `acts_as_superclass` in models with `actable` and if you where using
|
195
194
|
`:as_relation_superclass` option on `create_table` remove it and use `t.actable` on column definitions.
|
196
|
-
|
197
|
-
|
198
195
|
## RSpec custom matchers
|
199
196
|
|
200
197
|
To use this library custom RSpec matchers, you must require the `rspec/acts_as_matchers` file.
|
@@ -24,7 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "sqlite3"
|
25
25
|
spec.add_development_dependency "bundler"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3"
|
27
|
-
spec.add_development_dependency "
|
27
|
+
spec.add_development_dependency "psych", "3.3.2"
|
28
|
+
spec.add_development_dependency "rake"
|
28
29
|
spec.add_development_dependency "appraisal", "~> 2.1"
|
29
30
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
30
31
|
|
data/gemfiles/rails_6.0.gemfile
CHANGED
data/gemfiles/rails_6.1.gemfile
CHANGED
@@ -26,6 +26,23 @@ module ActiveRecord
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
module ExistsConcern
|
30
|
+
extend ActiveSupport::Concern
|
31
|
+
|
32
|
+
included do
|
33
|
+
alias :_original_exists? :exists?
|
34
|
+
|
35
|
+
# We redefine the method only when this module is included
|
36
|
+
# to have acces to the original exists? method
|
37
|
+
def exists?(...)
|
38
|
+
return super unless acting_as?
|
39
|
+
|
40
|
+
joins(acting_as_name.to_sym)._original_exists?(...)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
29
46
|
module ScopeForCreate
|
30
47
|
def scope_for_create(attributes = nil)
|
31
48
|
return super() unless acting_as?
|
@@ -41,3 +58,7 @@ module ActiveRecord
|
|
41
58
|
Relation.send(:prepend, ActsAs::QueryMethods)
|
42
59
|
Relation.send(:prepend, ActsAs::ScopeForCreate)
|
43
60
|
end
|
61
|
+
|
62
|
+
ActiveSupport.on_load(:active_record) do
|
63
|
+
ActiveRecord::Relation.include(ActiveRecord::ActsAs::ExistsConcern)
|
64
|
+
end
|
data/spec/acts_as_spec.rb
CHANGED
@@ -300,25 +300,27 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
300
300
|
end
|
301
301
|
|
302
302
|
context "errors" do
|
303
|
+
let(:error_message) { ActiveRecord.version >= Gem::Version.new('7.1.0.alpha') ? "can’t be blank" : "can't be blank"}
|
304
|
+
|
303
305
|
context 'when validates_actable is set to true' do
|
304
306
|
it "combines supermodel and submodel errors" do
|
305
307
|
pen = Pen.new
|
306
308
|
expect(pen).to be_invalid
|
307
309
|
expect(pen.errors.to_hash).to eq(
|
308
|
-
name: [
|
309
|
-
price: [
|
310
|
-
color: [
|
310
|
+
name: [error_message],
|
311
|
+
price: [error_message],
|
312
|
+
color: [error_message]
|
311
313
|
)
|
312
314
|
pen.name = 'testing'
|
313
315
|
expect(pen).to be_invalid
|
314
316
|
expect(pen.errors.to_hash).to eq(
|
315
|
-
price: [
|
316
|
-
color: [
|
317
|
+
price: [error_message],
|
318
|
+
color: [error_message]
|
317
319
|
)
|
318
320
|
pen.color = 'red'
|
319
321
|
expect(pen).to be_invalid
|
320
322
|
expect(pen.errors.to_hash).to eq(
|
321
|
-
price: [
|
323
|
+
price: [error_message]
|
322
324
|
)
|
323
325
|
pen.price = 0.8
|
324
326
|
expect(pen).to be_valid
|
@@ -329,9 +331,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
329
331
|
it "unless validates_actable is set to false" do
|
330
332
|
pen = IsolatedPen.new
|
331
333
|
expect(pen).to be_invalid
|
332
|
-
expect(pen.errors.to_hash).to eq(
|
333
|
-
color: ["can't be blank"]
|
334
|
-
)
|
334
|
+
expect(pen.errors.to_hash).to eq( { color: [error_message] })
|
335
335
|
pen.color = 'red'
|
336
336
|
expect(pen).to be_valid
|
337
337
|
end
|
@@ -487,6 +487,13 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
487
487
|
@black_pen.buyers.create! name: 'John'
|
488
488
|
end
|
489
489
|
|
490
|
+
describe 'exists?' do
|
491
|
+
it 'checks on both model and supermodel' do
|
492
|
+
expect(Pen.exists?(name: 'red pen')).to be_truthy
|
493
|
+
expect(Pen.exists?(name: 'red pen', price: 0.8)).to be_truthy
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
490
497
|
describe '.where and .where!' do
|
491
498
|
it 'respects supermodel attributes' do
|
492
499
|
conditions = { price: 0.8 }
|
data/spec/spec_helper.rb
CHANGED
@@ -11,3 +11,8 @@ require 'active_record'
|
|
11
11
|
if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=)
|
12
12
|
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
13
13
|
end
|
14
|
+
if ActiveRecord.version > Gem::Version.new('6.2')
|
15
|
+
ActiveRecord.use_yaml_unsafe_load = true
|
16
|
+
else
|
17
|
+
ActiveRecord::Base.use_yaml_unsafe_load = true
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-acts_as
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-09-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sqlite3
|
@@ -54,20 +54,34 @@ dependencies:
|
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '3'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: psych
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 3.3.2
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 3.3.2
|
57
71
|
- !ruby/object:Gem::Dependency
|
58
72
|
name: rake
|
59
73
|
requirement: !ruby/object:Gem::Requirement
|
60
74
|
requirements:
|
61
|
-
- - "
|
75
|
+
- - ">="
|
62
76
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
77
|
+
version: '0'
|
64
78
|
type: :development
|
65
79
|
prerelease: false
|
66
80
|
version_requirements: !ruby/object:Gem::Requirement
|
67
81
|
requirements:
|
68
|
-
- - "
|
82
|
+
- - ">="
|
69
83
|
- !ruby/object:Gem::Version
|
70
|
-
version: '
|
84
|
+
version: '0'
|
71
85
|
- !ruby/object:Gem::Dependency
|
72
86
|
name: appraisal
|
73
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,9 +163,9 @@ executables:
|
|
149
163
|
extensions: []
|
150
164
|
extra_rdoc_files: []
|
151
165
|
files:
|
166
|
+
- ".github/workflows/ruby.yml"
|
152
167
|
- ".gitignore"
|
153
168
|
- ".rspec"
|
154
|
-
- ".travis.yml"
|
155
169
|
- Appraisals
|
156
170
|
- CHANGELOG.md
|
157
171
|
- Gemfile
|
@@ -164,6 +178,7 @@ files:
|
|
164
178
|
- bin/console
|
165
179
|
- gemfiles/rails_6.0.gemfile
|
166
180
|
- gemfiles/rails_6.1.gemfile
|
181
|
+
- gemfiles/rails_7.0.gemfile
|
167
182
|
- gemfiles/rails_master.gemfile
|
168
183
|
- lib/active_record/acts_as.rb
|
169
184
|
- lib/active_record/acts_as/class_methods.rb
|
@@ -202,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
217
|
- !ruby/object:Gem::Version
|
203
218
|
version: '0'
|
204
219
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
220
|
+
rubygems_version: 3.1.6
|
206
221
|
signing_key:
|
207
222
|
specification_version: 4
|
208
223
|
summary: Simulate multi-table inheritance for activerecord models
|
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
rvm:
|
4
|
-
- 2.6
|
5
|
-
- 2.7
|
6
|
-
- 3.0
|
7
|
-
before_install:
|
8
|
-
- gem update --system
|
9
|
-
gemfile:
|
10
|
-
- gemfiles/rails_6.0.gemfile
|
11
|
-
- gemfiles/rails_6.1.gemfile
|
12
|
-
- gemfiles/rails_master.gemfile
|
13
|
-
jobs:
|
14
|
-
exclude:
|
15
|
-
- rvm: 2.6
|
16
|
-
gemfile: gemfiles/rails_master.gemfile
|