active_record-acts_as 5.0.3 → 5.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecd8cd75c441652a7719cc0b040d77a84a95f30b1ea8b19c02aa35fb6bdcd425
4
- data.tar.gz: a94c71a0cc0dec6e7468cc3949260ee521320a15ab09d433a7c6323aa8b2114d
3
+ metadata.gz: 2ed68e0f493ab0bca2e81e2a1f0fc1a37a9b97b125336e74f76c1a773794b6bc
4
+ data.tar.gz: 18934a6d17d87d3f5befeb57acdd11cbfbf0771e80ad95fafdb87819d0c1152a
5
5
  SHA512:
6
- metadata.gz: ea6d3e0caa50e3a5e39543684bf372e4d64d5b8adfeb29686523b6674d7d1f4d42449b924f657814cd2c14894068a019d8a8796c45efcc1a76bc1c8cac0ea886
7
- data.tar.gz: 9d12820c023f3c0f9d11594b17c904da1ece86fa4381a791cb84f086cde101078140ab9219dfee08185c7e90143d3ae1cffe7abe4f829e427fce002da72c8366
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
@@ -7,6 +7,7 @@ Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
10
+ /tags
10
11
  doc/
11
12
  lib/bundler/man
12
13
  pkg
data/Appraisals CHANGED
@@ -6,6 +6,10 @@ appraise "rails-6.1" do
6
6
  gem 'rails', '~> 6.1'
7
7
  end
8
8
 
9
+ appraise "rails-7.0" do
10
+ gem 'rails', '~> 7.0'
11
+ end
12
+
9
13
  appraise "rails-master" do
10
- gem 'rails', github: 'rails/rails'
14
+ gem 'rails', github: 'rails/rails', branch: 'main'
11
15
  end
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
- This is a refactor of [`acts_as_relation`](https://github.com/hzamani/acts_as_relation)
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 "rake", "~> 10"
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
 
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "coveralls", require: false
6
- gem "rails", "~> 6.0.0"
6
+ gem "rails", "~> 6.0"
7
7
 
8
8
  gemspec path: "../"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "coveralls", require: false
6
- gem "rails", "~> 6.1.0"
6
+ gem "rails", "~> 6.1"
7
7
 
8
8
  gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "coveralls", require: false
6
+ gem "rails", "~> 7.0"
7
+
8
+ gemspec path: "../"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "coveralls", require: false
6
- gem "rails", github: 'rails'
6
+ gem "rails", github: "rails/rails", branch: "main"
7
7
 
8
8
  gemspec path: "../"
@@ -16,7 +16,7 @@ module ActiveRecord
16
16
  end
17
17
 
18
18
  def actables
19
- acting_as_model.where(actable_id: select(:id))
19
+ acting_as_model.where(actable_id: select(:id), actable_type: model_name.name)
20
20
  end
21
21
 
22
22
  def respond_to_missing?(method, include_private = false)
@@ -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
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord
2
2
  module ActsAs
3
- VERSION = "5.0.3"
3
+ VERSION = "5.2.0"
4
4
  end
5
5
  end
6
6
 
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: ["can't be blank"],
309
- price: ["can't be blank"],
310
- color: ["can't be blank"]
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: ["can't be blank"],
316
- color: ["can't be blank"]
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: ["can't be blank"]
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.3
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: 2021-07-27 00:00:00.000000000 Z
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: '10'
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: '10'
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.2.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