active_record-acts_as 5.0.2 → 5.1.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: 52d4f9697fffd355665d4fbfec8e95d3df7e4a7f079c1075ec02433003088028
4
- data.tar.gz: 90991fdb687a92ea19ef8c3d1f86f8940079e8adc31a715b0c81a0c64cde8159
3
+ metadata.gz: 532e3effe05da886dea3162ea29263ecce12c459e321bcd4fb870554a0227053
4
+ data.tar.gz: 0e0a4d871dd0bd2be5e2521ddd36abbe9d8038b1bc3c046401abf6ac1c727bbd
5
5
  SHA512:
6
- metadata.gz: 7f387a9c486ad279c7c978bdd58136f34a0b74438d757be8d507c0817da2d7c51f95bfac00223f375942ae511124d63dcfc77970901481d6671d92559166dbfa
7
- data.tar.gz: 17cb390291b18ca97a7778177407694f300dc45fb5717d76410b859018339bf71988fb88c430355aa21ad3910d726f97d5e9f19139c5f86aa8b039d1957876db
6
+ metadata.gz: 0477314dde10d98e065be763b4555c3f9915909f129be5b53e5385d41c739dc3482ad4ee4ddc504b60d1e69fd57f36326a995d7cc3d3ab9a86a9a7b4d32ecb25
7
+ data.tar.gz: 3607a37917ee5fcd6eca4f0a3df7f14a55252e4777faeadb736bb76312bfe0c2dd372779ccf353d8f883472d41504917ce6c1d95deaf20998763db28fe41f1a8
@@ -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,15 @@ 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.1.0] - 2023-06-29
9
+ - Use Github actions instead of travis.yml
10
+ - Add support for ruby 2.7 3.0 and 3.1
11
+ - Add support for rails 7
12
+
13
+ ## [5.0.2] - 2021-07-27
14
+
15
+ ### Fixed
16
+ - Handle kwargs in ruby 3 in methods delegated to supermodel (@tindron)
8
17
 
9
18
  ## [5.0.1] - 2021-01-28
10
19
 
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,11 +24,13 @@ 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
 
31
32
  spec.add_dependency "activesupport", ">= 6.0"
32
33
  spec.add_dependency "activerecord", ">= 6.0"
34
+ spec.add_dependency "ruby2_keywords"
33
35
 
34
36
  end
@@ -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: "../"
@@ -23,7 +23,7 @@ module ActiveRecord
23
23
  acting_as_model.methods_callable_by_submodel.include?(method) || super
24
24
  end
25
25
 
26
- def method_missing(method, *args, &block)
26
+ ruby2_keywords def method_missing(method, *args, &block)
27
27
  if acting_as_model.methods_callable_by_submodel.include?(method)
28
28
  result = acting_as_model.public_send(method, *args, &block)
29
29
  if result.is_a?(ActiveRecord::Relation)
@@ -117,7 +117,7 @@ module ActiveRecord
117
117
  duplicate
118
118
  end
119
119
 
120
- def method_missing(method, *args, &block)
120
+ ruby2_keywords def method_missing(method, *args, &block)
121
121
  if !self_respond_to?(method) && acting_as.respond_to?(method)
122
122
  acting_as.send(method, *args, &block)
123
123
  else
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord
2
2
  module ActsAs
3
- VERSION = "5.0.2"
3
+ VERSION = "5.1.0"
4
4
  end
5
5
  end
6
6
 
@@ -1,3 +1,4 @@
1
+ require 'ruby2_keywords'
1
2
  require 'active_support'
2
3
  require 'active_record'
3
4
  require 'active_record/acts_as/version'
data/spec/acts_as_spec.rb CHANGED
@@ -157,6 +157,10 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
157
157
  expect(pen.present).to eq("pen - $0.8")
158
158
  end
159
159
 
160
+ it "responds to supermodel methods with keyword arguments" do
161
+ expect(pen.keyword_method(one: 3, two: 4)).to eq [3,4]
162
+ end
163
+
160
164
  it 'responds to serialized attribute' do
161
165
  expect(pen).to respond_to('option1')
162
166
  expect(isolated_pen).to respond_to('option2')
@@ -452,6 +456,10 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
452
456
  expect(Product.class_method_callable_by_submodel).to eq('class_method_callable_by_submodel')
453
457
  expect(Pen.class_method_callable_by_submodel).to eq('class_method_callable_by_submodel')
454
458
  end
459
+
460
+ it 'with keyword arguments can be called from the submodel' do
461
+ expect(Pen.class_keyword_method_callable_by_submodel(one: 3, two: 4)).to eq([3,4])
462
+ end
455
463
  end
456
464
 
457
465
  context 'when they are neither defined via `scope` nor made callable by submodel' do
data/spec/models.rb CHANGED
@@ -16,6 +16,10 @@ class Product < ActiveRecord::Base
16
16
  'class_method'
17
17
  end
18
18
 
19
+ callable_by_submodel def self.class_keyword_method_callable_by_submodel(one: 1, two: 2)
20
+ [one, two]
21
+ end
22
+
19
23
  callable_by_submodel def self.class_method_callable_by_submodel
20
24
  'class_method_callable_by_submodel'
21
25
  end
@@ -27,6 +31,10 @@ class Product < ActiveRecord::Base
27
31
  def raise_error
28
32
  specific.non_existant_method
29
33
  end
34
+
35
+ def keyword_method(one: 1, two: 2)
36
+ [one, two]
37
+ end
30
38
  end
31
39
 
32
40
  class Payment < ActiveRecord::Base
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.2
4
+ version: 5.1.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-02-09 00:00:00.000000000 Z
13
+ date: 2023-06-29 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
@@ -124,6 +138,20 @@ dependencies:
124
138
  - - ">="
125
139
  - !ruby/object:Gem::Version
126
140
  version: '6.0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: ruby2_keywords
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ type: :runtime
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
127
155
  description: Simulate multi-table inheritance for activerecord models using a polymorphic
128
156
  association
129
157
  email:
@@ -135,9 +163,9 @@ executables:
135
163
  extensions: []
136
164
  extra_rdoc_files: []
137
165
  files:
166
+ - ".github/workflows/ruby.yml"
138
167
  - ".gitignore"
139
168
  - ".rspec"
140
- - ".travis.yml"
141
169
  - Appraisals
142
170
  - CHANGELOG.md
143
171
  - Gemfile
@@ -150,6 +178,7 @@ files:
150
178
  - bin/console
151
179
  - gemfiles/rails_6.0.gemfile
152
180
  - gemfiles/rails_6.1.gemfile
181
+ - gemfiles/rails_7.0.gemfile
153
182
  - gemfiles/rails_master.gemfile
154
183
  - lib/active_record/acts_as.rb
155
184
  - lib/active_record/acts_as/class_methods.rb
@@ -188,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
217
  - !ruby/object:Gem::Version
189
218
  version: '0'
190
219
  requirements: []
191
- rubygems_version: 3.2.3
220
+ rubygems_version: 3.1.6
192
221
  signing_key:
193
222
  specification_version: 4
194
223
  summary: Simulate multi-table inheritance for activerecord models
data/.travis.yml DELETED
@@ -1,12 +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