active_record-acts_as 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/lib/active_record/acts_as/relation.rb +3 -2
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/actable_spec.rb +12 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 343f5f0ec73829580cfedcf39acaf118c672a73b
|
4
|
+
data.tar.gz: 07f06e2d9e8102b00030627222b2c9781593396b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e48b05426332a971ab3b175178ff758ff5a67b38892f1e98c101eb23cdbbc5ae5543b7ed29ff50af4708a03ec2a0ac446547dd7469080b24d7306d28449c13d
|
7
|
+
data.tar.gz: f642986b3c589b62663b94641abd58aacb1260e1ae85bc237ab3ef539e6572eb17bee0096989ab6f78ccc1b490ec9012b6532196915bbd880105a467c09937d3
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ 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
|
+
## [2.2.0] - 2017-04-08
|
8
|
+
### Added
|
9
|
+
- Added support for calling superclass methods on the subclass or subclass relations
|
10
|
+
|
7
11
|
## [2.1.1] - 2017-03-22
|
8
12
|
### Fixed
|
9
13
|
- Fix querying subclass with `where`, for `enum` (and possibly other) attributes the detection whether the attribute is defined on the superclass or subclass didn't work.
|
@@ -61,7 +65,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
61
65
|
### Fixed
|
62
66
|
- Fixed `remove_actable` migration helper (https://github.com/hzamani/active_record-acts_as/pull/71, thanks to [nuclearpidgeon](https://github.com/nuclearpidgeon)!)
|
63
67
|
|
64
|
-
[Unreleased]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.
|
68
|
+
[Unreleased]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.2.0...HEAD
|
69
|
+
[2.2.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.1.1...v2.2.0
|
65
70
|
[2.1.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.1.0...v2.1.1
|
66
71
|
[2.1.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.9...v2.1.0
|
67
72
|
[2.0.9]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.8...v2.0.9
|
@@ -8,7 +8,8 @@ module ActiveRecord
|
|
8
8
|
options, scope = scope, nil if Hash === scope
|
9
9
|
association_method = options.delete(:association_method)
|
10
10
|
touch = options.delete(:touch)
|
11
|
-
|
11
|
+
as = options.delete(:as) || :actable
|
12
|
+
options = options.reverse_merge(as: as, validate: false, autosave: true, inverse_of: as)
|
12
13
|
|
13
14
|
cattr_reader(:validates_actable) { options.delete(:validates_actable) == false ? false : true }
|
14
15
|
|
@@ -77,7 +78,7 @@ module ActiveRecord
|
|
77
78
|
def actable(options = {})
|
78
79
|
name = options.delete(:as) || :actable
|
79
80
|
|
80
|
-
reflections = belongs_to(name, options.reverse_merge(polymorphic: true, dependent: :destroy, autosave: true))
|
81
|
+
reflections = belongs_to(name, options.reverse_merge(polymorphic: true, dependent: :destroy, autosave: true, inverse_of: to_s.underscore))
|
81
82
|
|
82
83
|
cattr_reader(:actable_reflection) { reflections.stringify_keys[name.to_s] }
|
83
84
|
|
data/spec/actable_spec.rb
CHANGED
@@ -30,14 +30,19 @@ RSpec.describe "ActiveRecord::Base subclass with #actable" do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe "
|
34
|
-
context "
|
35
|
-
it
|
36
|
-
|
33
|
+
describe "#specific" do
|
34
|
+
context "when a submodel instance exists" do
|
35
|
+
it 'returns it' do
|
36
|
+
pen.save!
|
37
|
+
pen.color = 'cyan'
|
38
|
+
expect(pen.acting_as.specific).to eq(pen)
|
39
|
+
expect(pen.acting_as.specific.color).to eq('cyan')
|
37
40
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when no submodel instance exists" do
|
44
|
+
it 'returns nil' do
|
45
|
+
expect(subject.new.specific).to be_nil
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|