lhc 10.4.3 → 10.5.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
  SHA256:
3
- metadata.gz: a016cff9475c03c337aa44f8688b1499e6ea983a63f3d23d65bf638668ad54d8
4
- data.tar.gz: 061122763aef50722147734b3fe1985427a657b761da635dd3a3e91f82acff52
3
+ metadata.gz: 3cf5537cde6885a7e37d2bb70d7b222e761804018d0aab94bd9249c68a40d3f7
4
+ data.tar.gz: 1d501413fd820cffc020cc39eec04b4e775440abebdf61e030f8d6114b660922
5
5
  SHA512:
6
- metadata.gz: 27230061ee806b82ae5f566156460ff179d8b79089dd44fbe5ab493761edf4809165f7f69ff043a99f59a81eb123d603b1644d40116a2682cd4509d32dd6034a
7
- data.tar.gz: 774fffe78afb5c755b17ec7c04740fd5681a130f4dbe074e19c926d7df863a7948ea6a5b23bc43124238fcb4133029f318547db94f3a5e862bcb8b9f915a7b40
6
+ metadata.gz: 5fc4d1cb8b374931d4c53d295319e6f3c16657e0bde1dd7aa0799812bbc378390165f097b7c6627ced47f92d2ebe7459d5180745a4b00692875fbdfffda2c931
7
+ data.tar.gz: d5d39be61013fe93e275d2725e7fc4cfec83f27646c36762a2c3fbe64d1c40aa9831f7274fb7a46a7ff1500244a19a8fe76b2887539cb0e2f435a438178ff21a
@@ -56,3 +56,6 @@ RSpec/BeforeAfterAll:
56
56
 
57
57
  Style/EmptyMethod:
58
58
  EnforcedStyle: compact
59
+
60
+ RSpec/RepeatedExample:
61
+ Enabled: false
data/README.md CHANGED
@@ -67,7 +67,6 @@ use it like:
67
67
  * [Bearer Authentication with client access token](#bearer-authentication-with-client-access-token)
68
68
  * [Caching Interceptor](#caching-interceptor)
69
69
  * [Options](#options)
70
- * [Testing](#testing)
71
70
  * [Default Timeout Interceptor](#default-timeout-interceptor)
72
71
  * [Overwrite defaults](#overwrite-defaults)
73
72
  * [Logging Interceptor](#logging-interceptor)
@@ -83,13 +82,16 @@ use it like:
83
82
  * [Retry Interceptor](#retry-interceptor)
84
83
  * [Limit the amount of retries while making the request](#limit-the-amount-of-retries-while-making-the-request)
85
84
  * [Change the default maximum of retries of the retry interceptor](#change-the-default-maximum-of-retries-of-the-retry-interceptor)
85
+ * [Retry all requests](#retry-all-requests)
86
86
  * [Rollbar Interceptor](#rollbar-interceptor)
87
87
  * [Forward additional parameters](#forward-additional-parameters)
88
+ * [Throttle](#throttle)
88
89
  * [Zipkin](#zipkin)
89
90
  * [Create an interceptor from scratch](#create-an-interceptor-from-scratch)
90
91
  * [Interceptor callbacks](#interceptor-callbacks)
91
92
  * [Interceptor request/response](#interceptor-requestresponse)
92
93
  * [Provide a response replacement through an interceptor](#provide-a-response-replacement-through-an-interceptor)
94
+ * [Testing](#testing)
93
95
  * [License](#license)
94
96
 
95
97
  ## Basic methods
@@ -629,16 +631,6 @@ To avoid that case the first process to find an expired cache entry will bump th
629
631
 
630
632
  `use` - Set an explicit cache to be used for this request. If this option is missing `LHC::Caching.cache` is used.
631
633
 
632
- ##### Testing
633
-
634
- Add to your spec_helper.rb:
635
-
636
- ```ruby
637
- require 'lhc/test/cache_helper.rb'
638
- ```
639
-
640
- This will initialize a MemoryStore cache for LHC::Caching interceptor and resets the cache before every test.
641
-
642
634
  #### Default Timeout Interceptor
643
635
 
644
636
  Applies default timeout values to all requests made in an application, that uses LHC.
@@ -963,6 +955,16 @@ You can access the request.response to identify if a response was already provid
963
955
  end
964
956
  ```
965
957
 
958
+ ## Testing
959
+
960
+ When writing tests for your application when using LHC, please make sure you require the lhc rspec test helper:
961
+
962
+ ```ruby
963
+ # spec/spec_helper.rb
964
+
965
+ require 'lhc/rspec'
966
+ ```
967
+
966
968
  ## License
967
969
 
968
970
  [GNU General Public License Version 3.](https://www.gnu.org/licenses/gpl-3.0.en.html)
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lhc'
4
+
5
+ RSpec.configure do |config|
6
+ LHC::Caching.cache = ActiveSupport::Cache::MemoryStore.new
7
+
8
+ config.before(:each) do
9
+ LHC::Caching.cache.clear
10
+ LHC::Throttle.track = nil
11
+ end
12
+ end
@@ -1,9 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- LHC::Caching.cache = ActiveSupport::Cache::MemoryStore.new
5
-
6
- config.before(:each) do
7
- LHC::Caching.cache.clear
8
- end
9
- end
3
+ warn("[WARNING] require 'lhc/test/cache_helper.rb' is not needed any more! Just require 'lhc/rspec' in your spec helper instead.")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHC
4
- VERSION ||= '10.4.3'
4
+ VERSION ||= '10.5.0'
5
5
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC::Throttle do
6
+ let(:provider) { 'local.ch' }
7
+ let(:limit) { 10000 }
8
+ let(:remaining) { 1900 }
9
+ let(:options) do
10
+ {
11
+ throttle: {
12
+ provider: provider,
13
+ track: true,
14
+ limit: limit_options,
15
+ remaining: { header: 'Rate-Limit-Remaining' },
16
+ expires: { header: 'Rate-Limit-Reset' },
17
+ break: '80%'
18
+ }
19
+ }
20
+ end
21
+ let(:limit_options) { { header: 'Rate-Limit-Limit' } }
22
+ let(:break_option) { false }
23
+ let(:expires_in) { (Time.zone.now + 1.hour).to_i }
24
+
25
+ before(:each) do
26
+ LHC::Throttle.track = nil
27
+ LHC.config.interceptors = [LHC::Throttle]
28
+
29
+ stub_request(:get, 'http://local.ch')
30
+ .to_return(
31
+ headers: {
32
+ 'Rate-Limit-Limit' => limit,
33
+ 'Rate-Limit-Remaining' => remaining,
34
+ 'Rate-Limit-Reset' => expires_in
35
+ }
36
+ )
37
+ end
38
+
39
+ # If LHC::Trottle.track would be kept accross multiple tests,
40
+ # at least 2/3 of the following would fail
41
+
42
+ it 'resets track accross multiple tests 1/3' do
43
+ LHC.get('http://local.ch', options)
44
+ end
45
+
46
+ it 'resets track accross multiple tests 2/3' do
47
+ LHC.get('http://local.ch', options)
48
+ end
49
+
50
+ it 'resets track accross multiple tests 3/3' do
51
+ LHC.get('http://local.ch', options)
52
+ end
53
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhc
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.4.3
4
+ version: 10.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhc/contributors
@@ -245,6 +245,7 @@ files:
245
245
  - lib/lhc/response/data/base.rb
246
246
  - lib/lhc/response/data/collection.rb
247
247
  - lib/lhc/response/data/item.rb
248
+ - lib/lhc/rspec.rb
248
249
  - lib/lhc/test/cache_helper.rb
249
250
  - lib/lhc/version.rb
250
251
  - script/ci/build.sh
@@ -336,6 +337,7 @@ files:
336
337
  - spec/interceptors/return_response_spec.rb
337
338
  - spec/interceptors/rollbar/main_spec.rb
338
339
  - spec/interceptors/throttle/main_spec.rb
340
+ - spec/interceptors/throttle/reset_track_spec.rb
339
341
  - spec/interceptors/zipkin/distributed_tracing_spec.rb
340
342
  - spec/rails_helper.rb
341
343
  - spec/request/body_spec.rb
@@ -482,6 +484,7 @@ test_files:
482
484
  - spec/interceptors/return_response_spec.rb
483
485
  - spec/interceptors/rollbar/main_spec.rb
484
486
  - spec/interceptors/throttle/main_spec.rb
487
+ - spec/interceptors/throttle/reset_track_spec.rb
485
488
  - spec/interceptors/zipkin/distributed_tracing_spec.rb
486
489
  - spec/rails_helper.rb
487
490
  - spec/request/body_spec.rb