lhs 20.0.0 → 20.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a7bf20f71cff5e170d43991a6bd79ab90fd35e32798663055b074a44d123dc8
4
- data.tar.gz: d05a41113ba4e00868cd7c02cb8ca26ff0d0f1ea745ef24f1a8a09771748e42c
3
+ metadata.gz: 3217c5628886888aef5df940a80a386e8c1a268739bd8937e3580b20937b6601
4
+ data.tar.gz: 04d3f83972975f96a18b3191a1c922a81c3ede6df18c99fbf386731d103df013
5
5
  SHA512:
6
- metadata.gz: '0709a3da6db7dcf227254a4aaff48a54a75315ab1a7a281e5ed9ead269a04850a94fb3a906a3192bf86626185af1f0b9f84cd016fb19756f1c9ffa602e6352a4'
7
- data.tar.gz: fe62a75e751b4f37215740368a2b68c55a1c130e59e938d5d42b769f1ca4d66f008dde1b2c21dbbc0d9bc1b0cf0bb1492d4385adf0b119e8ef1ec2ff781f63be
6
+ metadata.gz: bfbbf1039908900cad487407b4d3886cc8f371d7deef76ea4ed59fdd77f8df175ad9ca52786ee64f2bc7f900dfa6bf63b05b8de1a6e17ea4ad9eccefdd16fb60
7
+ data.tar.gz: ef68c523a6cb8c6aec0bf34d37c9997879961b87621ec24308cf218607eea5f747981be8ff3991949a71a3eaba8282d6bd9857ede708888a3aee26b3024b323f
data/README.md CHANGED
@@ -139,7 +139,9 @@ record.review # "Lunch was great
139
139
  * [Request tracing](#request-tracing)
140
140
  * [Extended Rollbar Logging](#extended-rollbar-logging)
141
141
  * [Testing with LHS](#testing-with-lhs)
142
- * [Test helper for request cycle cache](#test-helper-for-request-cycle-cache)
142
+ * [Test helper](#test-helper)
143
+ * [Stub](#stub)
144
+ * [Stub All](#stub-all)
143
145
  * [Test query chains](#test-query-chains)
144
146
  * [By explicitly resolving the chain: fetch](#by-explicitly-resolving-the-chain-fetch)
145
147
  * [Without resolving the chain: where_values_hash](#without-resolving-the-chain-where_values_hash)
@@ -2533,6 +2535,32 @@ require 'lhs/rspec'
2533
2535
  This e.g. will prevent running into caching issues during your tests, when (request cycle cache)[#request-cycle-cache] is enabled.
2534
2536
  It will initialize a MemoryStore cache for LHC::Caching interceptor and resets the cache before every test.
2535
2537
 
2538
+ #### Stub
2539
+
2540
+ LHS offers stub helpers that simplify stubbing https request to your apis.
2541
+
2542
+ ##### Stub All
2543
+
2544
+ `LHS.stub.all(url, items, additional_options)`
2545
+
2546
+ ```ruby
2547
+ # your_spec.rb
2548
+
2549
+ before do
2550
+ LHS.stub.all(
2551
+ 'https://records',
2552
+ 200.times.map{ |index| { name: "Item #{index}" } },
2553
+ headers: {
2554
+ 'Authorization' => 'Bearer 123'
2555
+ }
2556
+ )
2557
+ end
2558
+ ```
2559
+ ```
2560
+ GET https://records?limit=100
2561
+ GET https://records?limit=100&offset=100
2562
+ ```
2563
+
2536
2564
  ### Test query chains
2537
2565
 
2538
2566
  #### By explicitly resolving the chain: fetch
data/lhs.gemspec CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.add_development_dependency 'capybara'
30
30
  s.add_development_dependency 'json', '>= 1.8.2'
31
+ s.add_development_dependency 'local_uri'
31
32
  s.add_development_dependency 'pry'
32
33
  s.add_development_dependency 'pry-byebug'
33
34
  s.add_development_dependency 'rails', '>= 4.2.11'
data/lib/lhs/rspec.rb CHANGED
@@ -1,9 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'lhs'
4
+ require 'lhs/test/stub'
4
5
 
5
6
  RSpec.configure do |config|
6
7
  config.before(:each) do
7
8
  LHS.config.request_cycle_cache.clear
8
9
  end
10
+
11
+ config.before(:all) do
12
+
13
+ module LHS
14
+ def self.stub
15
+ LHS::Test::Stub
16
+ end
17
+ end
18
+ end
9
19
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'local_uri'
4
+ require 'webmock'
5
+ module LHS
6
+ module Test
7
+ class Stub
8
+ extend WebMock::API
9
+ DEFAULT_LIMIT = LHS::Pagination::Base::DEFAULT_LIMIT
10
+
11
+ def self.all(url, items, options = {})
12
+ items.each_slice(DEFAULT_LIMIT).with_index do |(*batch), index|
13
+ uri = LocalUri::URI.new(url)
14
+ uri.query.merge!(limit: DEFAULT_LIMIT)
15
+ uri.query.merge!(offset: DEFAULT_LIMIT * index) unless index.zero?
16
+ stub_request(:get, uri.to_s)
17
+ .with(options)
18
+ .to_return(
19
+ body: {
20
+ items: batch,
21
+ offset: index * DEFAULT_LIMIT,
22
+ total: items.length
23
+ }.to_json
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/lhs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '20.0.0'
4
+ VERSION = '20.1.1'
5
5
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+ require 'lhs/rspec'
5
+
6
+ describe LHS do
7
+
8
+ before do
9
+ class Record < LHS::Record
10
+ endpoint 'https://records'
11
+ end
12
+
13
+ LHS.stub.all(
14
+ 'https://records',
15
+ 200.times.map { |index| { name: "Item #{index}" } },
16
+ headers: {
17
+ 'Authorization' => 'Bearer 123'
18
+ }
19
+ )
20
+ end
21
+
22
+ it 'stubs all requests' do
23
+ records = Record.options(headers: { 'Authorization' => 'Bearer 123' }).all.fetch
24
+ expect(records.count).to eq 200
25
+ expect(records.length).to eq 200
26
+ expect(records.first.name).to eq 'Item 0'
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 20.0.0
4
+ version: 20.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.8.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: local_uri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -301,6 +315,7 @@ files:
301
315
  - lib/lhs/railtie.rb
302
316
  - lib/lhs/record.rb
303
317
  - lib/lhs/rspec.rb
318
+ - lib/lhs/test/stub.rb
304
319
  - lib/lhs/unprocessable.rb
305
320
  - lib/lhs/version.rb
306
321
  - script/ci/build.sh
@@ -487,6 +502,7 @@ files:
487
502
  - spec/request_cycle_cache_spec.rb
488
503
  - spec/require_lhs_spec.rb
489
504
  - spec/spec_helper.rb
505
+ - spec/stubs/all_spec.rb
490
506
  - spec/support/fixtures/json/feedback.json
491
507
  - spec/support/fixtures/json/feedbacks.json
492
508
  - spec/support/fixtures/json/localina_content_ad.json
@@ -703,6 +719,7 @@ test_files:
703
719
  - spec/request_cycle_cache_spec.rb
704
720
  - spec/require_lhs_spec.rb
705
721
  - spec/spec_helper.rb
722
+ - spec/stubs/all_spec.rb
706
723
  - spec/support/fixtures/json/feedback.json
707
724
  - spec/support/fixtures/json/feedbacks.json
708
725
  - spec/support/fixtures/json/localina_content_ad.json