lhc-core-interceptors 1.0.0 → 2.0.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: b3d8f1d606680b4dc30c467b4b7dd83cabb19423
4
- data.tar.gz: 77ec5ff865484eb71beea6c04dc648d4f8ff4f16
3
+ metadata.gz: a1bcc91b0161bd232e2487449b928a351fcb92e7
4
+ data.tar.gz: d1a91579f20175af675aa6455bbf2412c68eeee4
5
5
  SHA512:
6
- metadata.gz: c9a8c8e363242f90b9ffb3cfb39c5ef95e93a2a9687d7c2accb19deadc6311cc1a65fa8db48d1ed101a5ec46ff3c38d2ca97b8bee643b823ca0bb1ea887ea02d
7
- data.tar.gz: 3e419cec01d175b226a222c165170b1f5612fb77f2d155a3a368acbdba32419f722ab751886c88855a80476aa1192436a8621e08d05583c5436ead05e15153d2
6
+ metadata.gz: 25ed9660ad091992ec955b65744ad9adde2b99cd18ca77f9d4e04e8c5c2923cd53e0aa869fc78bf83000f5fb75adbc14035e7f3c4c3d82013ea479a066307dfb
7
+ data.tar.gz: 86d7df8895e1f7ce2c37a3d6859a2214580a3c96778c725f1b9d4e310be5237b36578da5e05d46e041af676353efd308b3e8777edeb6923c0b2f3177c1d928d9
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.intra.local.ch/'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Declare your gem's dependencies in lhc.gemspec.
4
4
  # Bundler will treat runtime dependencies like base dependencies, and
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.requirements << 'Ruby >= 1.9.2'
21
21
  s.required_ruby_version = '>= 1.9.2'
22
22
 
23
- s.add_dependency 'lhc'
23
+ s.add_dependency 'lhc', '~> 3.1'
24
24
 
25
25
  s.add_development_dependency 'rspec-rails', '>= 3.0.0'
26
26
  s.add_development_dependency 'rails', '>= 4.0.0'
@@ -1,5 +1,7 @@
1
1
  class LHC::Caching < LHC::Interceptor
2
2
 
3
+ CACHE_VERSION = '1'
4
+
3
5
  # Options forwarded to the cache
4
6
  FORWARDED_OPTIONS = {
5
7
  cache_expires_in: :expires_in,
@@ -35,6 +37,8 @@ class LHC::Caching < LHC::Interceptor
35
37
  data[:code] = response.code
36
38
  # convert into a actual hash because the typhoeus headers object breaks marshaling
37
39
  data[:headers] = response.headers ? Hash[response.headers] : response.headers
40
+ # return_code is quite important as Typhoeus relies on it in order to determin 'success?'
41
+ data[:return_code] = response.options[:return_code]
38
42
  data
39
43
  end
40
44
 
@@ -44,7 +48,7 @@ class LHC::Caching < LHC::Interceptor
44
48
  key = "#{request.method.upcase} #{request.url}"
45
49
  key += "?#{request.params.to_query}" unless request.params.blank?
46
50
  end
47
- "LHC_CACHE: #{key}"
51
+ "LHC_CACHE(v#{CACHE_VERSION}): #{key}"
48
52
  end
49
53
 
50
54
  def options(input = {})
@@ -1,3 +1,3 @@
1
1
  module LHCCoreInterceptors
2
- VERSION = '1.0.0'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -13,7 +13,15 @@ describe LHC::Caching do
13
13
  stub
14
14
  LHC.config.endpoint(:local, 'http://local.ch', cache: true, cache_expires_in: 5.minutes)
15
15
  expect(Rails.cache).to receive(:write)
16
- .with('LHC_CACHE: GET http://local.ch', {body: "The Website", code: 200, headers: nil}, {expires_in: 5.minutes})
16
+ .with(
17
+ "LHC_CACHE(v#{LHC::Caching::CACHE_VERSION}): GET http://local.ch",
18
+ {
19
+ body: 'The Website',
20
+ code: 200,
21
+ headers: nil,
22
+ return_code: nil
23
+ }, expires_in: 5.minutes
24
+ )
17
25
  .and_call_original
18
26
  original_response = LHC.get(:local)
19
27
  cached_response = LHC.get(:local)
@@ -35,8 +43,8 @@ describe LHC::Caching do
35
43
 
36
44
  it 'lets you configure the cache key that will be used' do
37
45
  LHC.config.endpoint(:local, 'http://local.ch', cache: true, cache_key: 'STATICKEY')
38
- expect(Rails.cache).to receive(:fetch).with('LHC_CACHE: STATICKEY').and_call_original
39
- expect(Rails.cache).to receive(:write).with('LHC_CACHE: STATICKEY', anything, anything).and_call_original
46
+ expect(Rails.cache).to receive(:fetch).with("LHC_CACHE(v#{LHC::Caching::CACHE_VERSION}): STATICKEY").and_call_original
47
+ expect(Rails.cache).to receive(:write).with("LHC_CACHE(v#{LHC::Caching::CACHE_VERSION}): STATICKEY", anything, anything).and_call_original
40
48
  stub
41
49
  LHC.get(:local)
42
50
  end
@@ -0,0 +1,28 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHC::Caching do
4
+
5
+ before(:each) do
6
+ LHC.config.interceptors = [LHC::Caching]
7
+ LHC.config.endpoint(:local, 'http://local.ch', cache: true, cache_expires_in: 5.minutes)
8
+ Rails.cache.clear
9
+ # leverage the Typhoeus internal mock attribute in order to get Typhoeus evaluate the return_code
10
+ # lib/typhoeus/response/status.rb:48
11
+ allow_any_instance_of(Typhoeus::Response).to receive(:mock).and_return(false)
12
+ end
13
+
14
+ let!(:stub) { stub_request(:get, 'http://local.ch').to_return(status: 200, body: 'The Website') }
15
+
16
+ it 'provides the correct response status for responses from cache' do
17
+ stub
18
+ # the real request provides the return_code
19
+ allow_any_instance_of(Typhoeus::Response).to receive(:options)
20
+ .and_return(code: 200, status_message: '', body: 'The Website', headers: nil, return_code: :ok)
21
+ response = LHC.get(:local)
22
+ expect(response.success?).to eq true
23
+ # the cached response should get it from the cache
24
+ allow_any_instance_of(Typhoeus::Response).to receive(:options).and_call_original
25
+ cached_response = LHC.get(:local)
26
+ expect(cached_response.success?).to eq true
27
+ end
28
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhc-core-interceptors
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - local.ch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +129,7 @@ files:
129
129
  - spec/auth/bearer_spec.rb
130
130
  - spec/caching/main_spec.rb
131
131
  - spec/caching/parameters_spec.rb
132
+ - spec/caching/response_status_spec.rb
132
133
  - spec/caching/to_cache_spec.rb
133
134
  - spec/dummy/README.rdoc
134
135
  - spec/dummy/Rakefile
@@ -202,6 +203,7 @@ test_files:
202
203
  - spec/auth/bearer_spec.rb
203
204
  - spec/caching/main_spec.rb
204
205
  - spec/caching/parameters_spec.rb
206
+ - spec/caching/response_status_spec.rb
205
207
  - spec/caching/to_cache_spec.rb
206
208
  - spec/dummy/README.rdoc
207
209
  - spec/dummy/Rakefile