cassette 1.2.5 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9ed73a897ba8ecc5a7f0133132d28388b9f4a90bc2d0e8a1fe3d1ec21f9b4b3
4
- data.tar.gz: bdbe2968131cbddb9527ba973d68aaff7f5008be1b4fe6f662a26c7f5468edd1
3
+ metadata.gz: 537dfe98da3fa2ff458b4dcd7c8a4288711e8c44bc7093dd3271a2b10b2c7ceb
4
+ data.tar.gz: 0e61274545f74bcc569503231f9f856e2121af0e20b1843f10ac2f60fc6dc708
5
5
  SHA512:
6
- metadata.gz: 259b435580d9ebe186553374624dcab25e84d33b392ea00997dbc1729b0fd1fada1b1e5de3bf129aca440146c9bf5b94544525d7868c54b11509cbfc54b0e9b5
7
- data.tar.gz: 02fc9b53c0a2e873b0dde28d2757e1d23f59b62d949ace7f789466c1e37f874477d9d4489d03c2e48536bf25016eef2da358e9dbe4dcb5e99943f7dd56ac94be
6
+ metadata.gz: f6befb3beb94dcfdfb5c021dd144e349a3d06fbe18a6013fb90049fecd5aa9c2996c512253dbc2d5f7c08594725ba22cfad296df3491857037f13a94d4f68dc1
7
+ data.tar.gz: 461d20aa06ad57a0efad132883cbc005ab68160aa9bda58ec335e274d026abe298b829e179602020b375b03c222e3a743318be69af9ec500a92f32c39d489c85
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cassette::Client
2
2
 
3
- [![Build Status](https://travis-ci.org/locaweb/cassette.svg)](https://travis-ci.org/locaweb/cassette)
3
+ [![Build Status](https://travis-ci.org/locaweb/cassette.svg)](https://travis-ci.org/locaweb/cassette)
4
4
 
5
5
  [![Test Coverage](https://codeclimate.com/github/locaweb/cassette/badges/coverage.svg)](https://codeclimate.com/github/locaweb/cassette/coverage)
6
6
 
@@ -37,5 +37,21 @@ module Cassette
37
37
  @config if defined?(@config)
38
38
  end
39
39
 
40
+ def cache_backend
41
+ @cache_backend ||= begin
42
+ if defined?(::Rails) && ::Rails.cache
43
+ ::Rails.cache
44
+ elsif defined?(::ActiveSupport::Cache::MemoryStore)
45
+ ActiveSupport::Cache::MemoryStore.new
46
+ else
47
+ Cache::NullStore.new
48
+ end
49
+ end
50
+ end
51
+
52
+ def self.cache_backend=(cache_backend)
53
+ @cache_backend = cache_backend
54
+ end
55
+
40
56
  def_delegators Http::Request, :post
41
57
  end
@@ -8,28 +8,6 @@ end
8
8
 
9
9
  module Cassette
10
10
  module Cache
11
- def self.backend
12
- @backend ||= begin
13
- if defined?(::Rails) && ::Rails.cache
14
- ::Rails.cache
15
- elsif defined?(::ActiveSupport::Cache::MemoryStore)
16
- ActiveSupport::Cache::MemoryStore.new
17
- else
18
- NullStore.new
19
- end
20
- end
21
- end
22
-
23
- def self.backend=(backend)
24
- @backend = backend
25
- end
26
-
27
- def backend
28
- @backend ||= Cassette::Cache.backend
29
- end
30
-
31
- attr_writer :backend
32
-
33
11
  def uses_key(key)
34
12
  "uses:#{key}"
35
13
  end
@@ -50,5 +28,13 @@ module Cassette
50
28
 
51
29
  backend.fetch(key, options, &block)
52
30
  end
31
+
32
+ def backend
33
+ Cassette.cache_backend
34
+ end
35
+
36
+ def self.backend=(backend)
37
+ ::Cassette.cache_backend = backend
38
+ end
53
39
  end
54
40
  end
@@ -2,7 +2,7 @@ module Cassette
2
2
  class Version
3
3
  MAJOR = '1'
4
4
  MINOR = '2'
5
- PATCH = '5'
5
+ PATCH = '6'
6
6
 
7
7
  def self.version
8
8
  [MAJOR, MINOR, PATCH].join('.')
@@ -40,5 +40,21 @@ describe Cassette::Authentication::Cache do
40
40
  it { expect(call_with_other_service).to eq(2) }
41
41
  end
42
42
  end
43
+
44
+ it 'uses the cache store set in configuration' do
45
+ # setup
46
+ global_cache = double('cache_store')
47
+ Cassette.cache_backend = global_cache
48
+
49
+ logger = Logger.new('/dev/null')
50
+
51
+ # exercise
52
+ auth_cache = described_class.new(logger)
53
+
54
+ expect(auth_cache.backend).to eq(global_cache)
55
+
56
+ # tear down
57
+ Cassette.cache_backend = nil
58
+ end
43
59
  end
44
60
  end
@@ -5,62 +5,31 @@ describe Cassette::Cache do
5
5
  cached()
6
6
  end
7
7
 
8
- after do
9
- described_class.instance_variable_set(:@backend, nil)
10
- end
8
+ describe '#backend' do
9
+ it 'returns the global cache' do
10
+ # setup
11
+ global_cache = double('cache_store')
12
+ Cassette.cache_backend = global_cache
11
13
 
12
- describe '.backend' do
13
- it 'defaults to rails backend' do
14
- rails = double('Rails')
15
- cache = double('cache_backend')
16
- allow(rails).to receive(:cache).and_return(cache)
17
- stub_const('Rails', rails)
14
+ # exercise and verify
15
+ expect(subject.backend).to eql(global_cache)
18
16
 
19
- expect(described_class.backend).to eql(cache)
17
+ # tear down
18
+ Cassette.cache_backend = nil
20
19
  end
21
20
  end
22
21
 
23
22
  describe '.backend=' do
24
- it 'provides a default backend for new instances' do
25
- backend = double('backend')
26
- expect(subject.backend).not_to eq(backend)
27
-
28
- described_class.backend = backend
29
-
30
- new_instance = cached()
31
- expect(new_instance.backend).to eq(backend)
32
- expect(new_instance.backend).not_to eq(subject.backend)
33
- end
34
-
35
- it 'sets the default backend' do
36
- backend = double('backend')
37
- expect(described_class.backend).not_to eq(backend)
38
-
39
- described_class.backend = backend
40
-
41
- expect(described_class.backend).to eq(backend)
42
- end
43
- end
44
-
45
- describe '#backend' do
46
- before { subject.backend = nil }
47
- after { subject.backend = nil }
48
-
49
- it 'sets the backend' do
50
- backend = double('Backend')
51
-
52
- subject.backend = backend
53
-
54
- expect(subject.backend).to eql(backend)
55
- end
23
+ it 'sets the cache' do
24
+ # setup
25
+ global_cache = double('cache_store')
26
+ described_class.backend = global_cache
56
27
 
57
- it 'defaults to rails backend' do
58
- rails = double('Rails')
59
- cache = double('cache_backend')
60
- allow(rails).to receive(:cache).and_return(cache)
61
- stub_const('Rails', rails)
28
+ # exercise and verify
29
+ expect(subject.backend).to eql(global_cache)
62
30
 
63
- expect(subject.backend).to eql(cache)
31
+ # tear down
32
+ Cassette.cache_backend = nil
64
33
  end
65
34
  end
66
35
 
@@ -3,5 +3,19 @@
3
3
 
4
4
 
5
5
  describe Cassette::Client::Cache do
6
- pending
6
+ it 'uses the cache store set in configuration' do
7
+ # setup
8
+ global_cache = double('cache_store')
9
+ Cassette.cache_backend = global_cache
10
+
11
+ logger = Logger.new('/dev/null')
12
+
13
+ # exercise
14
+ client_cache = described_class.new(logger)
15
+
16
+ expect(client_cache.backend).to eq(global_cache)
17
+
18
+ # tear down
19
+ Cassette.cache_backend = nil
20
+ end
7
21
  end
@@ -33,4 +33,53 @@ describe Cassette do
33
33
  end
34
34
  end
35
35
  end
36
+
37
+ describe '.cache_backend' do
38
+ context 'when the cache_backend is already set' do
39
+ it 'returns the cache_backend set' do
40
+ new_cache = double('cache_backend')
41
+ described_class.cache_backend = new_cache
42
+
43
+ # exercise and verify
44
+ expect(described_class.cache_backend).to eq(new_cache)
45
+
46
+ # tear down
47
+ described_class.cache_backend = nil
48
+ end
49
+ end
50
+
51
+ context 'when the cache_backend is not set' do
52
+ it 'returns Rails.cache if set' do
53
+ rails_cache = double('cache')
54
+ rails = double('Rails')
55
+ allow(rails).to receive(:cache).and_return(rails_cache)
56
+ stub_const('Rails', rails)
57
+
58
+ # exercise and verify
59
+ expect(described_class.cache_backend).to eq(rails_cache)
60
+
61
+ # tear down
62
+ described_class.cache_backend = nil
63
+ end
64
+
65
+ it 'returns MemoryStore if Rails.cache not set' do
66
+ # exercise and verify
67
+ expect(described_class.cache_backend).to be_a(ActiveSupport::Cache::MemoryStore)
68
+
69
+ # tear down
70
+ described_class.cache_backend = nil
71
+ end
72
+
73
+ it 'returns NullStore if Rails.cache and MemoryStore are not set' do
74
+ hide_const('ActiveSupport::Cache::MemoryStore')
75
+ require 'cassette/cache/null_store'
76
+
77
+ # exercise and verify
78
+ expect(described_class.cache_backend).to be_a(Cassette::Cache::NullStore)
79
+
80
+ # tear down
81
+ described_class.cache_backend = nil
82
+ end
83
+ end
84
+ end
36
85
  end
@@ -5,6 +5,9 @@ require 'yaml'
5
5
  require 'webmock/rspec'
6
6
  require 'rspec/its'
7
7
  require 'faker'
8
+ if RUBY_VERSION >= '2.3.0'
9
+ require 'pry-byebug'
10
+ end
8
11
 
9
12
  Dir['spec/support/**/*.rb'].each { |f| load f }
10
13
 
@@ -17,6 +20,9 @@ end
17
20
  RSpec.configure do |config|
18
21
  config.mock_framework = :rspec
19
22
  config.include Fixtures
23
+ last_execution_result_file = 'spec/support/last_execution_examples_result.txt'
24
+ config.example_status_persistence_file_path = last_execution_result_file
25
+ config.order = 'random'
20
26
  end
21
27
 
22
28
  SimpleCov.start 'gem' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassette
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Hermida Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: pry-byebug
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="