active_record-acts_as 4.0.3 → 5.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -6
- data/Appraisals +6 -18
- data/CHANGELOG.md +72 -37
- data/README.md +7 -5
- data/active_record-acts_as.gemspec +10 -7
- data/gemfiles/{rails_4.2.gemfile → rails_6.0.gemfile} +1 -1
- data/gemfiles/{rails_5.0.gemfile → rails_6.1.gemfile} +1 -1
- data/gemfiles/{rails_5.1.gemfile → rails_master.gemfile} +1 -1
- data/lib/active_record/acts_as.rb +1 -0
- data/lib/active_record/acts_as/class_methods.rb +1 -1
- data/lib/active_record/acts_as/instance_methods.rb +16 -6
- data/lib/active_record/acts_as/migration.rb +4 -4
- data/lib/active_record/acts_as/querying.rb +1 -7
- data/lib/active_record/acts_as/relation.rb +2 -2
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +29 -19
- data/spec/models.rb +8 -0
- metadata +34 -20
- data/gemfiles/rails_5.2.1.1.gemfile +0 -8
- data/gemfiles/rails_5.2.1.gemfile +0 -8
- data/gemfiles/rails_5.2.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecd8cd75c441652a7719cc0b040d77a84a95f30b1ea8b19c02aa35fb6bdcd425
|
4
|
+
data.tar.gz: a94c71a0cc0dec6e7468cc3949260ee521320a15ab09d433a7c6323aa8b2114d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea6d3e0caa50e3a5e39543684bf372e4d64d5b8adfeb29686523b6674d7d1f4d42449b924f657814cd2c14894068a019d8a8796c45efcc1a76bc1c8cac0ea886
|
7
|
+
data.tar.gz: 9d12820c023f3c0f9d11594b17c904da1ece86fa4381a791cb84f086cde101078140ab9219dfee08185c7e90143d3ae1cffe7abe4f829e427fce002da72c8366
|
data/.travis.yml
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
rvm:
|
4
|
-
- 2.4
|
5
|
-
- 2.5
|
6
4
|
- 2.6
|
5
|
+
- 2.7
|
6
|
+
- 3.0
|
7
7
|
before_install:
|
8
8
|
- gem update --system
|
9
9
|
gemfile:
|
10
|
-
- gemfiles/
|
11
|
-
- gemfiles/
|
12
|
-
- gemfiles/
|
13
|
-
|
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
|
data/Appraisals
CHANGED
@@ -1,23 +1,11 @@
|
|
1
|
-
appraise
|
2
|
-
gem 'rails', '~>
|
1
|
+
appraise "rails-6.0" do
|
2
|
+
gem 'rails', '~> 6.0'
|
3
3
|
end
|
4
4
|
|
5
|
-
appraise
|
6
|
-
gem 'rails', '~>
|
5
|
+
appraise "rails-6.1" do
|
6
|
+
gem 'rails', '~> 6.1'
|
7
7
|
end
|
8
8
|
|
9
|
-
appraise
|
10
|
-
gem 'rails',
|
11
|
-
end
|
12
|
-
|
13
|
-
appraise 'rails-5.2.1' do
|
14
|
-
gem 'rails', '5.2.1'
|
15
|
-
end
|
16
|
-
|
17
|
-
appraise 'rails-5.2.1.1' do
|
18
|
-
gem 'rails', '5.2.1.1'
|
19
|
-
end
|
20
|
-
|
21
|
-
appraise 'rails-5.2' do
|
22
|
-
gem 'rails', '~> 5.2.0'
|
9
|
+
appraise "rails-master" do
|
10
|
+
gem 'rails', github: 'rails/rails'
|
23
11
|
end
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,40 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
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
|
+
## [Unreleased] -
|
8
|
+
|
9
|
+
## [5.0.2] - 2021-07-27
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- Handle kwargs in ruby 3 in methods delegated to supermodel (@tindron)
|
13
|
+
|
14
|
+
## [5.0.1] - 2021-01-28
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- Fixed rails `6.0.x` compatibility for `ActiveRecord::Errors` (@chaadow)
|
18
|
+
|
19
|
+
## [5.0.0] - 2020-12-29 by @chaadow
|
20
|
+
|
21
|
+
### Added
|
22
|
+
- Add support for rails 6 and 6.1 while removing rails 4.x and 5.x
|
23
|
+
from the travis matrix.
|
24
|
+
- Remove last ruby 3 warnings and make the gem **totally compatible with
|
25
|
+
ruby 3**
|
26
|
+
- Add support for rails master ( aka rails 6.2) to catch any upcoming
|
27
|
+
breaking change up front.
|
28
|
+
- bump minimum ruby version to 2.5
|
29
|
+
- Update test coverage
|
30
|
+
|
31
|
+
### Fixed
|
32
|
+
- Fix `#touch` API to match rails 5/6 API and make it ruby 3 compatible
|
33
|
+
- collection methods such as `<<` work now under rails 6.1
|
34
|
+
- Prepare for Rails 6.2 breaking change by updating how errors
|
35
|
+
are accessed and removing warning. They are now ruby objects.
|
36
|
+
see [this](https://api.rubyonrails.org/v6.1.0/classes/ActiveModel/Errors.html)
|
37
|
+
|
38
|
+
### Removed
|
39
|
+
- Remove support for rails 4.x and 5.x
|
40
|
+
|
7
41
|
## [4.0.0] - 2019-01-09
|
8
42
|
|
9
43
|
## [3.1.0] - 2018-12-13
|
@@ -37,10 +71,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
37
71
|
|
38
72
|
## [2.3.0] - 2017-04-12
|
39
73
|
### Fixed
|
40
|
-
- Prevent duplicate validation errors (fixes https://github.com/
|
74
|
+
- Prevent duplicate validation errors (fixes https://github.com/chaadow/active_record-acts_as/issues/2)
|
41
75
|
|
42
76
|
### Added
|
43
|
-
- Added support for touching submodel attributes (https://github.com/
|
77
|
+
- Added support for touching submodel attributes (https://github.com/chaadow/active_record-acts_as/pull/3, thanks to [dezmathio](https://github.com/dezmathio)!)
|
44
78
|
|
45
79
|
## [2.2.1] - 2017-04-08
|
46
80
|
### Fixed
|
@@ -107,38 +141,39 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
107
141
|
### Fixed
|
108
142
|
- Fixed `remove_actable` migration helper (https://github.com/hzamani/active_record-acts_as/pull/71, thanks to [nuclearpidgeon](https://github.com/nuclearpidgeon)!)
|
109
143
|
|
110
|
-
[Unreleased]: https://github.com/
|
111
|
-
[
|
112
|
-
[3.0
|
113
|
-
[3.0.
|
114
|
-
[3.0.
|
115
|
-
[
|
116
|
-
[2.
|
117
|
-
[2.4.
|
118
|
-
[2.4.
|
119
|
-
[2.
|
120
|
-
[2.3.
|
121
|
-
[2.
|
122
|
-
[2.2.
|
123
|
-
[2.
|
124
|
-
[2.1.
|
125
|
-
[2.0
|
126
|
-
[2.0.
|
127
|
-
[2.0.
|
128
|
-
[2.0.
|
129
|
-
[2.0.
|
130
|
-
[2.0.
|
131
|
-
[2.0.
|
132
|
-
[2.0.
|
133
|
-
[2.0.
|
134
|
-
[2.0.
|
135
|
-
[
|
136
|
-
[1.0.
|
137
|
-
[1.0.
|
138
|
-
[1.0.
|
139
|
-
[1.0.
|
140
|
-
[1.0.
|
141
|
-
[1.0.
|
142
|
-
[1.0.
|
143
|
-
[1.0.
|
144
|
-
[1.0.0
|
144
|
+
[Unreleased]: https://github.com/chaadow/active_record-acts_as/compare/v5.0.0...HEAD
|
145
|
+
[5.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v4.0.0...v5.0.0
|
146
|
+
[3.1.0]: https://github.com/chaadow/active_record-acts_as/compare/v3.1.0...v4.0.0
|
147
|
+
[3.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v3.0.1...v3.0.2
|
148
|
+
[3.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v3.0.0...v3.0.1
|
149
|
+
[3.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.5.0...v3.0.0
|
150
|
+
[2.5.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.2...v2.5.0
|
151
|
+
[2.4.2]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.1...v2.4.2
|
152
|
+
[2.4.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.0...v2.4.1
|
153
|
+
[2.4.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.3.1...v2.4.0
|
154
|
+
[2.3.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.3.0...v2.3.1
|
155
|
+
[2.3.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.2.1...v2.3.0
|
156
|
+
[2.2.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.2.0...v2.2.1
|
157
|
+
[2.2.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.1.1...v2.2.0
|
158
|
+
[2.1.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.1.0...v2.1.1
|
159
|
+
[2.1.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.9...v2.1.0
|
160
|
+
[2.0.9]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.8...v2.0.9
|
161
|
+
[2.0.8]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.7...v2.0.8
|
162
|
+
[2.0.7]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.6...v2.0.7
|
163
|
+
[2.0.6]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.5...v2.0.6
|
164
|
+
[2.0.5]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.4...v2.0.5
|
165
|
+
[2.0.4]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.3...v2.0.4
|
166
|
+
[2.0.3]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.2...v2.0.3
|
167
|
+
[2.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.1...v2.0.2
|
168
|
+
[2.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.0...v2.0.1
|
169
|
+
[2.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.8...v2.0.0
|
170
|
+
[1.0.8]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.7...v1.0.8
|
171
|
+
[1.0.7]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.6...v1.0.7
|
172
|
+
[1.0.6]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.5...v1.0.6
|
173
|
+
[1.0.5]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.4...v1.0.5
|
174
|
+
[1.0.4]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.3...v1.0.4
|
175
|
+
[1.0.3]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.2...v1.0.3
|
176
|
+
[1.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.1...v1.0.2
|
177
|
+
[1.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.0...v1.0.1
|
178
|
+
[1.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.0.rc...v1.0.0
|
179
|
+
[1.0.0.rc]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.0.pre...v1.0.0.rc
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
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/
|
2
|
+
[![Build Status](https://travis-ci.org/chaadow/active_record-acts_as.svg)](https://travis-ci.org/chaadow/active_record-acts_as)
|
3
3
|
|
4
4
|
# ActiveRecord::ActsAs
|
5
5
|
|
@@ -18,9 +18,11 @@ a separate table for each product type, i.e. a `pens` table with `color` column.
|
|
18
18
|
|
19
19
|
## Requirements
|
20
20
|
|
21
|
-
* Ruby >= 2.
|
22
|
-
* ActiveSupport >=
|
23
|
-
* ActiveRecord >=
|
21
|
+
* Ruby >= `2.5`
|
22
|
+
* ActiveSupport >= `6.0`
|
23
|
+
* 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`
|
24
26
|
|
25
27
|
## Installation
|
26
28
|
|
@@ -217,7 +219,7 @@ end
|
|
217
219
|
|
218
220
|
## Contributing
|
219
221
|
|
220
|
-
1. Fork it (https://github.com/
|
222
|
+
1. Fork it (https://github.com/chaadow/active_record-acts_as/fork)
|
221
223
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
222
224
|
3. Test changes don't break anything (`rspec`)
|
223
225
|
4. Add specs for your new feature
|
@@ -6,11 +6,12 @@ require 'active_record/acts_as/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "active_record-acts_as"
|
8
8
|
spec.version = ActiveRecord::ActsAs::VERSION
|
9
|
-
spec.authors = ["Hassan Zamani", "Manuel Meurer"]
|
10
|
-
spec.email = ["hsn.zamani@gmail.com", "manuel@krautcomputing.com"]
|
9
|
+
spec.authors = ["Hassan Zamani", "Manuel Meurer", "Chedli Bourguiba"]
|
10
|
+
spec.email = ["hsn.zamani@gmail.com", "manuel@krautcomputing.com", "bourguiba.chedli@gmail.com"]
|
11
11
|
spec.summary = %q{Simulate multi-table inheritance for activerecord models}
|
12
12
|
spec.description = %q{Simulate multi-table inheritance for activerecord models using a polymorphic association}
|
13
|
-
spec.homepage = "http://github.com/
|
13
|
+
spec.homepage = "http://github.com/chaadow/active_record-acts_as"
|
14
|
+
spec.metadata = { "source_code_uri" => "http://github.com/chaadow/active_record-acts_as" }
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -18,15 +19,17 @@ Gem::Specification.new do |spec|
|
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
|
-
spec.required_ruby_version = ">= 2.
|
22
|
+
spec.required_ruby_version = ">= 2.5"
|
22
23
|
|
23
|
-
spec.add_development_dependency "sqlite3"
|
24
|
+
spec.add_development_dependency "sqlite3"
|
24
25
|
spec.add_development_dependency "bundler"
|
25
26
|
spec.add_development_dependency "rspec", "~> 3"
|
26
27
|
spec.add_development_dependency "rake", "~> 10"
|
27
28
|
spec.add_development_dependency "appraisal", "~> 2.1"
|
28
29
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
29
30
|
|
30
|
-
spec.add_dependency "activesupport", ">=
|
31
|
-
spec.add_dependency "activerecord", ">=
|
31
|
+
spec.add_dependency "activesupport", ">= 6.0"
|
32
|
+
spec.add_dependency "activerecord", ">= 6.0"
|
33
|
+
spec.add_dependency "ruby2_keywords"
|
34
|
+
|
32
35
|
end
|
@@ -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)
|
@@ -19,8 +19,10 @@ module ActiveRecord
|
|
19
19
|
|
20
20
|
def actable_must_be_valid
|
21
21
|
unless acting_as.valid?
|
22
|
-
acting_as.errors.each do |attribute,
|
23
|
-
|
22
|
+
acting_as.errors.messages.each do |attribute, messages|
|
23
|
+
messages.each do |message|
|
24
|
+
errors.add(attribute, message) unless errors[attribute].include?(message)
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -42,6 +44,14 @@ module ActiveRecord
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
47
|
+
def _write_attribute(attr_name, value, *args, &block)
|
48
|
+
if attribute_method?(attr_name.to_s)
|
49
|
+
super
|
50
|
+
else
|
51
|
+
acting_as.send(:_write_attribute, attr_name, value, *args, &block)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
45
55
|
def read_store_attribute(store_attribute, key)
|
46
56
|
if attribute_method?(store_attribute.to_s)
|
47
57
|
super
|
@@ -83,10 +93,10 @@ module ActiveRecord
|
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
86
|
-
def touch(*args)
|
96
|
+
def touch(*args, time: nil)
|
87
97
|
self_args, acting_as_args = args.partition { |arg| has_attribute?(arg, true) }
|
88
|
-
super(*self_args) if self_args.any?
|
89
|
-
acting_as.touch(*acting_as_args) if acting_as.persisted?
|
98
|
+
super(*self_args, time: time) if self_args.any?
|
99
|
+
acting_as.touch(*acting_as_args, time: time) if acting_as.persisted?
|
90
100
|
end
|
91
101
|
|
92
102
|
def respond_to?(name, include_private = false, as_original_class = false)
|
@@ -107,7 +117,7 @@ module ActiveRecord
|
|
107
117
|
duplicate
|
108
118
|
end
|
109
119
|
|
110
|
-
def method_missing(method, *args, &block)
|
120
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
111
121
|
if !self_respond_to?(method) && acting_as.respond_to?(method)
|
112
122
|
acting_as.send(method, *args, &block)
|
113
123
|
else
|
@@ -2,20 +2,20 @@ module ActiveRecord
|
|
2
2
|
module ActsAs
|
3
3
|
module Migration
|
4
4
|
module TableDefinition
|
5
|
-
def actable(options
|
5
|
+
def actable(**options)
|
6
6
|
name = options.delete(:as) || :actable
|
7
7
|
options[:polymorphic] = true
|
8
|
-
references(name, options)
|
8
|
+
references(name, **options)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
module Table
|
13
13
|
include TableDefinition
|
14
14
|
|
15
|
-
def remove_actable(options
|
15
|
+
def remove_actable(**options)
|
16
16
|
name = options.delete(:as) || :actable
|
17
17
|
options[:polymorphic] = true
|
18
|
-
@base.remove_reference(@name, name, options)
|
18
|
+
@base.remove_reference(@name, name, **options)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -28,13 +28,7 @@ module ActiveRecord
|
|
28
28
|
|
29
29
|
module ScopeForCreate
|
30
30
|
def scope_for_create(attributes = nil)
|
31
|
-
unless acting_as?
|
32
|
-
if Gem::Dependency.new('', '>= 5.2.1', '< 5.2.2').match?('', ActiveRecord.version)
|
33
|
-
return super(attributes)
|
34
|
-
else
|
35
|
-
return super()
|
36
|
-
end
|
37
|
-
end
|
31
|
+
return super() unless acting_as?
|
38
32
|
|
39
33
|
scope = respond_to?(:values_for_create) ? values_for_create(attributes) : where_values_hash
|
40
34
|
scope.merge!(where_values_hash(acting_as_model.table_name))
|
@@ -28,11 +28,11 @@ module ActiveRecord
|
|
28
28
|
validate :actable_must_be_valid if validates_actable
|
29
29
|
|
30
30
|
unless touch == false
|
31
|
-
after_update :touch, if:
|
31
|
+
after_update :touch, if: :saved_changes?
|
32
32
|
end
|
33
33
|
|
34
34
|
before_save do
|
35
|
-
@_acting_as_changed =
|
35
|
+
@_acting_as_changed = acting_as.has_changes_to_save?
|
36
36
|
true
|
37
37
|
end
|
38
38
|
after_commit do
|
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')
|
@@ -221,10 +225,11 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
221
225
|
|
222
226
|
context 'touching' do
|
223
227
|
describe '#touch with arguments' do
|
224
|
-
it "forwards supermodel arguments
|
228
|
+
it "forwards supermodel arguments to the supermodel" do
|
229
|
+
now = Time.current
|
225
230
|
pen.save!
|
226
|
-
expect(pen.product).to receive(:touch).with(:updated_at)
|
227
|
-
pen.touch(:updated_at, :
|
231
|
+
expect(pen.product).to receive(:touch).with(:updated_at, {time: now})
|
232
|
+
pen.touch(:updated_at, time: now)
|
228
233
|
end
|
229
234
|
|
230
235
|
it "updates submodel arguments" do
|
@@ -236,7 +241,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
236
241
|
describe '#touch without arguments' do
|
237
242
|
it "touches the supermodel" do
|
238
243
|
pen.save!
|
239
|
-
expect(pen.product).to receive(:touch).with(
|
244
|
+
expect(pen.product).to receive(:touch).with(time: nil)
|
240
245
|
pen.touch
|
241
246
|
end
|
242
247
|
end
|
@@ -299,21 +304,21 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
299
304
|
it "combines supermodel and submodel errors" do
|
300
305
|
pen = Pen.new
|
301
306
|
expect(pen).to be_invalid
|
302
|
-
expect(pen.errors.
|
303
|
-
name: "can't be blank",
|
304
|
-
price: "can't be blank",
|
305
|
-
color: "can't be blank"
|
307
|
+
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"]
|
306
311
|
)
|
307
312
|
pen.name = 'testing'
|
308
313
|
expect(pen).to be_invalid
|
309
|
-
expect(pen.errors.
|
310
|
-
price: "can't be blank",
|
311
|
-
color: "can't be blank"
|
314
|
+
expect(pen.errors.to_hash).to eq(
|
315
|
+
price: ["can't be blank"],
|
316
|
+
color: ["can't be blank"]
|
312
317
|
)
|
313
318
|
pen.color = 'red'
|
314
319
|
expect(pen).to be_invalid
|
315
|
-
expect(pen.errors.
|
316
|
-
price: "can't be blank"
|
320
|
+
expect(pen.errors.to_hash).to eq(
|
321
|
+
price: ["can't be blank"]
|
317
322
|
)
|
318
323
|
pen.price = 0.8
|
319
324
|
expect(pen).to be_valid
|
@@ -324,8 +329,8 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
324
329
|
it "unless validates_actable is set to false" do
|
325
330
|
pen = IsolatedPen.new
|
326
331
|
expect(pen).to be_invalid
|
327
|
-
expect(pen.errors.
|
328
|
-
color: "can't be blank"
|
332
|
+
expect(pen.errors.to_hash).to eq(
|
333
|
+
color: ["can't be blank"]
|
329
334
|
)
|
330
335
|
pen.color = 'red'
|
331
336
|
expect(pen).to be_valid
|
@@ -402,7 +407,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
402
407
|
it "returns a query for the actable records" do
|
403
408
|
red_pen = Pen.create!(name: 'red pen', price: 0.8, color: 'red')
|
404
409
|
blue_pen = Pen.create!(name: 'blue pen', price: 0.8, color: 'blue')
|
405
|
-
|
410
|
+
_black_pen = Pen.create!(name: 'black pen', price: 0.9, color: 'black')
|
406
411
|
|
407
412
|
actables = Pen.where(price: 0.8).actables
|
408
413
|
|
@@ -438,7 +443,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
438
443
|
|
439
444
|
context 'when they are defined via `scope`' do
|
440
445
|
it 'can be called from the submodel' do
|
441
|
-
|
446
|
+
_cheap_pen = Pen.create!(name: 'cheap pen', price: 0.5, color: 'blue')
|
442
447
|
expensive_pen = Pen.create!(name: 'expensive pen', price: 1, color: 'red')
|
443
448
|
|
444
449
|
expect(Product.with_price_higher_than(0.5).to_a).to eq([expensive_pen.acting_as])
|
@@ -451,6 +456,10 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
451
456
|
expect(Product.class_method_callable_by_submodel).to eq('class_method_callable_by_submodel')
|
452
457
|
expect(Pen.class_method_callable_by_submodel).to eq('class_method_callable_by_submodel')
|
453
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
|
454
463
|
end
|
455
464
|
|
456
465
|
context 'when they are neither defined via `scope` nor made callable by submodel' do
|
@@ -528,6 +537,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
528
537
|
describe '.scope_for_create' do
|
529
538
|
it 'includes supermodel attributes' do
|
530
539
|
relation = Pen.where(name: 'new name', price: 1.4, color: 'red')
|
540
|
+
|
531
541
|
expect(relation.scope_for_create).to include('name')
|
532
542
|
expect(relation.scope_for_create['name']).to eq('new name')
|
533
543
|
end
|
@@ -562,7 +572,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
562
572
|
Object.send(:remove_const, :Pen)
|
563
573
|
end
|
564
574
|
|
565
|
-
it "should
|
575
|
+
it "should include the selected attribute when associating using 'eager_load'" do
|
566
576
|
class Pen < ActiveRecord::Base
|
567
577
|
acts_as :product , {association_method: :eager_load}
|
568
578
|
store_accessor :settings, :option1
|
@@ -570,7 +580,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
570
580
|
end
|
571
581
|
Pen.create pen_attributes
|
572
582
|
|
573
|
-
expect(Pen.select("'something' as thing").first['thing']).to
|
583
|
+
expect(Pen.select("'something' as thing").first['thing']).to eq 'something'
|
574
584
|
end
|
575
585
|
|
576
586
|
it "should include the selected attribute in the model when associating using 'includes'" 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
|
metadata
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-acts_as
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
8
8
|
- Manuel Meurer
|
9
|
+
- Chedli Bourguiba
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2021-07-27 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: sqlite3
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
18
|
requirements:
|
18
|
-
- - "
|
19
|
+
- - ">="
|
19
20
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
21
|
+
version: '0'
|
21
22
|
type: :development
|
22
23
|
prerelease: false
|
23
24
|
version_requirements: !ruby/object:Gem::Requirement
|
24
25
|
requirements:
|
25
|
-
- - "
|
26
|
+
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
+
version: '0'
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
30
|
name: bundler
|
30
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,33 +102,48 @@ dependencies:
|
|
101
102
|
requirements:
|
102
103
|
- - ">="
|
103
104
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
105
|
+
version: '6.0'
|
105
106
|
type: :runtime
|
106
107
|
prerelease: false
|
107
108
|
version_requirements: !ruby/object:Gem::Requirement
|
108
109
|
requirements:
|
109
110
|
- - ">="
|
110
111
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
112
|
+
version: '6.0'
|
112
113
|
- !ruby/object:Gem::Dependency
|
113
114
|
name: activerecord
|
114
115
|
requirement: !ruby/object:Gem::Requirement
|
115
116
|
requirements:
|
116
117
|
- - ">="
|
117
118
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
119
|
+
version: '6.0'
|
119
120
|
type: :runtime
|
120
121
|
prerelease: false
|
121
122
|
version_requirements: !ruby/object:Gem::Requirement
|
122
123
|
requirements:
|
123
124
|
- - ">="
|
124
125
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
126
|
+
version: '6.0'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: ruby2_keywords
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
126
141
|
description: Simulate multi-table inheritance for activerecord models using a polymorphic
|
127
142
|
association
|
128
143
|
email:
|
129
144
|
- hsn.zamani@gmail.com
|
130
145
|
- manuel@krautcomputing.com
|
146
|
+
- bourguiba.chedli@gmail.com
|
131
147
|
executables:
|
132
148
|
- console
|
133
149
|
extensions: []
|
@@ -146,12 +162,9 @@ files:
|
|
146
162
|
- _config.yml
|
147
163
|
- active_record-acts_as.gemspec
|
148
164
|
- bin/console
|
149
|
-
- gemfiles/
|
150
|
-
- gemfiles/
|
151
|
-
- gemfiles/
|
152
|
-
- gemfiles/rails_5.2.1.1.gemfile
|
153
|
-
- gemfiles/rails_5.2.1.gemfile
|
154
|
-
- gemfiles/rails_5.2.gemfile
|
165
|
+
- gemfiles/rails_6.0.gemfile
|
166
|
+
- gemfiles/rails_6.1.gemfile
|
167
|
+
- gemfiles/rails_master.gemfile
|
155
168
|
- lib/active_record/acts_as.rb
|
156
169
|
- lib/active_record/acts_as/class_methods.rb
|
157
170
|
- lib/active_record/acts_as/instance_methods.rb
|
@@ -169,10 +182,11 @@ files:
|
|
169
182
|
- spec/models.rb
|
170
183
|
- spec/rspec_matchers_spec.rb
|
171
184
|
- spec/spec_helper.rb
|
172
|
-
homepage: http://github.com/
|
185
|
+
homepage: http://github.com/chaadow/active_record-acts_as
|
173
186
|
licenses:
|
174
187
|
- MIT
|
175
|
-
metadata:
|
188
|
+
metadata:
|
189
|
+
source_code_uri: http://github.com/chaadow/active_record-acts_as
|
176
190
|
post_install_message:
|
177
191
|
rdoc_options: []
|
178
192
|
require_paths:
|
@@ -181,14 +195,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
195
|
requirements:
|
182
196
|
- - ">="
|
183
197
|
- !ruby/object:Gem::Version
|
184
|
-
version: '2.
|
198
|
+
version: '2.5'
|
185
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
200
|
requirements:
|
187
201
|
- - ">="
|
188
202
|
- !ruby/object:Gem::Version
|
189
203
|
version: '0'
|
190
204
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
205
|
+
rubygems_version: 3.2.3
|
192
206
|
signing_key:
|
193
207
|
specification_version: 4
|
194
208
|
summary: Simulate multi-table inheritance for activerecord models
|