identity_cache 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 953d802de951edde24a15f5d1c073bebdaebe477
4
- data.tar.gz: 8a329ec724a1b9a9dba8435a47de9df84c7e8715
3
+ metadata.gz: e1ebdc0142ea9597f6053f9d07ef1c43bfbd5434
4
+ data.tar.gz: 4aacba1f352ff488dc13cf4eadb136369c5cb767
5
5
  SHA512:
6
- metadata.gz: 89fe603c343ad1fcd8c92d1bd12a7375a52b82a12c4c016256e1940ddbd0a1d66d1248b033640b661b8d30f21020cc29b5b5600a9a36591b5e03cac9238d0ca9
7
- data.tar.gz: 252d8f5066cc625fb799d490c3a4e5736283e82adf8817179c35697dbbb76ac07d28feeda32ad6e1d84db2440f820277578f3b9ea253997d64f3b1735e5fa74c
6
+ metadata.gz: a46686540738897cc446dda713c3d99dcb8c7fd513351894d7ac3ae3ee43c46baac0648eb0876cb1db1e5b2bfacf1ee2e8586b3aeb055d6126479794fd797dfa
7
+ data.tar.gz: 40af995454fc23abaddcab686808a62972758d586f6a4514314a0b30730fac71accbfd83cd671a9e90553dc5daa45a30ab162c21680e76b9691697e9bb8f7707
@@ -1,5 +1,9 @@
1
1
  # IdentityCache changelog
2
2
 
3
+ #### 0.4.0
4
+
5
+ - Return an array from fetched association to prevent chaining. Up to now, a relation was returned by default. (#287)
6
+
3
7
  #### 0.3.2
4
8
 
5
9
  - Deprecate returning non read-only records when cache is used. Set IdentityCache.fetch_readonly_records to true to avoid this. (#282)
data/dev.yml CHANGED
@@ -52,3 +52,6 @@ railgun:
52
52
  postgresql: 5432
53
53
  memcached: 11211
54
54
 
55
+ packages:
56
+ - git@github.com:Shopify/dev-shopify.git
57
+
@@ -42,22 +42,17 @@ module IdentityCache
42
42
 
43
43
  version = Gem::Version.new(IdentityCache::VERSION)
44
44
 
45
- # fetch_#{association} for a cache_has_many association returns a relation
46
- # when fetch_returns_relation is set to true and an array when set to false.
47
- mattr_accessor :fetch_returns_relation
48
- self.fetch_returns_relation = version < Gem::Version.new("0.4")
49
-
50
45
  # Inverse active record associations are set when loading embedded
51
46
  # cache_has_many associations from the cache when never_set_inverse_association
52
47
  # is false. When set to true, it will only set the inverse cached association.
53
48
  mattr_accessor :never_set_inverse_association
54
- self.never_set_inverse_association = version >= Gem::Version.new("0.4")
49
+ self.never_set_inverse_association = version >= Gem::Version.new("0.5")
55
50
 
56
51
  # Fetched records are not read-only and this could sometimes prevent IDC from
57
52
  # reflecting what's truly in the database when fetch_read_only_records is false.
58
53
  # When set to true, it will only return read-only records when cache is used.
59
54
  mattr_accessor :fetch_read_only_records
60
- self.fetch_read_only_records = version >= Gem::Version.new("0.4")
55
+ self.fetch_read_only_records = version >= Gem::Version.new("0.5")
61
56
 
62
57
  def included(base) #:nodoc:
63
58
  raise AlreadyIncludedError if base.include?(IdentityCache::ConfigurationDSL)
@@ -150,14 +145,6 @@ module IdentityCache
150
145
  result
151
146
  end
152
147
 
153
- def with_fetch_returns_relation(value = true)
154
- previous_value = self.fetch_returns_relation
155
- self.fetch_returns_relation = value
156
- yield
157
- ensure
158
- self.fetch_returns_relation = previous_value
159
- end
160
-
161
148
  def with_never_set_inverse_association(value = true)
162
149
  old_value = self.never_set_inverse_association
163
150
  self.never_set_inverse_association = value
@@ -236,11 +236,7 @@ module IdentityCache
236
236
  if IdentityCache.should_use_cache? && !#{association}.loaded?
237
237
  @#{options[:records_variable_name]} ||= #{options[:association_reflection].klass}.fetch_multi(#{options[:cached_ids_name]})
238
238
  else
239
- if IdentityCache.fetch_returns_relation
240
- #{association}
241
- else
242
- #{association}.to_a
243
- end
239
+ #{association}.to_a
244
240
  end
245
241
  end
246
242
 
@@ -435,7 +435,7 @@ module IdentityCache
435
435
  else
436
436
  send(association_name.to_sym)
437
437
  end
438
- assoc = assoc.to_ary if assoc.respond_to?(:to_ary) && !IdentityCache.fetch_returns_relation
438
+ assoc = assoc.to_ary if assoc.respond_to?(:to_ary)
439
439
  assoc
440
440
  end
441
441
 
@@ -1,4 +1,4 @@
1
1
  module IdentityCache
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  CACHE_VERSION = 6
4
4
  end
@@ -12,12 +12,9 @@ class DenormalizedHasManyTest < IdentityCache::TestCase
12
12
  @record.reload
13
13
  end
14
14
 
15
- def test_uncached_record_from_the_db_should_come_back_with_association_array_when_fetch_returns_array
16
- IdentityCache.with_fetch_returns_relation(false) do
17
- assert_equal IdentityCache.fetch_returns_relation, false
18
- record_from_db = Item.find(@record.id)
19
- assert_equal Array, record_from_db.fetch_associated_records.class
20
- end
15
+ def test_uncached_record_from_the_db_should_come_back_with_association_array
16
+ record_from_db = Item.find(@record.id)
17
+ assert_equal Array, record_from_db.fetch_associated_records.class
21
18
  end
22
19
 
23
20
  def test_uncached_record_from_the_db_will_use_normal_association
@@ -30,15 +27,12 @@ class DenormalizedHasManyTest < IdentityCache::TestCase
30
27
  assert_equal expected, record_from_db.fetch_associated_records
31
28
  end
32
29
 
33
- def test_on_cache_hit_record_should_come_back_with_cached_association_array_when_fetch_returns_array
34
- IdentityCache.with_fetch_returns_relation(false) do
35
- assert_equal IdentityCache.fetch_returns_relation, false
36
- Item.fetch(@record.id) # warm cache
30
+ def test_on_cache_hit_record_should_come_back_with_cached_association_array
31
+ Item.fetch(@record.id) # warm cache
37
32
 
38
- record_from_cache_hit = Item.fetch(@record.id)
39
- assert_equal @record, record_from_cache_hit
40
- assert_equal Array, record_from_cache_hit.fetch_associated_records.class
41
- end
33
+ record_from_cache_hit = Item.fetch(@record.id)
34
+ assert_equal @record, record_from_cache_hit
35
+ assert_equal Array, record_from_cache_hit.fetch_associated_records.class
42
36
  end
43
37
 
44
38
  def test_on_cache_hit_record_should_come_back_with_cached_association
@@ -113,12 +107,10 @@ class DenormalizedHasManyTest < IdentityCache::TestCase
113
107
  child.save!
114
108
  end
115
109
 
116
- def test_fetch_association_does_not_allow_chaining_when_fetch_returns_array
117
- IdentityCache.with_fetch_returns_relation(false) do
118
- check = proc { assert_equal false, Item.fetch(@record.id).fetch_associated_records.respond_to?(:where) }
119
- 2.times { check.call } # for miss and hit
120
- Item.transaction { check.call }
121
- end
110
+ def test_fetch_association_does_not_allow_chaining
111
+ check = proc { assert_equal false, Item.fetch(@record.id).fetch_associated_records.respond_to?(:where) }
112
+ 2.times { check.call } # for miss and hit
113
+ Item.transaction { check.call }
122
114
  end
123
115
 
124
116
  def test_never_set_inverse_association_on_cache_hit
@@ -197,12 +197,10 @@ class NormalizedHasManyTest < IdentityCache::TestCase
197
197
  @not_cached.save!
198
198
  end
199
199
 
200
- def test_fetch_association_does_not_allow_chaining_when_fetch_returns_array
201
- IdentityCache.with_fetch_returns_relation(false) do
202
- check = proc { assert_equal false, Item.fetch(@record.id).fetch_associated_records.respond_to?(:where) }
203
- 2.times { check.call } # for miss and hit
204
- Item.transaction { check.call }
205
- end
200
+ def test_fetch_association_does_not_allow_chaining
201
+ check = proc { assert_equal false, Item.fetch(@record.id).fetch_associated_records.respond_to?(:where) }
202
+ 2.times { check.call } # for miss and hit
203
+ Item.transaction { check.call }
206
204
  end
207
205
 
208
206
  def test_returned_records_should_be_readonly_on_cache_hit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: identity_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Lopez
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2016-08-10 00:00:00.000000000 Z
17
+ date: 2017-02-02 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: ar_transaction_changes