garner 0.5.0 → 0.5.1
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/.rubocop.yml +1 -30
 - data/.rubocop_todo.yml +49 -0
 - data/.travis.yml +2 -0
 - data/CHANGELOG.md +6 -0
 - data/Gemfile +1 -1
 - data/README.md +2 -2
 - data/garner.gemspec +2 -2
 - data/lib/garner/cache.rb +1 -1
 - data/lib/garner/strategies/binding/key/binding_index.rb +1 -1
 - data/lib/garner/version.rb +1 -1
 - data/spec/garner/cache/context_spec.rb +4 -4
 - data/spec/garner/cache/identity_spec.rb +6 -6
 - data/spec/garner/cache_spec.rb +14 -6
 - data/spec/garner/config_spec.rb +1 -1
 - data/spec/garner/mixins/mongoid/document_spec.rb +12 -12
 - data/spec/garner/mixins/mongoid/identity_spec.rb +25 -25
 - data/spec/garner/mixins/rack_spec.rb +6 -6
 - data/spec/garner/strategies/binding/invalidation/binding_index_spec.rb +1 -1
 - data/spec/garner/strategies/binding/invalidation/touch_spec.rb +3 -3
 - data/spec/garner/strategies/binding/key/binding_index_spec.rb +44 -44
 - data/spec/garner/strategies/binding/key/cache_key_spec.rb +2 -2
 - data/spec/garner/strategies/binding/key/safe_cache_key_spec.rb +12 -12
 - data/spec/garner/strategies/context/key/caller_spec.rb +17 -17
 - data/spec/garner/strategies/context/key/jsonp_spec.rb +2 -2
 - data/spec/garner/strategies/context/key/request_get_spec.rb +3 -3
 - data/spec/garner/strategies/context/key/request_path_spec.rb +3 -3
 - data/spec/garner/strategies/context/key/request_post_spec.rb +3 -3
 - data/spec/garner/version_spec.rb +2 -2
 - data/spec/integration/active_record_spec.rb +4 -4
 - data/spec/integration/grape_spec.rb +1 -1
 - data/spec/integration/mongoid_spec.rb +57 -57
 - data/spec/integration/rack_spec.rb +7 -7
 - data/spec/integration/sinatra_spec.rb +1 -1
 - data/spec/shared/binding_invalidation_strategy.rb +1 -1
 - data/spec/shared/binding_key_strategy.rb +4 -4
 - data/spec/shared/conditional_get.rb +13 -13
 - data/spec/shared/context_key_strategy.rb +2 -2
 - data/spec/spec_helper.rb +1 -0
 - metadata +8 -7
 
| 
         @@ -6,7 +6,7 @@ describe Garner::Strategies::Context::Key::Jsonp do 
     | 
|
| 
       6 
6 
     | 
    
         
             
                @request = Rack::Request.new('REQUEST_METHOD' => 'GET', 'QUERY_STRING' => 'callback=jQuery21435&_=34234')
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                @mock_context = double('object')
         
     | 
| 
       9 
     | 
    
         
            -
                @mock_context. 
     | 
| 
      
 9 
     | 
    
         
            +
                allow(@mock_context).to receive(:request) { @request }
         
     | 
| 
       10 
10 
     | 
    
         
             
              end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
              subject { Garner::Strategies::Context::Key::Jsonp }
         
     | 
| 
         @@ -17,6 +17,6 @@ describe Garner::Strategies::Context::Key::Jsonp do 
     | 
|
| 
       17 
17 
     | 
    
         
             
                request_get = Garner::Strategies::Context::Key::RequestGet
         
     | 
| 
       18 
18 
     | 
    
         
             
                applied_identity = request_get.apply(@cache_identity, @mock_context)
         
     | 
| 
       19 
19 
     | 
    
         
             
                subject.apply(applied_identity, @mock_context)
         
     | 
| 
       20 
     | 
    
         
            -
                @cache_identity.key_hash[:request_params]. 
     | 
| 
      
 20 
     | 
    
         
            +
                expect(@cache_identity.key_hash[:request_params]).to eq({})
         
     | 
| 
       21 
21 
     | 
    
         
             
              end
         
     | 
| 
       22 
22 
     | 
    
         
             
            end
         
     | 
| 
         @@ -9,7 +9,7 @@ describe Garner::Strategies::Context::Key::RequestGet do 
     | 
|
| 
       9 
9 
     | 
    
         
             
                    @request = Rack::Request.new('REQUEST_METHOD' => method, 'QUERY_STRING' => 'foo=bar')
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
                    @mock_context = double('object')
         
     | 
| 
       12 
     | 
    
         
            -
                    @mock_context. 
     | 
| 
      
 12 
     | 
    
         
            +
                    allow(@mock_context).to receive(:request) { @request }
         
     | 
| 
       13 
13 
     | 
    
         
             
                  end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                  subject { Garner::Strategies::Context::Key::RequestGet }
         
     | 
| 
         @@ -18,12 +18,12 @@ describe Garner::Strategies::Context::Key::RequestGet do 
     | 
|
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                  it 'adds :request_params to the key' do
         
     | 
| 
       20 
20 
     | 
    
         
             
                    subject.apply(@cache_identity, @mock_context)
         
     | 
| 
       21 
     | 
    
         
            -
                    @cache_identity.key_hash[:request_params]. 
     | 
| 
      
 21 
     | 
    
         
            +
                    expect(@cache_identity.key_hash[:request_params]).to eq('foo' => 'bar')
         
     | 
| 
       22 
22 
     | 
    
         
             
                  end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                  it 'appends to an existing key hash' do
         
     | 
| 
       25 
25 
     | 
    
         
             
                    @cache_identity.key(x: :y)
         
     | 
| 
       26 
     | 
    
         
            -
                    subject.apply(@cache_identity, @mock_context).key_hash. 
     | 
| 
      
 26 
     | 
    
         
            +
                    expect(subject.apply(@cache_identity, @mock_context).key_hash).to eq(
         
     | 
| 
       27 
27 
     | 
    
         
             
                      x: :y,
         
     | 
| 
       28 
28 
     | 
    
         
             
                      request_params: { 'foo' => 'bar' }
         
     | 
| 
       29 
29 
     | 
    
         
             
                    )
         
     | 
| 
         @@ -6,7 +6,7 @@ describe Garner::Strategies::Context::Key::RequestPath do 
     | 
|
| 
       6 
6 
     | 
    
         
             
                @request = Rack::Request.new('PATH_INFO' => '/foo')
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                @mock_context = double('object')
         
     | 
| 
       9 
     | 
    
         
            -
                @mock_context. 
     | 
| 
      
 9 
     | 
    
         
            +
                allow(@mock_context).to receive(:request) { @request }
         
     | 
| 
       10 
10 
     | 
    
         
             
              end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
              subject { Garner::Strategies::Context::Key::RequestPath }
         
     | 
| 
         @@ -15,12 +15,12 @@ describe Garner::Strategies::Context::Key::RequestPath do 
     | 
|
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
              it 'adds :request_params to the key' do
         
     | 
| 
       17 
17 
     | 
    
         
             
                subject.apply(@cache_identity, @mock_context)
         
     | 
| 
       18 
     | 
    
         
            -
                @cache_identity.key_hash[:request_path]. 
     | 
| 
      
 18 
     | 
    
         
            +
                expect(@cache_identity.key_hash[:request_path]).to eq '/foo'
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
              it 'appends to an existing key hash' do
         
     | 
| 
       22 
22 
     | 
    
         
             
                @cache_identity.key(x: :y)
         
     | 
| 
       23 
     | 
    
         
            -
                subject.apply(@cache_identity, @mock_context).key_hash. 
     | 
| 
      
 23 
     | 
    
         
            +
                expect(subject.apply(@cache_identity, @mock_context).key_hash).to eq(
         
     | 
| 
       24 
24 
     | 
    
         
             
                  x: :y,
         
     | 
| 
       25 
25 
     | 
    
         
             
                  request_path: '/foo'
         
     | 
| 
       26 
26 
     | 
    
         
             
                )
         
     | 
| 
         @@ -12,7 +12,7 @@ describe Garner::Strategies::Context::Key::RequestPost do 
     | 
|
| 
       12 
12 
     | 
    
         
             
                )
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                @mock_context = double('object')
         
     | 
| 
       15 
     | 
    
         
            -
                @mock_context. 
     | 
| 
      
 15 
     | 
    
         
            +
                allow(@mock_context).to receive(:request) { @request }
         
     | 
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
              subject { Garner::Strategies::Context::Key::RequestPost }
         
     | 
| 
         @@ -21,12 +21,12 @@ describe Garner::Strategies::Context::Key::RequestPost do 
     | 
|
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
              it 'adds :request_params to the key' do
         
     | 
| 
       23 
23 
     | 
    
         
             
                subject.apply(@cache_identity, @mock_context)
         
     | 
| 
       24 
     | 
    
         
            -
                @cache_identity.key_hash[:request_params]. 
     | 
| 
      
 24 
     | 
    
         
            +
                expect(@cache_identity.key_hash[:request_params]).to eq('foo' => 'bar')
         
     | 
| 
       25 
25 
     | 
    
         
             
              end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
              it 'appends to an existing key hash' do
         
     | 
| 
       28 
28 
     | 
    
         
             
                @cache_identity.key(x: :y)
         
     | 
| 
       29 
     | 
    
         
            -
                subject.apply(@cache_identity, @mock_context).key_hash. 
     | 
| 
      
 29 
     | 
    
         
            +
                expect(subject.apply(@cache_identity, @mock_context).key_hash).to eq(
         
     | 
| 
       30 
30 
     | 
    
         
             
                  x: :y,
         
     | 
| 
       31 
31 
     | 
    
         
             
                  request_params: { 'foo' => 'bar' }
         
     | 
| 
       32 
32 
     | 
    
         
             
                )
         
     | 
    
        data/spec/garner/version_spec.rb
    CHANGED
    
    
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            describe 'ActiveRecord integration' do
         
     | 
| 
      
 3 
     | 
    
         
            +
            describe 'ActiveRecord integration', type: :request do
         
     | 
| 
       4 
4 
     | 
    
         
             
              context 'using the Garner::Strategies::Binding::Key::CacheKey strategy' do
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                describe 'cache key generation' do
         
     | 
| 
         @@ -13,12 +13,12 @@ describe 'ActiveRecord integration' do 
     | 
|
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                  it "returns the object's cache key, or nil" do
         
     | 
| 
       15 
15 
     | 
    
         
             
                    new_activist = Activist.new
         
     | 
| 
       16 
     | 
    
         
            -
                    subject.apply(new_activist). 
     | 
| 
      
 16 
     | 
    
         
            +
                    expect(subject.apply(new_activist)).to eq 'activists/new'
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                    persisted_activist = Activist.create
         
     | 
| 
       19 
19 
     | 
    
         
             
                    timestamp = persisted_activist.updated_at.utc.to_s(persisted_activist.cache_timestamp_format)
         
     | 
| 
       20 
20 
     | 
    
         
             
                    expected_key = "activists/#{persisted_activist.id}-#{timestamp}"
         
     | 
| 
       21 
     | 
    
         
            -
                    subject.apply(persisted_activist). 
     | 
| 
      
 21 
     | 
    
         
            +
                    expect(subject.apply(persisted_activist)).to eq expected_key
         
     | 
| 
       22 
22 
     | 
    
         
             
                  end
         
     | 
| 
       23 
23 
     | 
    
         
             
                end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
         @@ -27,7 +27,7 @@ describe 'ActiveRecord integration' do 
     | 
|
| 
       27 
27 
     | 
    
         
             
                    subject { Activist.create }
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                    it 'returns a non-nil cache_key' do
         
     | 
| 
       30 
     | 
    
         
            -
                      subject.garner_cache_key. 
     | 
| 
      
 30 
     | 
    
         
            +
                      expect(subject.garner_cache_key).not_to be_nil
         
     | 
| 
       31 
31 
     | 
    
         
             
                    end
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
         @@ -2,7 +2,7 @@ require 'spec_helper' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'garner/mixins/rack'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'grape'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            describe 'Grape integration' do
         
     | 
| 
      
 5 
     | 
    
         
            +
            describe 'Grape integration', type: :request do
         
     | 
| 
       6 
6 
     | 
    
         
             
              class TestCachebuster < Grape::Middleware::Base
         
     | 
| 
       7 
7 
     | 
    
         
             
                def after
         
     | 
| 
       8 
8 
     | 
    
         
             
                  @app_response[1]['Expires'] = Time.at(0).utc.to_s
         
     | 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'garner/mixins/mongoid'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            describe 'Mongoid integration' do
         
     | 
| 
      
 4 
     | 
    
         
            +
            describe 'Mongoid integration', type: :request do
         
     | 
| 
       5 
5 
     | 
    
         
             
              before(:each) do
         
     | 
| 
       6 
6 
     | 
    
         
             
                @app = Class.new.tap do |app|
         
     | 
| 
       7 
7 
     | 
    
         
             
                  app.send(:extend, Garner::Cache::Context)
         
     | 
| 
         @@ -34,42 +34,42 @@ describe 'Mongoid integration' do 
     | 
|
| 
       34 
34 
     | 
    
         
             
                        end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                        it 'caches one copy across all callers' do
         
     | 
| 
       37 
     | 
    
         
            -
                          Monger. 
     | 
| 
       38 
     | 
    
         
            -
                          Monger. 
     | 
| 
      
 37 
     | 
    
         
            +
                          allow(Monger).to receive(:find) { @object }
         
     | 
| 
      
 38 
     | 
    
         
            +
                          expect(Monger).to receive(:find).once
         
     | 
| 
       39 
39 
     | 
    
         
             
                          2.times { Monger.garnered_find('m1') }
         
     | 
| 
       40 
40 
     | 
    
         
             
                        end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                        it 'returns the instance requested' do
         
     | 
| 
       43 
     | 
    
         
            -
                          Monger.garnered_find('m1'). 
     | 
| 
      
 43 
     | 
    
         
            +
                          expect(Monger.garnered_find('m1')).to eq @object
         
     | 
| 
       44 
44 
     | 
    
         
             
                        end
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
46 
     | 
    
         
             
                        it 'can be called with an array of one object, and will return an array' do
         
     | 
| 
       47 
     | 
    
         
            -
                          Monger.garnered_find(['m1']). 
     | 
| 
      
 47 
     | 
    
         
            +
                          expect(Monger.garnered_find(['m1'])).to eq [@object]
         
     | 
| 
       48 
48 
     | 
    
         
             
                        end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                        it 'is invalidated on changing identity field' do
         
     | 
| 
       51 
     | 
    
         
            -
                          Monger.garnered_find('m1').name. 
     | 
| 
      
 51 
     | 
    
         
            +
                          expect(Monger.garnered_find('m1').name).to eq 'M1'
         
     | 
| 
       52 
52 
     | 
    
         
             
                          @object.update_attributes!(name: 'M2')
         
     | 
| 
       53 
     | 
    
         
            -
                          Monger.garnered_find('m1').name. 
     | 
| 
      
 53 
     | 
    
         
            +
                          expect(Monger.garnered_find('m1').name).to eq 'M2'
         
     | 
| 
       54 
54 
     | 
    
         
             
                        end
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
                        it 'is invalidated on destruction' do
         
     | 
| 
       57 
     | 
    
         
            -
                          Monger.garnered_find('m1').name. 
     | 
| 
      
 57 
     | 
    
         
            +
                          expect(Monger.garnered_find('m1').name).to eq 'M1'
         
     | 
| 
       58 
58 
     | 
    
         
             
                          @object.destroy
         
     | 
| 
       59 
     | 
    
         
            -
                          Monger.garnered_find('m1'). 
     | 
| 
      
 59 
     | 
    
         
            +
                          expect(Monger.garnered_find('m1')).to be_nil
         
     | 
| 
       60 
60 
     | 
    
         
             
                        end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
                        context 'with case-insensitive find' do
         
     | 
| 
       63 
63 
     | 
    
         
             
                          before(:each) do
         
     | 
| 
       64 
64 
     | 
    
         
             
                            find_method = Monger.method(:find)
         
     | 
| 
       65 
     | 
    
         
            -
                            Monger. 
     | 
| 
      
 65 
     | 
    
         
            +
                            allow(Monger).to receive(:find) do |param|
         
     | 
| 
       66 
66 
     | 
    
         
             
                              find_method.call(param.to_s.downcase)
         
     | 
| 
       67 
67 
     | 
    
         
             
                            end
         
     | 
| 
       68 
68 
     | 
    
         
             
                          end
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                          it 'does not cache a nil identity' do
         
     | 
| 
       71 
     | 
    
         
            -
                            Monger.garnered_find('M1'). 
     | 
| 
       72 
     | 
    
         
            -
                            Monger.garnered_find('foobar'). 
     | 
| 
      
 71 
     | 
    
         
            +
                            expect(Monger.garnered_find('M1')).to eq @object
         
     | 
| 
      
 72 
     | 
    
         
            +
                            expect(Monger.garnered_find('foobar')).to be_nil
         
     | 
| 
       73 
73 
     | 
    
         
             
                          end
         
     | 
| 
       74 
74 
     | 
    
         
             
                        end
         
     | 
| 
       75 
75 
     | 
    
         | 
| 
         @@ -79,50 +79,50 @@ describe 'Mongoid integration' do 
     | 
|
| 
       79 
79 
     | 
    
         
             
                          end
         
     | 
| 
       80 
80 
     | 
    
         | 
| 
       81 
81 
     | 
    
         
             
                          it 'returns the instances requested' do
         
     | 
| 
       82 
     | 
    
         
            -
                            Monger.garnered_find('m1', 'm2'). 
     | 
| 
      
 82 
     | 
    
         
            +
                            expect(Monger.garnered_find('m1', 'm2')).to eq [@object, @object2]
         
     | 
| 
       83 
83 
     | 
    
         
             
                          end
         
     | 
| 
       84 
84 
     | 
    
         | 
| 
       85 
85 
     | 
    
         
             
                          it 'can take an array' do
         
     | 
| 
       86 
     | 
    
         
            -
                            Monger.garnered_find(%w(m1 m2)). 
     | 
| 
      
 86 
     | 
    
         
            +
                            expect(Monger.garnered_find(%w(m1 m2))).to eq [@object, @object2]
         
     | 
| 
       87 
87 
     | 
    
         
             
                          end
         
     | 
| 
       88 
88 
     | 
    
         | 
| 
       89 
89 
     | 
    
         
             
                          it 'is invalidated when one of the objects is changed' do
         
     | 
| 
       90 
     | 
    
         
            -
                            Monger.garnered_find('m1', 'm2'). 
     | 
| 
      
 90 
     | 
    
         
            +
                            expect(Monger.garnered_find('m1', 'm2')).to eq [@object, @object2]
         
     | 
| 
       91 
91 
     | 
    
         
             
                            @object2.update_attributes!(name: 'M3')
         
     | 
| 
       92 
     | 
    
         
            -
                            Monger.garnered_find('m1', 'm2').last.name. 
     | 
| 
      
 92 
     | 
    
         
            +
                            expect(Monger.garnered_find('m1', 'm2').last.name).to eq 'M3'
         
     | 
| 
       93 
93 
     | 
    
         
             
                          end
         
     | 
| 
       94 
94 
     | 
    
         | 
| 
       95 
95 
     | 
    
         
             
                          it 'is invalidated when one of the objects is changed, passed as an array' do
         
     | 
| 
       96 
     | 
    
         
            -
                            Monger.garnered_find(%w(m1 m2)). 
     | 
| 
      
 96 
     | 
    
         
            +
                            expect(Monger.garnered_find(%w(m1 m2))).to eq [@object, @object2]
         
     | 
| 
       97 
97 
     | 
    
         
             
                            @object2.update_attributes!(name: 'M3')
         
     | 
| 
       98 
     | 
    
         
            -
                            Monger.garnered_find(%w(m1 m2)).last.name. 
     | 
| 
      
 98 
     | 
    
         
            +
                            expect(Monger.garnered_find(%w(m1 m2)).last.name).to eq 'M3'
         
     | 
| 
       99 
99 
     | 
    
         
             
                          end
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
       101 
101 
     | 
    
         
             
                          it 'does not return a match when the objects cannot be found' do
         
     | 
| 
       102 
     | 
    
         
            -
                            Monger.garnered_find('m3'). 
     | 
| 
       103 
     | 
    
         
            -
                            Monger.garnered_find('m3', 'm4'). 
     | 
| 
       104 
     | 
    
         
            -
                            Monger.garnered_find(%w(m3 m4)). 
     | 
| 
      
 102 
     | 
    
         
            +
                            expect(Monger.garnered_find('m3')).to be_nil
         
     | 
| 
      
 103 
     | 
    
         
            +
                            expect(Monger.garnered_find('m3', 'm4')).to eq []
         
     | 
| 
      
 104 
     | 
    
         
            +
                            expect(Monger.garnered_find(%w(m3 m4))).to eq []
         
     | 
| 
       105 
105 
     | 
    
         
             
                          end
         
     | 
| 
       106 
106 
     | 
    
         | 
| 
       107 
107 
     | 
    
         
             
                          it 'does not return a match when some of the objects cannot be found, and returns those that can' do
         
     | 
| 
       108 
     | 
    
         
            -
                            Monger.garnered_find('m1', 'm2'). 
     | 
| 
      
 108 
     | 
    
         
            +
                            expect(Monger.garnered_find('m1', 'm2')).to eq [@object, @object2]
         
     | 
| 
       109 
109 
     | 
    
         
             
                            @object2.destroy
         
     | 
| 
       110 
     | 
    
         
            -
                            Monger.garnered_find('m1', 'm2'). 
     | 
| 
      
 110 
     | 
    
         
            +
                            expect(Monger.garnered_find('m1', 'm2')).to eq [@object]
         
     | 
| 
       111 
111 
     | 
    
         
             
                          end
         
     | 
| 
       112 
112 
     | 
    
         | 
| 
       113 
113 
     | 
    
         
             
                          it 'correctly returns a single object when first asked for a single object as an array' do
         
     | 
| 
       114 
     | 
    
         
            -
                            Monger.garnered_find(['m1']). 
     | 
| 
       115 
     | 
    
         
            -
                            Monger.garnered_find('m1'). 
     | 
| 
      
 114 
     | 
    
         
            +
                            expect(Monger.garnered_find(['m1'])).to eq [@object]
         
     | 
| 
      
 115 
     | 
    
         
            +
                            expect(Monger.garnered_find('m1')).to eq @object
         
     | 
| 
       116 
116 
     | 
    
         
             
                          end
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                          it 'correctly returns an array of a single object, when first asked for a single object' do
         
     | 
| 
       119 
     | 
    
         
            -
                            Monger.garnered_find('m1'). 
     | 
| 
       120 
     | 
    
         
            -
                            Monger.garnered_find(['m1']). 
     | 
| 
      
 119 
     | 
    
         
            +
                            expect(Monger.garnered_find('m1')).to eq @object
         
     | 
| 
      
 120 
     | 
    
         
            +
                            expect(Monger.garnered_find(['m1'])).to eq [@object]
         
     | 
| 
       121 
121 
     | 
    
         
             
                          end
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
       123 
123 
     | 
    
         
             
                          it 'caches properly when called with an array' do
         
     | 
| 
       124 
     | 
    
         
            -
                            Monger. 
     | 
| 
       125 
     | 
    
         
            -
                            Monger. 
     | 
| 
      
 124 
     | 
    
         
            +
                            allow(Monger).to receive(:find) { @object }
         
     | 
| 
      
 125 
     | 
    
         
            +
                            expect(Monger).to receive(:find).once
         
     | 
| 
       126 
126 
     | 
    
         
             
                            2.times { Monger.garnered_find(%w(m1 m2)) }
         
     | 
| 
       127 
127 
     | 
    
         
             
                          end
         
     | 
| 
       128 
128 
     | 
    
         | 
| 
         @@ -140,30 +140,30 @@ describe 'Mongoid integration' do 
     | 
|
| 
       140 
140 
     | 
    
         
             
                          end
         
     | 
| 
       141 
141 
     | 
    
         | 
| 
       142 
142 
     | 
    
         
             
                          it 'invalidates on update' do
         
     | 
| 
       143 
     | 
    
         
            -
                            cached_object_namer.call. 
     | 
| 
      
 143 
     | 
    
         
            +
                            expect(cached_object_namer.call).to eq 'M1'
         
     | 
| 
       144 
144 
     | 
    
         
             
                            @object.update_attributes!(name: 'M2')
         
     | 
| 
       145 
     | 
    
         
            -
                            cached_object_namer.call. 
     | 
| 
      
 145 
     | 
    
         
            +
                            expect(cached_object_namer.call).to eq 'M2'
         
     | 
| 
       146 
146 
     | 
    
         
             
                          end
         
     | 
| 
       147 
147 
     | 
    
         | 
| 
       148 
148 
     | 
    
         
             
                          it 'invalidates on destroy' do
         
     | 
| 
       149 
     | 
    
         
            -
                            cached_object_namer.call. 
     | 
| 
      
 149 
     | 
    
         
            +
                            expect(cached_object_namer.call).to eq 'M1'
         
     | 
| 
       150 
150 
     | 
    
         
             
                            @object.destroy
         
     | 
| 
       151 
     | 
    
         
            -
                            cached_object_namer. 
     | 
| 
      
 151 
     | 
    
         
            +
                            expect(cached_object_namer).to raise_error
         
     | 
| 
       152 
152 
     | 
    
         
             
                          end
         
     | 
| 
       153 
153 
     | 
    
         | 
| 
       154 
154 
     | 
    
         
             
                          it 'invalidates by explicit call to invalidate_garner_caches' do
         
     | 
| 
       155 
     | 
    
         
            -
                            cached_object_namer.call. 
     | 
| 
      
 155 
     | 
    
         
            +
                            expect(cached_object_namer.call).to eq 'M1'
         
     | 
| 
       156 
156 
     | 
    
         
             
                            if Mongoid.mongoid3?
         
     | 
| 
       157 
157 
     | 
    
         
             
                              @object.set(:name, 'M2')
         
     | 
| 
       158 
158 
     | 
    
         
             
                            else
         
     | 
| 
       159 
159 
     | 
    
         
             
                              @object.set(name: 'M2')
         
     | 
| 
       160 
160 
     | 
    
         
             
                            end
         
     | 
| 
       161 
161 
     | 
    
         
             
                            @object.invalidate_garner_caches
         
     | 
| 
       162 
     | 
    
         
            -
                            cached_object_namer.call. 
     | 
| 
      
 162 
     | 
    
         
            +
                            expect(cached_object_namer.call).to eq 'M2'
         
     | 
| 
       163 
163 
     | 
    
         
             
                          end
         
     | 
| 
       164 
164 
     | 
    
         | 
| 
       165 
165 
     | 
    
         
             
                          it 'does not invalidate results for other like-classed objects' do
         
     | 
| 
       166 
     | 
    
         
            -
                            cached_object_namer.call. 
     | 
| 
      
 166 
     | 
    
         
            +
                            expect(cached_object_namer.call).to eq 'M1'
         
     | 
| 
       167 
167 
     | 
    
         
             
                            if Mongoid.mongoid3?
         
     | 
| 
       168 
168 
     | 
    
         
             
                              @object.set(:name, 'M2')
         
     | 
| 
       169 
169 
     | 
    
         
             
                            else
         
     | 
| 
         @@ -173,7 +173,7 @@ describe 'Mongoid integration' do 
     | 
|
| 
       173 
173 
     | 
    
         
             
                            new_monger.update_attributes!(name: 'M4')
         
     | 
| 
       174 
174 
     | 
    
         
             
                            new_monger.destroy
         
     | 
| 
       175 
175 
     | 
    
         | 
| 
       176 
     | 
    
         
            -
                            cached_object_namer.call. 
     | 
| 
      
 176 
     | 
    
         
            +
                            expect(cached_object_namer.call).to eq 'M1'
         
     | 
| 
       177 
177 
     | 
    
         
             
                          end
         
     | 
| 
       178 
178 
     | 
    
         | 
| 
       179 
179 
     | 
    
         
             
                          context 'with racing destruction' do
         
     | 
| 
         @@ -192,7 +192,7 @@ describe 'Mongoid integration' do 
     | 
|
| 
       192 
192 
     | 
    
         
             
                              end
         
     | 
| 
       193 
193 
     | 
    
         
             
                              @monger1.destroy
         
     | 
| 
       194 
194 
     | 
    
         
             
                              @monger2.save
         
     | 
| 
       195 
     | 
    
         
            -
                              cached_object_namer. 
     | 
| 
      
 195 
     | 
    
         
            +
                              expect(cached_object_namer).to raise_error
         
     | 
| 
       196 
196 
     | 
    
         
             
                            end
         
     | 
| 
       197 
197 
     | 
    
         | 
| 
       198 
198 
     | 
    
         
             
                            it 'invalidates caches properly (Type II)' do
         
     | 
| 
         @@ -205,7 +205,7 @@ describe 'Mongoid integration' do 
     | 
|
| 
       205 
205 
     | 
    
         
             
                              @monger1.remove
         
     | 
| 
       206 
206 
     | 
    
         
             
                              @monger2.save
         
     | 
| 
       207 
207 
     | 
    
         
             
                              @monger1.destroy
         
     | 
| 
       208 
     | 
    
         
            -
                              cached_object_namer. 
     | 
| 
      
 208 
     | 
    
         
            +
                              expect(cached_object_namer).to raise_error
         
     | 
| 
       209 
209 
     | 
    
         
             
                            end
         
     | 
| 
       210 
210 
     | 
    
         
             
                          end
         
     | 
| 
       211 
211 
     | 
    
         | 
| 
         @@ -224,9 +224,9 @@ describe 'Mongoid integration' do 
     | 
|
| 
       224 
224 
     | 
    
         
             
                            end
         
     | 
| 
       225 
225 
     | 
    
         | 
| 
       226 
226 
     | 
    
         
             
                            it 'binds to the correct object' do
         
     | 
| 
       227 
     | 
    
         
            -
                              cached_object_namer.call. 
     | 
| 
      
 227 
     | 
    
         
            +
                              expect(cached_object_namer.call).to eq 'Swiss'
         
     | 
| 
       228 
228 
     | 
    
         
             
                              @object.update_attributes!(name: 'Havarti')
         
     | 
| 
       229 
     | 
    
         
            -
                              cached_object_namer.call. 
     | 
| 
      
 229 
     | 
    
         
            +
                              expect(cached_object_namer.call).to eq 'Havarti'
         
     | 
| 
       230 
230 
     | 
    
         
             
                            end
         
     | 
| 
       231 
231 
     | 
    
         
             
                          end
         
     | 
| 
       232 
232 
     | 
    
         | 
| 
         @@ -244,9 +244,9 @@ describe 'Mongoid integration' do 
     | 
|
| 
       244 
244 
     | 
    
         
             
                            end
         
     | 
| 
       245 
245 
     | 
    
         | 
| 
       246 
246 
     | 
    
         
             
                            it 'binds to the correct object' do
         
     | 
| 
       247 
     | 
    
         
            -
                              cached_object_namer.call. 
     | 
| 
      
 247 
     | 
    
         
            +
                              expect(cached_object_namer.call).to eq 'Trout'
         
     | 
| 
       248 
248 
     | 
    
         
             
                              @fish.update_attributes!(name: 'Sockeye')
         
     | 
| 
       249 
     | 
    
         
            -
                              cached_object_namer.call. 
     | 
| 
      
 249 
     | 
    
         
            +
                              expect(cached_object_namer.call).to eq 'Sockeye'
         
     | 
| 
       250 
250 
     | 
    
         
             
                            end
         
     | 
| 
       251 
251 
     | 
    
         | 
| 
       252 
252 
     | 
    
         
             
                            context 'with :invalidate_mongoid_root = true' do
         
     | 
| 
         @@ -264,9 +264,9 @@ describe 'Mongoid integration' do 
     | 
|
| 
       264 
264 
     | 
    
         
             
                              end
         
     | 
| 
       265 
265 
     | 
    
         | 
| 
       266 
266 
     | 
    
         
             
                              it 'invalidates the root document' do
         
     | 
| 
       267 
     | 
    
         
            -
                                root_cached_object_namer.call. 
     | 
| 
      
 267 
     | 
    
         
            +
                                expect(root_cached_object_namer.call).to eq 'Trout'
         
     | 
| 
       268 
268 
     | 
    
         
             
                                @fish.update_attributes!(name: 'Sockeye')
         
     | 
| 
       269 
     | 
    
         
            -
                                root_cached_object_namer.call. 
     | 
| 
      
 269 
     | 
    
         
            +
                                expect(root_cached_object_namer.call).to eq 'Sockeye'
         
     | 
| 
       270 
270 
     | 
    
         
             
                              end
         
     | 
| 
       271 
271 
     | 
    
         
             
                            end
         
     | 
| 
       272 
272 
     | 
    
         
             
                          end
         
     | 
| 
         @@ -287,11 +287,11 @@ describe 'Mongoid integration' do 
     | 
|
| 
       287 
287 
     | 
    
         
             
                            end
         
     | 
| 
       288 
288 
     | 
    
         | 
| 
       289 
289 
     | 
    
         
             
                            it 'invalidates all identities' do
         
     | 
| 
       290 
     | 
    
         
            -
                              cached_object_namer.call. 
     | 
| 
       291 
     | 
    
         
            -
                              cached_object_namer_by_slug.call('m1'). 
     | 
| 
      
 290 
     | 
    
         
            +
                              expect(cached_object_namer.call).to eq 'M1'
         
     | 
| 
      
 291 
     | 
    
         
            +
                              expect(cached_object_namer_by_slug.call('m1')).to eq 'M1'
         
     | 
| 
       292 
292 
     | 
    
         
             
                              @object.update_attributes!(name: 'M2')
         
     | 
| 
       293 
     | 
    
         
            -
                              cached_object_namer.call. 
     | 
| 
       294 
     | 
    
         
            -
                              cached_object_namer_by_slug.call('m1'). 
     | 
| 
      
 293 
     | 
    
         
            +
                              expect(cached_object_namer.call).to eq 'M2'
         
     | 
| 
      
 294 
     | 
    
         
            +
                              expect(cached_object_namer_by_slug.call('m1')).to eq 'M2'
         
     | 
| 
       295 
295 
     | 
    
         
             
                            end
         
     | 
| 
       296 
296 
     | 
    
         
             
                          end
         
     | 
| 
       297 
297 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -313,38 +313,38 @@ describe 'Mongoid integration' do 
     | 
|
| 
       313 
313 
     | 
    
         | 
| 
       314 
314 
     | 
    
         
             
                          it 'invalidates on create' do
         
     | 
| 
       315 
315 
     | 
    
         
             
                            Cheese.create(name: 'M1')
         
     | 
| 
       316 
     | 
    
         
            -
                            cached_object_name_concatenator.call. 
     | 
| 
      
 316 
     | 
    
         
            +
                            expect(cached_object_name_concatenator.call).to eq 'M1'
         
     | 
| 
       317 
317 
     | 
    
         
             
                            Cheese.create(name: 'M3')
         
     | 
| 
       318 
     | 
    
         
            -
                            cached_object_name_concatenator.call. 
     | 
| 
      
 318 
     | 
    
         
            +
                            expect(cached_object_name_concatenator.call).to eq 'M1, M3'
         
     | 
| 
       319 
319 
     | 
    
         
             
                          end
         
     | 
| 
       320 
320 
     | 
    
         | 
| 
       321 
321 
     | 
    
         
             
                          it 'invalidates on update' do
         
     | 
| 
       322 
322 
     | 
    
         
             
                            m1 = Cheese.create(name: 'M1')
         
     | 
| 
       323 
323 
     | 
    
         
             
                            Cheese.create(name: 'M3')
         
     | 
| 
       324 
     | 
    
         
            -
                            cached_object_name_concatenator.call. 
     | 
| 
      
 324 
     | 
    
         
            +
                            expect(cached_object_name_concatenator.call).to eq 'M1, M3'
         
     | 
| 
       325 
325 
     | 
    
         
             
                            m1.update_attributes(name: 'M2')
         
     | 
| 
       326 
     | 
    
         
            -
                            cached_object_name_concatenator.call. 
     | 
| 
      
 326 
     | 
    
         
            +
                            expect(cached_object_name_concatenator.call).to eq 'M2, M3'
         
     | 
| 
       327 
327 
     | 
    
         
             
                          end
         
     | 
| 
       328 
328 
     | 
    
         | 
| 
       329 
329 
     | 
    
         
             
                          it 'invalidates on destroy' do
         
     | 
| 
       330 
330 
     | 
    
         
             
                            m1 = Cheese.create(name: 'M1')
         
     | 
| 
       331 
331 
     | 
    
         
             
                            Cheese.create(name: 'M3')
         
     | 
| 
       332 
     | 
    
         
            -
                            cached_object_name_concatenator.call. 
     | 
| 
      
 332 
     | 
    
         
            +
                            expect(cached_object_name_concatenator.call).to eq 'M1, M3'
         
     | 
| 
       333 
333 
     | 
    
         
             
                            m1.destroy
         
     | 
| 
       334 
     | 
    
         
            -
                            cached_object_name_concatenator.call. 
     | 
| 
      
 334 
     | 
    
         
            +
                            expect(cached_object_name_concatenator.call).to eq 'M3'
         
     | 
| 
       335 
335 
     | 
    
         
             
                          end
         
     | 
| 
       336 
336 
     | 
    
         | 
| 
       337 
337 
     | 
    
         
             
                          it 'invalidates by explicit call to invalidate_garner_caches' do
         
     | 
| 
       338 
338 
     | 
    
         
             
                            m1 = Cheese.create(name: 'M1')
         
     | 
| 
       339 
339 
     | 
    
         
             
                            Cheese.create(name: 'M3')
         
     | 
| 
       340 
     | 
    
         
            -
                            cached_object_name_concatenator.call. 
     | 
| 
      
 340 
     | 
    
         
            +
                            expect(cached_object_name_concatenator.call).to eq 'M1, M3'
         
     | 
| 
       341 
341 
     | 
    
         
             
                            if Mongoid.mongoid3?
         
     | 
| 
       342 
342 
     | 
    
         
             
                              m1.set(:name, 'M2')
         
     | 
| 
       343 
343 
     | 
    
         
             
                            else
         
     | 
| 
       344 
344 
     | 
    
         
             
                              m1.set(name: 'M2')
         
     | 
| 
       345 
345 
     | 
    
         
             
                            end
         
     | 
| 
       346 
346 
     | 
    
         
             
                            klass.invalidate_garner_caches
         
     | 
| 
       347 
     | 
    
         
            -
                            cached_object_name_concatenator.call. 
     | 
| 
      
 347 
     | 
    
         
            +
                            expect(cached_object_name_concatenator.call).to eq 'M2, M3'
         
     | 
| 
       348 
348 
     | 
    
         
             
                          end
         
     | 
| 
       349 
349 
     | 
    
         
             
                        end
         
     | 
| 
       350 
350 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -2,7 +2,7 @@ require 'spec_helper' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'garner/mixins/rack'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'securerandom'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            describe 'Rack integration' do
         
     | 
| 
      
 5 
     | 
    
         
            +
            describe 'Rack integration', type: :request do
         
     | 
| 
       6 
6 
     | 
    
         
             
              include Rack::Test::Methods
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              let(:app) do
         
     | 
| 
         @@ -37,18 +37,18 @@ describe 'Rack integration' do 
     | 
|
| 
       37 
37 
     | 
    
         
             
                  response1 = JSON.parse(last_response.body)[0]
         
     | 
| 
       38 
38 
     | 
    
         
             
                  get '/foo?q=2'
         
     | 
| 
       39 
39 
     | 
    
         
             
                  response2 = JSON.parse(last_response.body)[0]
         
     | 
| 
       40 
     | 
    
         
            -
                  response1. 
     | 
| 
      
 40 
     | 
    
         
            +
                  expect(response1).to eq response2
         
     | 
| 
       41 
41 
     | 
    
         
             
                end
         
     | 
| 
       42 
42 
     | 
    
         
             
              end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
              context 'with default configuration' do
         
     | 
| 
       45 
45 
     | 
    
         
             
                it 'bypasses cache if cache_enabled? returns false' do
         
     | 
| 
       46 
     | 
    
         
            -
                  TestRackApp. 
     | 
| 
      
 46 
     | 
    
         
            +
                  allow_any_instance_of(TestRackApp).to receive(:cache_enabled?) { false }
         
     | 
| 
       47 
47 
     | 
    
         
             
                  get '/'
         
     | 
| 
       48 
48 
     | 
    
         
             
                  response1 = JSON.parse(last_response.body)[0]
         
     | 
| 
       49 
49 
     | 
    
         
             
                  get '/'
         
     | 
| 
       50 
50 
     | 
    
         
             
                  response2 = JSON.parse(last_response.body)[0]
         
     | 
| 
       51 
     | 
    
         
            -
                  response1. 
     | 
| 
      
 51 
     | 
    
         
            +
                  expect(response1).not_to eq(response2)
         
     | 
| 
       52 
52 
     | 
    
         
             
                end
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
54 
     | 
    
         
             
                it 'caches different results for different paths' do
         
     | 
| 
         @@ -56,7 +56,7 @@ describe 'Rack integration' do 
     | 
|
| 
       56 
56 
     | 
    
         
             
                  response1 = JSON.parse(last_response.body)[0]
         
     | 
| 
       57 
57 
     | 
    
         
             
                  get '/bar'
         
     | 
| 
       58 
58 
     | 
    
         
             
                  response2 = JSON.parse(last_response.body)[0]
         
     | 
| 
       59 
     | 
    
         
            -
                  response1. 
     | 
| 
      
 59 
     | 
    
         
            +
                  expect(response1).not_to eq(response2)
         
     | 
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
                it 'caches different results for different query strings' do
         
     | 
| 
         @@ -64,14 +64,14 @@ describe 'Rack integration' do 
     | 
|
| 
       64 
64 
     | 
    
         
             
                  response1 = JSON.parse(last_response.body)[0]
         
     | 
| 
       65 
65 
     | 
    
         
             
                  get '/foo?q=2'
         
     | 
| 
       66 
66 
     | 
    
         
             
                  response2 = JSON.parse(last_response.body)[0]
         
     | 
| 
       67 
     | 
    
         
            -
                  response1. 
     | 
| 
      
 67 
     | 
    
         
            +
                  expect(response1).not_to eq(response2)
         
     | 
| 
       68 
68 
     | 
    
         
             
                end
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                it 'caches multiple blocks separately within an endpoint' do
         
     | 
| 
       71 
71 
     | 
    
         
             
                  get '/'
         
     | 
| 
       72 
72 
     | 
    
         
             
                  random1 = JSON.parse(last_response.body)[0]
         
     | 
| 
       73 
73 
     | 
    
         
             
                  random2 = JSON.parse(last_response.body)[1]
         
     | 
| 
       74 
     | 
    
         
            -
                  random1. 
     | 
| 
      
 74 
     | 
    
         
            +
                  expect(random1).not_to eq(random2)
         
     | 
| 
       75 
75 
     | 
    
         
             
                end
         
     | 
| 
       76 
76 
     | 
    
         
             
              end
         
     | 
| 
       77 
77 
     | 
    
         
             
            end
         
     |