active_record-acts_as 2.0.4 → 2.0.5
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 +4 -4
- data/CHANGELOG.md +3 -2
- data/README.md +1 -1
- data/lib/active_record/acts_as/instance_methods.rb +1 -6
- data/lib/active_record/acts_as/relation.rb +5 -2
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +24 -2
- data/spec/models.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f5963e720c4d133aec9bbcadb5d8034e805c5da
|
4
|
+
data.tar.gz: b72a5773b65e24a08baa22ef43ff420f25d24d29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6308fb4da307ca8d479ed40e6f6e1245dec31cbdc031ed28f6ebb4832dc1d282f28622235d074b296c9783ee1eb7c82e1aab6a93cc5fbf03f96918e824927a29
|
7
|
+
data.tar.gz: cb452a38e28515964324e1540cf562631cdb0c3e403fdb9f512682a36d5076a9ad0f31d4b989fffc2fe65da828fe46266a91ed3cd3991985088821bca482f016
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@ 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
|
-
## [
|
7
|
+
## [2.0.4] - 2016-12-07
|
8
8
|
### Fixed
|
9
9
|
- Touch associated objects if supermodel is updated
|
10
10
|
|
@@ -32,7 +32,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
32
32
|
### Fixed
|
33
33
|
- Fixed `remove_actable` migration helper (https://github.com/hzamani/active_record-acts_as/pull/71, thanks to [nuclearpidgeon](https://github.com/nuclearpidgeon)!)
|
34
34
|
|
35
|
-
[Unreleased]: https://github.com/hzamani/active_record-acts_as/compare/v2.0.
|
35
|
+
[Unreleased]: https://github.com/hzamani/active_record-acts_as/compare/v2.0.4...HEAD
|
36
|
+
[2.0.4]: https://github.com/hzamani/active_record-acts_as/compare/v2.0.3...v2.0.4
|
36
37
|
[2.0.3]: https://github.com/hzamani/active_record-acts_as/compare/v2.0.2...v2.0.3
|
37
38
|
[2.0.2]: https://github.com/hzamani/active_record-acts_as/compare/v2.0.1...v2.0.2
|
38
39
|
[2.0.1]: https://github.com/hzamani/active_record-acts_as/compare/v2.0.0...v2.0.1
|
data/README.md
CHANGED
@@ -167,7 +167,7 @@ acts_as :person, -> { includes(:friends) }
|
|
167
167
|
```
|
168
168
|
|
169
169
|
`actable` support all `belongs_to` options, where defaults are these:
|
170
|
-
`polymorphic: true, dependent: :
|
170
|
+
`polymorphic: true, dependent: :destroy, autosave: true`
|
171
171
|
|
172
172
|
Make sure you know what you are doing when overwriting `polymorphic` option.
|
173
173
|
|
@@ -23,11 +23,6 @@ module ActiveRecord
|
|
23
23
|
!acting_as.id.nil? && !acting_as_foreign_key.nil?
|
24
24
|
end
|
25
25
|
|
26
|
-
def touch_actable
|
27
|
-
return unless changed?
|
28
|
-
acting_as.touch
|
29
|
-
end
|
30
|
-
|
31
26
|
def actable_must_be_valid
|
32
27
|
if validates_actable
|
33
28
|
unless acting_as.valid?
|
@@ -97,7 +92,7 @@ module ActiveRecord
|
|
97
92
|
end
|
98
93
|
|
99
94
|
def touch
|
100
|
-
acting_as.touch
|
95
|
+
acting_as.touch if acting_as.persisted?
|
101
96
|
end
|
102
97
|
|
103
98
|
def respond_to?(name, include_private = false, as_original_class = false)
|
@@ -24,7 +24,10 @@ module ActiveRecord
|
|
24
24
|
end
|
25
25
|
}
|
26
26
|
validate :actable_must_be_valid
|
27
|
-
|
27
|
+
|
28
|
+
unless touch == false
|
29
|
+
after_update :touch, if: :changed?
|
30
|
+
end
|
28
31
|
|
29
32
|
before_save do
|
30
33
|
@_acting_as_changed = acting_as.changed?
|
@@ -70,7 +73,7 @@ module ActiveRecord
|
|
70
73
|
def actable(options = {})
|
71
74
|
name = options.delete(:as) || :actable
|
72
75
|
|
73
|
-
reflections = belongs_to
|
76
|
+
reflections = belongs_to(name, options.reverse_merge(polymorphic: true, dependent: :destroy, autosave: true))
|
74
77
|
|
75
78
|
cattr_reader(:actable_reflection) { reflections.stringify_keys[name.to_s] }
|
76
79
|
|
data/spec/acts_as_spec.rb
CHANGED
@@ -152,7 +152,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
152
152
|
|
153
153
|
describe "._reflections" do
|
154
154
|
it "merges the reflections on both superclass and subclass" do
|
155
|
-
expect(Pen._reflections.length).to eq(Product._reflections.length +
|
155
|
+
expect(Pen._reflections.length).to eq(Product._reflections.length + 3)
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
@@ -198,6 +198,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
198
198
|
"name": "pen",
|
199
199
|
"price": 0.8,
|
200
200
|
"store_id": null,
|
201
|
+
"pen_collection_id": null,
|
201
202
|
"settings": {"global_option":"globalvalue", "option1":"value1"},
|
202
203
|
"color": "red",
|
203
204
|
"created_at": ' + pen.created_at.to_json + ',
|
@@ -214,6 +215,20 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
214
215
|
expect(pen.color).to eq('red')
|
215
216
|
end
|
216
217
|
|
218
|
+
context "deleting" do
|
219
|
+
it "destroys associated records defined with `has_many dependent: :destroy` on supermodel" do
|
220
|
+
pen.save!
|
221
|
+
pen.buyers.create!
|
222
|
+
expect { pen.destroy }.to change { Buyer.count }.by(-1)
|
223
|
+
end
|
224
|
+
|
225
|
+
it "destroys associated records defined with `has_many dependent: :destroy` on submodel" do
|
226
|
+
pen.save!
|
227
|
+
pen.pen_caps.create!
|
228
|
+
expect { pen.destroy }.to change { PenCap.count }.by(-1)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
217
232
|
context "touching" do
|
218
233
|
it "touches supermodel on save" do
|
219
234
|
pen.save
|
@@ -316,7 +331,13 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
316
331
|
|
317
332
|
context "includes supermodel attributes in .to_json response" do
|
318
333
|
it "unless the submodel instance association doesn't exist" do
|
319
|
-
expect(JSON.parse(isolated_pen.to_json)).to eq(JSON.parse('
|
334
|
+
expect(JSON.parse(isolated_pen.to_json)).to eq(JSON.parse('''
|
335
|
+
{
|
336
|
+
"id": null,
|
337
|
+
"color": "red",
|
338
|
+
"pen_collection_id": null
|
339
|
+
}
|
340
|
+
'''))
|
320
341
|
end
|
321
342
|
|
322
343
|
it "if the submodel instance association exists" do
|
@@ -328,6 +349,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
328
349
|
"name": "pen",
|
329
350
|
"price": 0.8,
|
330
351
|
"store_id": null,
|
352
|
+
"pen_collection_id": null,
|
331
353
|
"settings": {},
|
332
354
|
"color": "red",
|
333
355
|
"created_at": ' + pen.created_at.to_json + ',
|
data/spec/models.rb
CHANGED
@@ -4,7 +4,7 @@ require 'active_record/acts_as'
|
|
4
4
|
class Product < ActiveRecord::Base
|
5
5
|
actable
|
6
6
|
belongs_to :store, touch: true
|
7
|
-
has_many :buyers
|
7
|
+
has_many :buyers, dependent: :destroy
|
8
8
|
validates_presence_of :name, :price
|
9
9
|
store :settings, accessors: [:global_option]
|
10
10
|
|
@@ -25,7 +25,7 @@ class Pen < ActiveRecord::Base
|
|
25
25
|
acts_as :product
|
26
26
|
store_accessor :settings, :option1
|
27
27
|
|
28
|
-
has_many :pen_caps
|
28
|
+
has_many :pen_caps, dependent: :destroy
|
29
29
|
belongs_to :pen_collection, touch: true
|
30
30
|
|
31
31
|
validates_presence_of :color
|
@@ -100,7 +100,7 @@ def initialize_schema
|
|
100
100
|
end
|
101
101
|
|
102
102
|
create_table :pen_caps do |t|
|
103
|
-
t.integer :
|
103
|
+
t.integer :pen_id
|
104
104
|
end
|
105
105
|
|
106
106
|
create_table :inventory_pen_lids do |t|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-acts_as
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|