cacheable_delegator 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjRjYTRkYjIwNmIzYmQ1NTY4OTFlNzIzNDc5ZDJkYWZlYjg5MGJkNA==
4
+ OGMxYmRiOTU2OTM4YmU0YTJkMzJmYTMxODNlMWUyYmM4YmQ5YTJhMw==
5
5
  data.tar.gz: !binary |-
6
- NDVjODg0N2EwYzQzZjliMmU1MmVjYWY3MmVkMGMwYjFkY2E1YzIzNA==
6
+ NDFjZjQxZjM5ZTA4YTZjOWFlY2ZiMDViMGYwYWEzZWJmNWExNmNhOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- N2U0MThmYjY5ZGQ5ZmZkYTEyNjJlNWJiZmIxYjc4OTEwZmIxODRhODhhNDBi
10
- ZGQ2OWU0Y2ZjYTEwNTk4ZGEyNmZkZDdkZjAyZDJjNzU4ZWFiODRkNmQyMTA0
11
- NjBhMzI3NTc5MzcxZGZhZDU1NzIwNTExZmY0OWM0YTliNjkyYWU=
9
+ NGY0YzI5MDU3OGI5Yjk5ZjExNDZhNThiMmE1NmE2Yjk4MzMwMmMzODgxODk5
10
+ OTRhYTEwMmRiOGJiMmNiODQ4MzFjNjI2MDc5NjBkMThkNmYyOWFkY2YwNWJj
11
+ MGQxYjYxMDYzODYwMWQwNTQ3NGUwNDJmNjA2OTU0MzQyZTUzMTM=
12
12
  data.tar.gz: !binary |-
13
- ZjZkYzAxZjgyN2RlNjhmOTczNmRlNzI0MTUwMWVkNDAwYThlOTJhYjY2ZjZk
14
- Mzc0ODIyZjA1YWMzZmFlYmZmMDdlNjU3ODRjMTY5NThlMGZjMTAyZmQxMmI1
15
- MzEzMzBkOGU2NWQ1OTQxZjZjZmZhMTE0OWRiMDQ2MmY2NWE2MWU=
13
+ OTU2M2Q4M2FiOTRlN2MyYTNhZGJmMzBlYzdkNzVjNDdlYjRhNDI1NmI2NTBk
14
+ OWY0MDdiYjFkMDQ3NGYwNzIyNzUzOWU4MDZkY2VjMzRjYTUwNzZiMmIwYWRh
15
+ NmJiMWJhNzY1Yzc5MjY3ZGUzNjZjNjA4NjBlMThkOGY1M2MxODE=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cacheable_delegator"
8
- s.version = "1.2.1"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Nguyen"]
@@ -195,14 +195,18 @@ module CacheableDelegator
195
195
  # instance method
196
196
  # pre: must already have source_record set
197
197
 
198
-
199
- def refresh_cache!
198
+ def refresh_cache
200
199
  atts = self.class.build_attributes_hash(self.source_record)
201
- self.update_attributes(obj)
200
+ self.assign_attributes(atts)
202
201
 
203
202
  self
204
203
  end
205
204
 
205
+ def refresh_cache!
206
+ refresh_cache
207
+ self.save
208
+ end
209
+
206
210
 
207
211
  end
208
212
 
@@ -39,13 +39,17 @@ describe CacheableDelegator do
39
39
  context 'explicit delegations' do
40
40
  context 'it should delegate all the things' do
41
41
  before(:each) do
42
- @my_record = MyRecord.create
42
+ @my_record = MyRecord.create(name: 'Namond')
43
43
  @cache_record = MyCachedRecord.create
44
44
  @cache_record.source_record = @my_record
45
45
 
46
46
  @cache_record.save
47
47
  end
48
48
 
49
+ it 'should not take in source_record atts unless explicitly commanded' do
50
+ expect(@cache_record.name).to_not eq 'Namond'
51
+ end
52
+
49
53
  it 'should have a :source_record through the #belongs_to relation' do
50
54
  expect(@cache_record.source_record).to eq @my_record
51
55
  end
@@ -62,6 +66,58 @@ describe CacheableDelegator do
62
66
  end
63
67
 
64
68
 
69
+ context 'cache building and refreshing' do
70
+ before do
71
+ @my_record = MyRecord.create(name: 'Namond', awesome_value: 10)
72
+ @cache_record = MyCachedRecord.create_cache(@my_record)
73
+ end
74
+
75
+ describe '.create_cache' do
76
+
77
+ it 'should create a new cached_record' do
78
+ expect(@cache_record).to be_valid
79
+ expect(@cache_record).not_to be_new_record
80
+ end
81
+
82
+ it 'should associate cache_record\'s source_record' do
83
+ expect(@cache_record.source_record).to eq @my_record
84
+ end
85
+
86
+ it 'should have same column data values' do
87
+ expect(@cache_record.name).to eq 'Namond'
88
+ end
89
+
90
+ it 'should have derived values' do
91
+ expect(@cache_record.read_attribute :foo_double_awesome_value).to eq @my_record.send :foo_double_awesome_value
92
+ end
93
+ end
94
+
95
+ describe '#refresh_cache' do
96
+ it 'should assign attributes, not update them' do
97
+ @my_record.update_attributes name: 'Mike'
98
+ @cache_record.refresh_cache
99
+
100
+ expect(@cache_record).to be_changed
101
+ end
102
+ end
103
+
104
+ describe '#refresh_cache!' do
105
+ before(:each) do
106
+ @my_record.update_attributes(name: 'Randy', awesome_value: 99)
107
+ @cache_record.refresh_cache!
108
+ end
109
+
110
+ it 'should update the column data values' do
111
+ expect(@cache_record.name).to eq 'Randy'
112
+ end
113
+
114
+ it 'should update the derived values' do
115
+ expect(@cache_record.read_attribute :foo_double_awesome_value).to eq @my_record.send :foo_double_awesome_value
116
+ end
117
+ end
118
+ end
119
+
120
+
65
121
 
66
122
 
67
123
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cacheable_delegator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Nguyen