lhs 19.10.0 → 21.0.0
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/Gemfile +0 -9
- data/README.md +78 -5
- data/lhs.gemspec +2 -0
- data/lib/lhs/concerns/option_blocks.rb +1 -0
- data/lib/lhs/interceptors/extended_rollbar/thread_registry.rb +1 -0
- data/lib/lhs/interceptors/request_cycle_cache/thread_registry.rb +1 -0
- data/lib/lhs/{test/request_cycle_cache_helper.rb → rspec.rb} +3 -0
- data/lib/lhs/test/stubbable_records.rb +34 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/stubs/all_spec.rb +72 -0
- metadata +35 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 80228cca0e4b14a7a21cf408db24114f85648afccc58fbc658fbe7ef579b69a9
         | 
| 4 | 
            +
              data.tar.gz: 774070abf3a426ef7f68c9ee707c540f53c91499f8576220fcae2e610baca1bd
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 33f14c2fe5cd5e6cc9a8bdbee060d247bc3f62fe9a3dfde38ff87aadb4370de371996455a4ea55865c2ee13aa7b3728e405c73ad7185e29ec48a8f2a657b750d
         | 
| 7 | 
            +
              data.tar.gz: 8aebc91f90fe095c4dc7d0d10dd8c389c0b1935928299421fce9df6c6245caa69a4991ce9f9a73758b5e316ea871a4437b7128243413634e4e7949ce96ac9405
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -1,13 +1,4 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            source 'https://rubygems.org/'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            # Declare your gem's dependencies in lhs.gemspec.
         | 
| 6 | 
            -
            # Bundler will treat runtime dependencies like base dependencies, and
         | 
| 7 | 
            -
            # development dependencies will be added by default to the :development group.
         | 
| 8 4 | 
             
            gemspec
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            # Declare any dependencies that are still in development here instead of in
         | 
| 11 | 
            -
            # your gemspec. These might include edge Rails or gems from your path or
         | 
| 12 | 
            -
            # Git. Remember to move these dependencies to your gemspec before releasing
         | 
| 13 | 
            -
            # your gem to rubygems.org.
         | 
    
        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 | 
| 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)
         | 
| @@ -1629,6 +1631,15 @@ POST https://service.example.com/records/1z-5r1fkaj { body: "{ 'name': 'Starbuck | |
| 1629 1631 |  | 
| 1630 1632 | 
             
            -> See [record validation](#record-validation) for how to handle validation errors when updating records.
         | 
| 1631 1633 |  | 
| 1634 | 
            +
            You can also pass explicit request options to `update`, by passing two explicit hashes:
         | 
| 1635 | 
            +
             | 
| 1636 | 
            +
            ```ruby
         | 
| 1637 | 
            +
            # app/controllers/some_controller.rb
         | 
| 1638 | 
            +
             | 
| 1639 | 
            +
            record.update({ recommended: true }, { method: 'put' })
         | 
| 1640 | 
            +
             | 
| 1641 | 
            +
            ```
         | 
| 1642 | 
            +
             | 
| 1632 1643 | 
             
            ##### partial_update
         | 
| 1633 1644 |  | 
| 1634 1645 | 
             
            `partial_update` updates just the provided parameters.
         | 
| @@ -1660,6 +1671,15 @@ POST https://service.example.com/records/1z-5r1fkaj { body: "{ 'name': 'Starbuck | |
| 1660 1671 |  | 
| 1661 1672 | 
             
            -> See [record validation](#record-validation) for how to handle validation errors when updating records.
         | 
| 1662 1673 |  | 
| 1674 | 
            +
            You can also pass explicit request options to `partial_update`, by passing two explicit hashes:
         | 
| 1675 | 
            +
             | 
| 1676 | 
            +
            ```ruby
         | 
| 1677 | 
            +
            # app/controllers/some_controller.rb
         | 
| 1678 | 
            +
             | 
| 1679 | 
            +
            record.partial_update({ recommended: true }, { method: 'put' })
         | 
| 1680 | 
            +
             | 
| 1681 | 
            +
            ```
         | 
| 1682 | 
            +
             | 
| 1663 1683 | 
             
            #### Endpoint url parameter injection during record creation/change
         | 
| 1664 1684 |  | 
| 1665 1685 | 
             
            LHS injects parameters provided to `create`, `update`, `partial_update`, `save` etc. into an endpoint's URL when matching:
         | 
| @@ -2502,17 +2522,70 @@ it 'displays contracts' do | |
| 2502 2522 | 
             
            end
         | 
| 2503 2523 | 
             
            ```
         | 
| 2504 2524 |  | 
| 2505 | 
            -
            ### Test helper | 
| 2525 | 
            +
            ### Test helper
         | 
| 2506 2526 |  | 
| 2507 | 
            -
            In order to  | 
| 2527 | 
            +
            In order to load LHS test helpers into your tests, add the following to your spec helper:
         | 
| 2508 2528 |  | 
| 2509 2529 | 
             
            ```ruby
         | 
| 2510 2530 | 
             
            # spec/spec_helper.rb
         | 
| 2511 2531 |  | 
| 2512 | 
            -
            require 'lhs/ | 
| 2532 | 
            +
            require 'lhs/rspec'
         | 
| 2533 | 
            +
            ```
         | 
| 2534 | 
            +
             | 
| 2535 | 
            +
            This e.g. will prevent running into caching issues during your tests, when (request cycle cache)[#request-cycle-cache] is enabled.
         | 
| 2536 | 
            +
            It will initialize a MemoryStore cache for LHC::Caching interceptor and resets the cache before every test.
         | 
| 2537 | 
            +
             | 
| 2538 | 
            +
            #### Stub
         | 
| 2539 | 
            +
             | 
| 2540 | 
            +
            LHS offers stub helpers that simplify stubbing https request to your apis through your defined Records.
         | 
| 2541 | 
            +
             | 
| 2542 | 
            +
            ##### stub_all
         | 
| 2543 | 
            +
             | 
| 2544 | 
            +
            `Record.stub_all(url, items, additional_options)`
         | 
| 2545 | 
            +
             | 
| 2546 | 
            +
            ```ruby
         | 
| 2547 | 
            +
            # your_spec.rb
         | 
| 2548 | 
            +
             | 
| 2549 | 
            +
            before do
         | 
| 2550 | 
            +
              class Record < LHS::Record
         | 
| 2551 | 
            +
                endpoint 'https://records'
         | 
| 2552 | 
            +
              end
         | 
| 2553 | 
            +
             | 
| 2554 | 
            +
              Record.stub_all(
         | 
| 2555 | 
            +
                'https://records',
         | 
| 2556 | 
            +
                200.times.map{ |index| { name: "Item #{index}" } },
         | 
| 2557 | 
            +
                headers: {
         | 
| 2558 | 
            +
                  'Authorization' => 'Bearer 123'
         | 
| 2559 | 
            +
                }
         | 
| 2560 | 
            +
              )
         | 
| 2561 | 
            +
            end
         | 
| 2562 | 
            +
            ```
         | 
| 2563 | 
            +
            ```
         | 
| 2564 | 
            +
            GET https://records?limit=100
         | 
| 2565 | 
            +
            GET https://records?limit=100&offset=100
         | 
| 2513 2566 | 
             
            ```
         | 
| 2514 2567 |  | 
| 2515 | 
            -
             | 
| 2568 | 
            +
            LHS also uses Record configuration when stubbing all.
         | 
| 2569 | 
            +
            ```ruby
         | 
| 2570 | 
            +
            # your_spec.rb
         | 
| 2571 | 
            +
             | 
| 2572 | 
            +
            before do
         | 
| 2573 | 
            +
              class Record < LHS::Record
         | 
| 2574 | 
            +
                configuration limit_key: :per_page, pagination_strategy: :page, pagination_key: :page
         | 
| 2575 | 
            +
             | 
| 2576 | 
            +
                endpoint 'https://records'
         | 
| 2577 | 
            +
              end
         | 
| 2578 | 
            +
             | 
| 2579 | 
            +
              Record.stub_all(
         | 
| 2580 | 
            +
                'https://records',
         | 
| 2581 | 
            +
                200.times.map{ |index| { name: "Item #{index}" } }
         | 
| 2582 | 
            +
              )
         | 
| 2583 | 
            +
            end
         | 
| 2584 | 
            +
            ```
         | 
| 2585 | 
            +
            ```
         | 
| 2586 | 
            +
            GET https://records?per_page=100
         | 
| 2587 | 
            +
            GET https://records?per_page=100&page=2
         | 
| 2588 | 
            +
            ```
         | 
| 2516 2589 |  | 
| 2517 2590 | 
             
            ### Test query chains
         | 
| 2518 2591 |  | 
    
        data/lhs.gemspec
    CHANGED
    
    | @@ -25,6 +25,7 @@ Gem::Specification.new do |s| | |
| 25 25 | 
             
              s.add_dependency 'activemodel'
         | 
| 26 26 | 
             
              s.add_dependency 'activesupport', '>= 4.2.11'
         | 
| 27 27 | 
             
              s.add_dependency 'lhc', '~> 10.2'
         | 
| 28 | 
            +
              s.add_dependency 'local_uri'
         | 
| 28 29 |  | 
| 29 30 | 
             
              s.add_development_dependency 'capybara'
         | 
| 30 31 | 
             
              s.add_development_dependency 'json', '>=  1.8.2'
         | 
| @@ -35,6 +36,7 @@ Gem::Specification.new do |s| | |
| 35 36 | 
             
              s.add_development_dependency 'rspec-rails', '>= 3.7.0'
         | 
| 36 37 | 
             
              s.add_development_dependency 'rubocop', '~> 0.57.1'
         | 
| 37 38 | 
             
              s.add_development_dependency 'rubocop-rspec', '~> 1.26.0'
         | 
| 39 | 
            +
              s.add_development_dependency 'sprockets', '< 4'
         | 
| 38 40 | 
             
              s.add_development_dependency 'webmock'
         | 
| 39 41 |  | 
| 40 42 | 
             
              s.license = 'GPL-3'
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'local_uri'
         | 
| 4 | 
            +
            require 'webmock'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class LHS::Record
         | 
| 7 | 
            +
              DEFAULT_LIMIT = LHS::Pagination::Base::DEFAULT_LIMIT
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              def self.stub_all(url, items, options = {})
         | 
| 10 | 
            +
                extend WebMock::API
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                items.each_slice(DEFAULT_LIMIT).with_index do |(*batch), index|
         | 
| 13 | 
            +
                  uri = LocalUri::URI.new(url)
         | 
| 14 | 
            +
                  uri.query.merge!(
         | 
| 15 | 
            +
                    limit_key(:parameter) => DEFAULT_LIMIT
         | 
| 16 | 
            +
                  )
         | 
| 17 | 
            +
                  offset = pagination_class.page_to_offset(index + 1, DEFAULT_LIMIT)
         | 
| 18 | 
            +
                  unless index.zero?
         | 
| 19 | 
            +
                    uri.query.merge!(
         | 
| 20 | 
            +
                      pagination_key(:parameter) => offset
         | 
| 21 | 
            +
                    )
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                  request_stub = stub_request(:get, uri.to_s)
         | 
| 24 | 
            +
                  request_stub.with(options) if options.present?
         | 
| 25 | 
            +
                  request_stub.to_return(
         | 
| 26 | 
            +
                    body: {
         | 
| 27 | 
            +
                      items: batch,
         | 
| 28 | 
            +
                      offset: index.zero? ? 0 : offset,
         | 
| 29 | 
            +
                      total: items.length
         | 
| 30 | 
            +
                    }.to_json
         | 
| 31 | 
            +
                  )
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
    
        data/lib/lhs/version.rb
    CHANGED
    
    
| @@ -0,0 +1,72 @@ | |
| 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 | 
            +
                Record.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 | 
            +
             | 
| 29 | 
            +
              context 'without conditions' do
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                before do
         | 
| 32 | 
            +
                  class Record < LHS::Record
         | 
| 33 | 
            +
                    endpoint 'https://records'
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  Record.stub_all(
         | 
| 37 | 
            +
                    'https://records',
         | 
| 38 | 
            +
                    200.times.map { |index| { name: "Item #{index}" } }
         | 
| 39 | 
            +
                  )
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                it 'stubs all requests without a webmock "with"' do
         | 
| 43 | 
            +
                  records = Record.all.fetch
         | 
| 44 | 
            +
                  expect(records.count).to eq 200
         | 
| 45 | 
            +
                  expect(records.length).to eq 200
         | 
| 46 | 
            +
                  expect(records.first.name).to eq 'Item 0'
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              context 'with configured record' do
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                before do
         | 
| 53 | 
            +
                  class Record < LHS::Record
         | 
| 54 | 
            +
                    configuration limit_key: :per_page, pagination_strategy: :page, pagination_key: :page
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    endpoint 'https://records'
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  Record.stub_all(
         | 
| 60 | 
            +
                    'https://records',
         | 
| 61 | 
            +
                    200.times.map { |index| { name: "Item #{index}" } }
         | 
| 62 | 
            +
                  )
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                it 'stubs all requests with record configurations for pagination' do
         | 
| 66 | 
            +
                  records = Record.all.fetch
         | 
| 67 | 
            +
                  expect(records.count).to eq 200
         | 
| 68 | 
            +
                  expect(records.length).to eq 200
         | 
| 69 | 
            +
                  expect(records.first.name).to eq 'Item 0'
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: lhs
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 21.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - https://github.com/local-ch/lhs/graphs/contributors
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019- | 
| 11 | 
            +
            date: 2019-11-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activemodel
         | 
| @@ -52,6 +52,20 @@ dependencies: | |
| 52 52 | 
             
                - - "~>"
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: '10.2'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: local_uri
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 55 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 70 | 
             
              name: capybara
         | 
| 57 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -178,6 +192,20 @@ dependencies: | |
| 178 192 | 
             
                - - "~>"
         | 
| 179 193 | 
             
                  - !ruby/object:Gem::Version
         | 
| 180 194 | 
             
                    version: 1.26.0
         | 
| 195 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 196 | 
            +
              name: sprockets
         | 
| 197 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 198 | 
            +
                requirements:
         | 
| 199 | 
            +
                - - "<"
         | 
| 200 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 201 | 
            +
                    version: '4'
         | 
| 202 | 
            +
              type: :development
         | 
| 203 | 
            +
              prerelease: false
         | 
| 204 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 205 | 
            +
                requirements:
         | 
| 206 | 
            +
                - - "<"
         | 
| 207 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 208 | 
            +
                    version: '4'
         | 
| 181 209 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 182 210 | 
             
              name: webmock
         | 
| 183 211 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -300,7 +328,8 @@ files: | |
| 300 328 | 
             
            - lib/lhs/proxy.rb
         | 
| 301 329 | 
             
            - lib/lhs/railtie.rb
         | 
| 302 330 | 
             
            - lib/lhs/record.rb
         | 
| 303 | 
            -
            - lib/lhs/ | 
| 331 | 
            +
            - lib/lhs/rspec.rb
         | 
| 332 | 
            +
            - lib/lhs/test/stubbable_records.rb
         | 
| 304 333 | 
             
            - lib/lhs/unprocessable.rb
         | 
| 305 334 | 
             
            - lib/lhs/version.rb
         | 
| 306 335 | 
             
            - script/ci/build.sh
         | 
| @@ -487,6 +516,7 @@ files: | |
| 487 516 | 
             
            - spec/request_cycle_cache_spec.rb
         | 
| 488 517 | 
             
            - spec/require_lhs_spec.rb
         | 
| 489 518 | 
             
            - spec/spec_helper.rb
         | 
| 519 | 
            +
            - spec/stubs/all_spec.rb
         | 
| 490 520 | 
             
            - spec/support/fixtures/json/feedback.json
         | 
| 491 521 | 
             
            - spec/support/fixtures/json/feedbacks.json
         | 
| 492 522 | 
             
            - spec/support/fixtures/json/localina_content_ad.json
         | 
| @@ -514,8 +544,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 514 544 | 
             
                  version: '0'
         | 
| 515 545 | 
             
            requirements:
         | 
| 516 546 | 
             
            - Ruby >= 2.3.0
         | 
| 517 | 
            -
             | 
| 518 | 
            -
            rubygems_version: 2.7.8
         | 
| 547 | 
            +
            rubygems_version: 3.0.6
         | 
| 519 548 | 
             
            signing_key: 
         | 
| 520 549 | 
             
            specification_version: 4
         | 
| 521 550 | 
             
            summary: 'REST services accelerator: Rails gem providing an easy, active-record-like
         | 
| @@ -703,6 +732,7 @@ test_files: | |
| 703 732 | 
             
            - spec/request_cycle_cache_spec.rb
         | 
| 704 733 | 
             
            - spec/require_lhs_spec.rb
         | 
| 705 734 | 
             
            - spec/spec_helper.rb
         | 
| 735 | 
            +
            - spec/stubs/all_spec.rb
         | 
| 706 736 | 
             
            - spec/support/fixtures/json/feedback.json
         | 
| 707 737 | 
             
            - spec/support/fixtures/json/feedbacks.json
         | 
| 708 738 | 
             
            - spec/support/fixtures/json/localina_content_ad.json
         |