active_record-acts_as 4.0.1 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -6
- data/Appraisals +6 -18
- data/CHANGELOG.md +67 -37
- data/README.md +7 -7
- data/active_record-acts_as.gemspec +9 -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/instance_methods.rb +15 -5
- 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 +8 -8
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +21 -19
- metadata +23 -23
- 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: 52d4f9697fffd355665d4fbfec8e95d3df7e4a7f079c1075ec02433003088028
|
4
|
+
data.tar.gz: 90991fdb687a92ea19ef8c3d1f86f8940079e8adc31a715b0c81a0c64cde8159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f387a9c486ad279c7c978bdd58136f34a0b74438d757be8d507c0817da2d7c51f95bfac00223f375942ae511124d63dcfc77970901481d6671d92559166dbfa
|
7
|
+
data.tar.gz: 17cb390291b18ca97a7778177407694f300dc45fb5717d76410b859018339bf71988fb88c430355aa21ad3910d726f97d5e9f19139c5f86aa8b039d1957876db
|
data/.travis.yml
CHANGED
@@ -1,13 +1,12 @@
|
|
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
|
-
- gemfiles/rails_5.2.gemfile
|
10
|
+
- gemfiles/rails_6.0.gemfile
|
11
|
+
- gemfiles/rails_6.1.gemfile
|
12
|
+
- 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,35 @@ 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.1] - 2021-01-28
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- Fixed rails `6.0.x` compatibility for `ActiveRecord::Errors` (@chaadow)
|
13
|
+
|
14
|
+
## [5.0.0] - 2020-12-29 by @chaadow
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Add support for rails 6 and 6.1 while removing rails 4.x and 5.x
|
18
|
+
from the travis matrix.
|
19
|
+
- Remove last ruby 3 warnings and make the gem **totally compatible with
|
20
|
+
ruby 3**
|
21
|
+
- Add support for rails master ( aka rails 6.2) to catch any upcoming
|
22
|
+
breaking change up front.
|
23
|
+
- bump minimum ruby version to 2.5
|
24
|
+
- Update test coverage
|
25
|
+
|
26
|
+
### Fixed
|
27
|
+
- Fix `#touch` API to match rails 5/6 API and make it ruby 3 compatible
|
28
|
+
- collection methods such as `<<` work now under rails 6.1
|
29
|
+
- Prepare for Rails 6.2 breaking change by updating how errors
|
30
|
+
are accessed and removing warning. They are now ruby objects.
|
31
|
+
see [this](https://api.rubyonrails.org/v6.1.0/classes/ActiveModel/Errors.html)
|
32
|
+
|
33
|
+
### Removed
|
34
|
+
- Remove support for rails 4.x and 5.x
|
35
|
+
|
7
36
|
## [4.0.0] - 2019-01-09
|
8
37
|
|
9
38
|
## [3.1.0] - 2018-12-13
|
@@ -37,10 +66,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
37
66
|
|
38
67
|
## [2.3.0] - 2017-04-12
|
39
68
|
### Fixed
|
40
|
-
- Prevent duplicate validation errors (fixes https://github.com/
|
69
|
+
- Prevent duplicate validation errors (fixes https://github.com/chaadow/active_record-acts_as/issues/2)
|
41
70
|
|
42
71
|
### Added
|
43
|
-
- Added support for touching submodel attributes (https://github.com/
|
72
|
+
- Added support for touching submodel attributes (https://github.com/chaadow/active_record-acts_as/pull/3, thanks to [dezmathio](https://github.com/dezmathio)!)
|
44
73
|
|
45
74
|
## [2.2.1] - 2017-04-08
|
46
75
|
### Fixed
|
@@ -107,38 +136,39 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
107
136
|
### Fixed
|
108
137
|
- Fixed `remove_actable` migration helper (https://github.com/hzamani/active_record-acts_as/pull/71, thanks to [nuclearpidgeon](https://github.com/nuclearpidgeon)!)
|
109
138
|
|
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
|
139
|
+
[Unreleased]: https://github.com/chaadow/active_record-acts_as/compare/v5.0.0...HEAD
|
140
|
+
[5.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v4.0.0...v5.0.0
|
141
|
+
[3.1.0]: https://github.com/chaadow/active_record-acts_as/compare/v3.1.0...v4.0.0
|
142
|
+
[3.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v3.0.1...v3.0.2
|
143
|
+
[3.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v3.0.0...v3.0.1
|
144
|
+
[3.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.5.0...v3.0.0
|
145
|
+
[2.5.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.2...v2.5.0
|
146
|
+
[2.4.2]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.1...v2.4.2
|
147
|
+
[2.4.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.0...v2.4.1
|
148
|
+
[2.4.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.3.1...v2.4.0
|
149
|
+
[2.3.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.3.0...v2.3.1
|
150
|
+
[2.3.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.2.1...v2.3.0
|
151
|
+
[2.2.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.2.0...v2.2.1
|
152
|
+
[2.2.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.1.1...v2.2.0
|
153
|
+
[2.1.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.1.0...v2.1.1
|
154
|
+
[2.1.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.9...v2.1.0
|
155
|
+
[2.0.9]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.8...v2.0.9
|
156
|
+
[2.0.8]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.7...v2.0.8
|
157
|
+
[2.0.7]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.6...v2.0.7
|
158
|
+
[2.0.6]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.5...v2.0.6
|
159
|
+
[2.0.5]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.4...v2.0.5
|
160
|
+
[2.0.4]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.3...v2.0.4
|
161
|
+
[2.0.3]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.2...v2.0.3
|
162
|
+
[2.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.1...v2.0.2
|
163
|
+
[2.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.0...v2.0.1
|
164
|
+
[2.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.8...v2.0.0
|
165
|
+
[1.0.8]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.7...v1.0.8
|
166
|
+
[1.0.7]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.6...v1.0.7
|
167
|
+
[1.0.6]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.5...v1.0.6
|
168
|
+
[1.0.5]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.4...v1.0.5
|
169
|
+
[1.0.4]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.3...v1.0.4
|
170
|
+
[1.0.3]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.2...v1.0.3
|
171
|
+
[1.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.1...v1.0.2
|
172
|
+
[1.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.0...v1.0.1
|
173
|
+
[1.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.0.rc...v1.0.0
|
174
|
+
[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,7 +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/
|
3
|
-
[![Code Climate](https://codeclimate.com/github/krautcomputing/active_record-acts_as.png)](https://codeclimate.com/github/krautcomputing/active_record-acts_as)
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/krautcomputing/active_record-acts_as/badge.png)](https://coveralls.io/r/krautcomputing/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)
|
5
3
|
|
6
4
|
# ActiveRecord::ActsAs
|
7
5
|
|
@@ -20,9 +18,11 @@ a separate table for each product type, i.e. a `pens` table with `color` column.
|
|
20
18
|
|
21
19
|
## Requirements
|
22
20
|
|
23
|
-
* Ruby >= 2.
|
24
|
-
* ActiveSupport >=
|
25
|
-
* 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`
|
26
26
|
|
27
27
|
## Installation
|
28
28
|
|
@@ -219,7 +219,7 @@ end
|
|
219
219
|
|
220
220
|
## Contributing
|
221
221
|
|
222
|
-
1. Fork it (
|
222
|
+
1. Fork it (https://github.com/chaadow/active_record-acts_as/fork)
|
223
223
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
224
224
|
3. Test changes don't break anything (`rspec`)
|
225
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,16 @@ 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
|
+
|
32
34
|
end
|
@@ -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)
|
@@ -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))
|
@@ -14,7 +14,7 @@ module ActiveRecord
|
|
14
14
|
|
15
15
|
options = options.reverse_merge(as: as, validate: false, autosave: true, inverse_of: as)
|
16
16
|
|
17
|
-
reflections = has_one(name, scope, options)
|
17
|
+
reflections = has_one(name, scope, **options)
|
18
18
|
default_scope -> {
|
19
19
|
case association_method
|
20
20
|
when :eager_load
|
@@ -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
|
@@ -79,11 +79,11 @@ module ActiveRecord
|
|
79
79
|
def actable(scope = nil, **options)
|
80
80
|
name = options.delete(:as) || :actable
|
81
81
|
|
82
|
-
reflections = belongs_to(name, scope, options.reverse_merge(validate: false,
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
82
|
+
reflections = belongs_to(name, scope, **options.reverse_merge(validate: false,
|
83
|
+
polymorphic: true,
|
84
|
+
dependent: :destroy,
|
85
|
+
autosave: true,
|
86
|
+
inverse_of: to_s.underscore))
|
87
87
|
|
88
88
|
cattr_reader(:actable_reflection) { reflections.stringify_keys[name.to_s] }
|
89
89
|
|
data/spec/acts_as_spec.rb
CHANGED
@@ -221,10 +221,11 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
221
221
|
|
222
222
|
context 'touching' do
|
223
223
|
describe '#touch with arguments' do
|
224
|
-
it "forwards supermodel arguments
|
224
|
+
it "forwards supermodel arguments to the supermodel" do
|
225
|
+
now = Time.current
|
225
226
|
pen.save!
|
226
|
-
expect(pen.product).to receive(:touch).with(:updated_at)
|
227
|
-
pen.touch(:updated_at, :
|
227
|
+
expect(pen.product).to receive(:touch).with(:updated_at, {time: now})
|
228
|
+
pen.touch(:updated_at, time: now)
|
228
229
|
end
|
229
230
|
|
230
231
|
it "updates submodel arguments" do
|
@@ -236,7 +237,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
236
237
|
describe '#touch without arguments' do
|
237
238
|
it "touches the supermodel" do
|
238
239
|
pen.save!
|
239
|
-
expect(pen.product).to receive(:touch).with(
|
240
|
+
expect(pen.product).to receive(:touch).with(time: nil)
|
240
241
|
pen.touch
|
241
242
|
end
|
242
243
|
end
|
@@ -299,21 +300,21 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
299
300
|
it "combines supermodel and submodel errors" do
|
300
301
|
pen = Pen.new
|
301
302
|
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"
|
303
|
+
expect(pen.errors.to_hash).to eq(
|
304
|
+
name: ["can't be blank"],
|
305
|
+
price: ["can't be blank"],
|
306
|
+
color: ["can't be blank"]
|
306
307
|
)
|
307
308
|
pen.name = 'testing'
|
308
309
|
expect(pen).to be_invalid
|
309
|
-
expect(pen.errors.
|
310
|
-
price: "can't be blank",
|
311
|
-
color: "can't be blank"
|
310
|
+
expect(pen.errors.to_hash).to eq(
|
311
|
+
price: ["can't be blank"],
|
312
|
+
color: ["can't be blank"]
|
312
313
|
)
|
313
314
|
pen.color = 'red'
|
314
315
|
expect(pen).to be_invalid
|
315
|
-
expect(pen.errors.
|
316
|
-
price: "can't be blank"
|
316
|
+
expect(pen.errors.to_hash).to eq(
|
317
|
+
price: ["can't be blank"]
|
317
318
|
)
|
318
319
|
pen.price = 0.8
|
319
320
|
expect(pen).to be_valid
|
@@ -324,8 +325,8 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
324
325
|
it "unless validates_actable is set to false" do
|
325
326
|
pen = IsolatedPen.new
|
326
327
|
expect(pen).to be_invalid
|
327
|
-
expect(pen.errors.
|
328
|
-
color: "can't be blank"
|
328
|
+
expect(pen.errors.to_hash).to eq(
|
329
|
+
color: ["can't be blank"]
|
329
330
|
)
|
330
331
|
pen.color = 'red'
|
331
332
|
expect(pen).to be_valid
|
@@ -402,7 +403,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
402
403
|
it "returns a query for the actable records" do
|
403
404
|
red_pen = Pen.create!(name: 'red pen', price: 0.8, color: 'red')
|
404
405
|
blue_pen = Pen.create!(name: 'blue pen', price: 0.8, color: 'blue')
|
405
|
-
|
406
|
+
_black_pen = Pen.create!(name: 'black pen', price: 0.9, color: 'black')
|
406
407
|
|
407
408
|
actables = Pen.where(price: 0.8).actables
|
408
409
|
|
@@ -438,7 +439,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
438
439
|
|
439
440
|
context 'when they are defined via `scope`' do
|
440
441
|
it 'can be called from the submodel' do
|
441
|
-
|
442
|
+
_cheap_pen = Pen.create!(name: 'cheap pen', price: 0.5, color: 'blue')
|
442
443
|
expensive_pen = Pen.create!(name: 'expensive pen', price: 1, color: 'red')
|
443
444
|
|
444
445
|
expect(Product.with_price_higher_than(0.5).to_a).to eq([expensive_pen.acting_as])
|
@@ -528,6 +529,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
528
529
|
describe '.scope_for_create' do
|
529
530
|
it 'includes supermodel attributes' do
|
530
531
|
relation = Pen.where(name: 'new name', price: 1.4, color: 'red')
|
532
|
+
|
531
533
|
expect(relation.scope_for_create).to include('name')
|
532
534
|
expect(relation.scope_for_create['name']).to eq('new name')
|
533
535
|
end
|
@@ -562,7 +564,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
562
564
|
Object.send(:remove_const, :Pen)
|
563
565
|
end
|
564
566
|
|
565
|
-
it "should
|
567
|
+
it "should include the selected attribute when associating using 'eager_load'" do
|
566
568
|
class Pen < ActiveRecord::Base
|
567
569
|
acts_as :product , {association_method: :eager_load}
|
568
570
|
store_accessor :settings, :option1
|
@@ -570,7 +572,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
570
572
|
end
|
571
573
|
Pen.create pen_attributes
|
572
574
|
|
573
|
-
expect(Pen.select("'something' as thing").first['thing']).to
|
575
|
+
expect(Pen.select("'something' as thing").first['thing']).to eq 'something'
|
574
576
|
end
|
575
577
|
|
576
578
|
it "should include the selected attribute in the model when associating using 'includes'" do
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
8
8
|
- Manuel Meurer
|
9
|
-
|
9
|
+
- Chedli Bourguiba
|
10
|
+
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2021-02-09 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,34 @@ 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'
|
126
127
|
description: Simulate multi-table inheritance for activerecord models using a polymorphic
|
127
128
|
association
|
128
129
|
email:
|
129
130
|
- hsn.zamani@gmail.com
|
130
131
|
- manuel@krautcomputing.com
|
132
|
+
- bourguiba.chedli@gmail.com
|
131
133
|
executables:
|
132
134
|
- console
|
133
135
|
extensions: []
|
@@ -146,12 +148,9 @@ files:
|
|
146
148
|
- _config.yml
|
147
149
|
- active_record-acts_as.gemspec
|
148
150
|
- 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
|
151
|
+
- gemfiles/rails_6.0.gemfile
|
152
|
+
- gemfiles/rails_6.1.gemfile
|
153
|
+
- gemfiles/rails_master.gemfile
|
155
154
|
- lib/active_record/acts_as.rb
|
156
155
|
- lib/active_record/acts_as/class_methods.rb
|
157
156
|
- lib/active_record/acts_as/instance_methods.rb
|
@@ -169,11 +168,12 @@ files:
|
|
169
168
|
- spec/models.rb
|
170
169
|
- spec/rspec_matchers_spec.rb
|
171
170
|
- spec/spec_helper.rb
|
172
|
-
homepage: http://github.com/
|
171
|
+
homepage: http://github.com/chaadow/active_record-acts_as
|
173
172
|
licenses:
|
174
173
|
- MIT
|
175
|
-
metadata:
|
176
|
-
|
174
|
+
metadata:
|
175
|
+
source_code_uri: http://github.com/chaadow/active_record-acts_as
|
176
|
+
post_install_message:
|
177
177
|
rdoc_options: []
|
178
178
|
require_paths:
|
179
179
|
- lib
|
@@ -181,15 +181,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
181
|
requirements:
|
182
182
|
- - ">="
|
183
183
|
- !ruby/object:Gem::Version
|
184
|
-
version: '2.
|
184
|
+
version: '2.5'
|
185
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
186
|
requirements:
|
187
187
|
- - ">="
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '0'
|
190
190
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
192
|
-
signing_key:
|
191
|
+
rubygems_version: 3.2.3
|
192
|
+
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: Simulate multi-table inheritance for activerecord models
|
195
195
|
test_files:
|