arid_cache 1.3.5 → 1.3.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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arid_cache (1.3.4)
4
+ arid_cache (1.3.5)
5
5
  will_paginate
6
6
 
7
7
  GEM
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.5
1
+ 1.3.6
data/arid_cache.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{arid_cache}
8
- s.version = "1.3.5"
8
+ s.version = "1.3.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Karl Varga"]
@@ -66,11 +66,12 @@ module AridCache
66
66
  end
67
67
  Utilities.object_class(@options[:receiver]).send(@options[:proxy], @result)
68
68
  elsif is_activerecord_reflection?
69
+
69
70
  if @options.count_only?
70
71
  lazy_cache.count = @result.count
71
72
  else
72
- lazy_cache.klass = @result.proxy_reflection.klass if @result.respond_to?(:proxy_reflection)
73
73
  lazy_cache.ids = @result.collect { |r| r[:id] }
74
+ lazy_cache.klass = @result.respond_to?(:proxy_reflection) ? @result.proxy_reflection.klass : (is_empty? ? result_klass : @result.first.class)
74
75
  lazy_cache.count = @result.size
75
76
  end
76
77
  lazy_cache
@@ -83,7 +84,7 @@ module AridCache
83
84
  lazy_cache.ids = @result
84
85
  lazy_cache.count = 0
85
86
  lazy_cache.klass = result_klass
86
- lazy_cache
87
+ lazy_cache
87
88
  elsif @result.nil? # so we can distinguish a cached nil vs an empty cache
88
89
  lazy_cache.klass = NilClass
89
90
  lazy_cache
@@ -6,8 +6,9 @@ describe AridCache::CacheProxy::ResultProcessor do
6
6
  AridCache::CacheProxy::ResultProcessor.new(value, opts)
7
7
  end
8
8
 
9
- before :all do
9
+ before :each do
10
10
  AridCache.store.delete! # so no options get stored and interfere with other tests
11
+ AridCache.raw_with_options = true
11
12
  end
12
13
 
13
14
  describe "empty array" do
@@ -364,7 +365,6 @@ describe AridCache::CacheProxy::ResultProcessor do
364
365
 
365
366
  describe "raw with options handling" do
366
367
  before :each do
367
- AridCache.raw_with_options = true
368
368
  @user = User.make
369
369
  @company1 = Company.make
370
370
  @company2 = Company.make
@@ -404,4 +404,81 @@ describe AridCache::CacheProxy::ResultProcessor do
404
404
  value.should == [@company2.id]
405
405
  end
406
406
  end
407
+
408
+ describe "cached proxy_options result" do
409
+ before :each do
410
+ @user = User.make
411
+ @obj = Array.new([@user])
412
+ @obj.class_eval do
413
+ def respond_to?(method)
414
+ return true if method == :proxy_options
415
+ end
416
+ end
417
+ end
418
+
419
+ it "should store a CachedResult" do
420
+ new_result(@obj).to_cache.should be_a(AridCache::CacheProxy::CachedResult)
421
+ end
422
+
423
+ it "should be a reflection" do
424
+ new_result(@obj).is_activerecord_reflection?.should be_true
425
+ end
426
+
427
+ it "should set klass" do
428
+ cache = new_result(@obj).to_cache
429
+ cache.klass.should be(User)
430
+ end
431
+ end
432
+
433
+ describe "cached proxy_reflection result" do
434
+ before :each do
435
+ @user = User.make
436
+ @obj = Array.new([@user])
437
+ stub(@obj).proxy_reflection { stub(Object.new).klass { Company } }
438
+ end
439
+
440
+ it "should be a reflection" do
441
+ new_result(@obj).is_activerecord_reflection?.should be_true
442
+ end
443
+
444
+ it "should store a CachedResult" do
445
+ new_result(@obj).to_cache.should be_a(AridCache::CacheProxy::CachedResult)
446
+ end
447
+
448
+ it "should set klass from the proxy_reflection" do
449
+ cache = new_result(@obj).to_cache
450
+ cache.klass.should be(Company)
451
+ end
452
+ end
453
+
454
+ describe "deprecated" do
455
+ before :each do
456
+ AridCache.raw_with_options = false
457
+ end
458
+
459
+ describe "cached empty reflection-like result" do
460
+ before :each do
461
+ @user = User.make
462
+ @obj = Array.new([])
463
+ @obj.class_eval do
464
+ def respond_to?(method)
465
+ return true if method == :proxy_options
466
+ end
467
+ end
468
+ end
469
+
470
+ it "should store a CachedResult" do
471
+ new_result(@obj).to_cache.should be_a(AridCache::CacheProxy::CachedResult)
472
+ end
473
+
474
+ it "should be a reflection" do
475
+ new_result(@obj).is_activerecord_reflection?.should be_true
476
+ end
477
+
478
+ it "should fall back to the receiver class" do
479
+ cache = new_result(@obj, :receiver => User).to_cache
480
+ cache.klass.should be(User)
481
+ end
482
+ end
483
+ end
407
484
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arid_cache
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 5
10
- version: 1.3.5
9
+ - 6
10
+ version: 1.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Karl Varga