active_record-acts_as 1.0.5 → 1.0.6
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/lib/active_record/acts_as/instance_methods.rb +17 -1
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +28 -1
- data/spec/models.rb +4 -0
- 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: 64cbfe3c6d86757fceca3cd920138468bac93d4b
|
4
|
+
data.tar.gz: 4687d0558602f189e3c771174aa986afadf3b4cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26021ad15fd01db7dcbad29e912ed2a6b96a66ed148f8e442bca9f8c5ace9786c4171b6d318773639a1de20b04ce0a28420f72ef1dd0d2c5a218189ead20c883
|
7
|
+
data.tar.gz: 3912076316e37325948021045815231891e045fa5ac5488830399d68b61d5d1e5296fc20a771efbc4ee7184a56b2ad79db76b7e459fd6a817f20f74e01a80e17
|
@@ -46,7 +46,23 @@ module ActiveRecord
|
|
46
46
|
acting_as.send(:write_attribute, attr_name, value, *args, &block)
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
|
+
def read_store_attribute(store_attribute, key)
|
51
|
+
if attribute_method?(store_attribute.to_s)
|
52
|
+
super
|
53
|
+
else
|
54
|
+
acting_as.read_store_attribute(store_attribute, key)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def write_store_attribute(store_attribute, key, value)
|
59
|
+
if attribute_method?(store_attribute.to_s)
|
60
|
+
super
|
61
|
+
else
|
62
|
+
acting_as.send(:write_store_attribute, store_attribute, key, value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
private :write_attribute, :write_store_attribute
|
50
66
|
|
51
67
|
def attributes
|
52
68
|
acting_as_persisted? ? acting_as.attributes.except(acting_as_reflection.type, acting_as_reflection.foreign_key).merge(super) : super
|
data/spec/acts_as_spec.rb
CHANGED
@@ -123,6 +123,33 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
123
123
|
expect(pen.present).to eq("pen - $0.8")
|
124
124
|
end
|
125
125
|
|
126
|
+
it 'responds to serialized attribute' do
|
127
|
+
expect(pen).to respond_to('option1')
|
128
|
+
expect(isolated_pen).to respond_to('option2')
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'responds to supermodel serialized attribute' do
|
132
|
+
expect(pen).to respond_to('global_option')
|
133
|
+
expect(isolated_pen).to respond_to('global_option')
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'does not respond to other models serialized attribute' do
|
137
|
+
expect(pen).to_not respond_to('option2')
|
138
|
+
expect(isolated_pen).to_not respond_to('option1')
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'saves supermodel serialized attribute on save' do
|
142
|
+
pen.option1 = 'value1'
|
143
|
+
pen.global_option = 'globalvalue'
|
144
|
+
pen.save
|
145
|
+
pen.reload
|
146
|
+
isolated_pen.save
|
147
|
+
isolated_pen.reload
|
148
|
+
expect(pen.option1).to eq('value1')
|
149
|
+
expect(isolated_pen).to_not respond_to('option1')
|
150
|
+
expect(JSON.parse(pen.to_json)).to eq(JSON.parse('{"id":' + pen.id.to_s + ',"name":"pen","price":0.8,"store_id":null,"settings":{"global_option":"globalvalue","option1":"value1"},"color":"red"}'))
|
151
|
+
end
|
152
|
+
|
126
153
|
it "saves supermodel attributes on save" do
|
127
154
|
pen.save
|
128
155
|
pen.reload
|
@@ -185,7 +212,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
185
212
|
it "if the submodel instance association exists" do
|
186
213
|
p = Product.new(name: 'Test Pen', price: 0.8, actable: pen)
|
187
214
|
p.save
|
188
|
-
expect(JSON.parse(pen.to_json)).to eq(JSON.parse('{"id":' + pen.id.to_s + ',"name":"pen","price":0.8,"store_id":null,"color":"red"}'))
|
215
|
+
expect(JSON.parse(pen.to_json)).to eq(JSON.parse('{"id":' + pen.id.to_s + ',"name":"pen","price":0.8,"store_id":null,"settings": {},"color":"red"}'))
|
189
216
|
end
|
190
217
|
end
|
191
218
|
|
data/spec/models.rb
CHANGED
@@ -5,6 +5,7 @@ class Product < ActiveRecord::Base
|
|
5
5
|
actable
|
6
6
|
belongs_to :store
|
7
7
|
validates_presence_of :name, :price
|
8
|
+
store :settings, accessors: [:global_option]
|
8
9
|
|
9
10
|
def present
|
10
11
|
"#{name} - $#{price}"
|
@@ -17,6 +18,7 @@ end
|
|
17
18
|
|
18
19
|
class Pen < ActiveRecord::Base
|
19
20
|
acts_as :product
|
21
|
+
store_accessor :settings, :option1
|
20
22
|
|
21
23
|
validates_presence_of :color
|
22
24
|
end
|
@@ -24,6 +26,7 @@ end
|
|
24
26
|
class IsolatedPen < ActiveRecord::Base
|
25
27
|
self.table_name = :pens
|
26
28
|
acts_as :product, validates_actable: false
|
29
|
+
store_accessor :settings, :option2
|
27
30
|
|
28
31
|
validates_presence_of :color
|
29
32
|
end
|
@@ -60,6 +63,7 @@ initialize_database do
|
|
60
63
|
t.string :name
|
61
64
|
t.float :price
|
62
65
|
t.integer :store_id
|
66
|
+
t.text :settings
|
63
67
|
t.actable
|
64
68
|
end
|
65
69
|
|
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: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|