active_record-acts_as 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/active_record/acts_as/instance_methods.rb +4 -0
- data/lib/active_record/acts_as/relation.rb +8 -0
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +31 -15
- data/spec/models.rb +13 -1
- 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: 9cc915fa77c939869175617ca452707352f1c958
|
4
|
+
data.tar.gz: 49e729130f7d047cd550791e47d91f8aae02233e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a33e98e3a6fe6df92f4e3a89b597ae503e3091deb9b65c73596d38b14cb29bcf12d0d900e9f0e2779b36e7e902f3b5a767db18b550c6b290e0bee48aee7fd9e7
|
7
|
+
data.tar.gz: 4cbe6d4237c1ca1c198bd95a0176ee3cbbe561b773073f3a9168fe739da35a006cdb316467c0a2fc8b3856fcb1a9e4ea498b86128cd16e3b11b7dad44a0da619
|
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
|
+
## [Unreleased]
|
8
|
+
### Fixed
|
9
|
+
- Touch associated objects if supermodel is updated
|
10
|
+
|
7
11
|
## [2.0.3] - 2016-11-07
|
8
12
|
### Fixed
|
9
13
|
- Fix defining associations on `acting_as` model after calling `acting_as`
|
@@ -26,6 +26,14 @@ module ActiveRecord
|
|
26
26
|
validate :actable_must_be_valid
|
27
27
|
after_update :touch_actable unless touch == false
|
28
28
|
|
29
|
+
before_save do
|
30
|
+
@_acting_as_changed = acting_as.changed?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
after_commit do
|
34
|
+
@_acting_as_changed = nil
|
35
|
+
end
|
36
|
+
|
29
37
|
cattr_reader(:acting_as_reflection) { reflections.stringify_keys[name.to_s] }
|
30
38
|
cattr_reader(:acting_as_name) { name.to_s }
|
31
39
|
cattr_reader(:acting_as_model) { (options[:class_name] || name.to_s.camelize).constantize }
|
data/spec/acts_as_spec.rb
CHANGED
@@ -214,25 +214,41 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
214
214
|
expect(pen.color).to eq('red')
|
215
215
|
end
|
216
216
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
217
|
+
context "touching" do
|
218
|
+
it "touches supermodel on save" do
|
219
|
+
pen.save
|
220
|
+
pen.reload
|
221
|
+
update = pen.product.updated_at
|
222
|
+
pen.color = "gray"
|
223
|
+
pen.save
|
224
|
+
expect(pen.updated_at).not_to eq(update)
|
225
|
+
end
|
225
226
|
|
226
|
-
|
227
|
-
|
227
|
+
it "touches supermodel only when attributes changed" do
|
228
|
+
pen.save
|
228
229
|
|
229
|
-
|
230
|
-
|
230
|
+
expect { pen.save }.to_not change { pen.reload.product.updated_at }
|
231
|
+
end
|
231
232
|
|
232
|
-
|
233
|
-
|
233
|
+
it "touches supermodel when #touch is called" do
|
234
|
+
pen.save
|
235
|
+
|
236
|
+
expect { pen.touch }.to change { pen.product.updated_at }
|
237
|
+
end
|
234
238
|
|
235
|
-
|
239
|
+
it "touches belongs_to-touch associations if supermodel is updated" do
|
240
|
+
pen.build_pen_collection
|
241
|
+
pen.save!
|
242
|
+
pen.name = "superpen"
|
243
|
+
expect { pen.save! }.to change { pen.pen_collection.updated_at }
|
244
|
+
end
|
245
|
+
|
246
|
+
it "touches belongs_to-touch associations of supermodel when submodel is updated" do
|
247
|
+
pen.store = store
|
248
|
+
pen.save!
|
249
|
+
pen.color = "gray"
|
250
|
+
expect { pen.save! }.to change { pen.store.updated_at }
|
251
|
+
end
|
236
252
|
end
|
237
253
|
|
238
254
|
it "raises NoMethodEror on unexisting method call" do
|
data/spec/models.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_record/acts_as'
|
|
3
3
|
|
4
4
|
class Product < ActiveRecord::Base
|
5
5
|
actable
|
6
|
-
belongs_to :store
|
6
|
+
belongs_to :store, touch: true
|
7
7
|
has_many :buyers
|
8
8
|
validates_presence_of :name, :price
|
9
9
|
store :settings, accessors: [:global_option]
|
@@ -17,11 +17,16 @@ class Product < ActiveRecord::Base
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
class PenCollection < ActiveRecord::Base
|
21
|
+
has_many :pens
|
22
|
+
end
|
23
|
+
|
20
24
|
class Pen < ActiveRecord::Base
|
21
25
|
acts_as :product
|
22
26
|
store_accessor :settings, :option1
|
23
27
|
|
24
28
|
has_many :pen_caps
|
29
|
+
belongs_to :pen_collection, touch: true
|
25
30
|
|
26
31
|
validates_presence_of :color
|
27
32
|
end
|
@@ -67,8 +72,13 @@ end
|
|
67
72
|
|
68
73
|
def initialize_schema
|
69
74
|
initialize_database do
|
75
|
+
create_table :pen_collections do |t|
|
76
|
+
t.timestamps null: true
|
77
|
+
end
|
78
|
+
|
70
79
|
create_table :pens do |t|
|
71
80
|
t.string :color
|
81
|
+
t.integer :pen_collection_id
|
72
82
|
end
|
73
83
|
|
74
84
|
create_table :products do |t|
|
@@ -82,6 +92,7 @@ def initialize_schema
|
|
82
92
|
|
83
93
|
create_table :stores do |t|
|
84
94
|
t.string :name
|
95
|
+
t.timestamps null: true
|
85
96
|
end
|
86
97
|
|
87
98
|
create_table :buyers do |t|
|
@@ -103,4 +114,5 @@ def initialize_schema
|
|
103
114
|
end
|
104
115
|
end
|
105
116
|
end
|
117
|
+
|
106
118
|
initialize_schema
|
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.4
|
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-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|