Sha256: 04d8e5ac1f486e61e25bcd7fdd7d57306adf7ce17bb237172403676ae7ac28b5

Contents?: true

Size: 879 Bytes

Versions: 41

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

require 'local_uri'
require 'webmock'

class LHS::Record
  DEFAULT_LIMIT = LHS::Pagination::Base::DEFAULT_LIMIT

  def self.stub_all(url, items, options = {})
    extend WebMock::API

    items.each_slice(DEFAULT_LIMIT).with_index do |(*batch), index|
      uri = LocalUri::URI.new(url)
      uri.query.merge!(
        limit_key(:parameter) => DEFAULT_LIMIT
      )
      offset = pagination_class.page_to_offset(index + 1, DEFAULT_LIMIT)
      unless index.zero?
        uri.query.merge!(
          pagination_key(:parameter) => offset
        )
      end
      request_stub = stub_request(:get, uri.to_s)
      request_stub.with(options) if options.present?
      request_stub.to_return(
        body: {
          items: batch,
          offset: index.zero? ? 0 : offset,
          total: items.length
        }.to_json
      )
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
lhs-26.2.0 lib/lhs/test/stubbable_records.rb
lhs-26.1.0 lib/lhs/test/stubbable_records.rb
lhs-26.0.1 lib/lhs/test/stubbable_records.rb
lhs-26.0.0 lib/lhs/test/stubbable_records.rb
lhs-25.2.0 lib/lhs/test/stubbable_records.rb
lhs-25.1.0 lib/lhs/test/stubbable_records.rb
lhs-25.0.4 lib/lhs/test/stubbable_records.rb
lhs-25.0.3 lib/lhs/test/stubbable_records.rb
lhs-25.0.2 lib/lhs/test/stubbable_records.rb
lhs-25.0.1 lib/lhs/test/stubbable_records.rb
lhs-25.0.0 lib/lhs/test/stubbable_records.rb
lhs-24.1.2 lib/lhs/test/stubbable_records.rb
lhs-24.1.1 lib/lhs/test/stubbable_records.rb
lhs-24.1.0 lib/lhs/test/stubbable_records.rb
lhs-24.1.0.pre.2 lib/lhs/test/stubbable_records.rb
lhs-24.1.0.pre.1 lib/lhs/test/stubbable_records.rb
lhs-24.0.0 lib/lhs/test/stubbable_records.rb
lhs-23.0.2 lib/lhs/test/stubbable_records.rb
lhs-23.0.1 lib/lhs/test/stubbable_records.rb
lhs-23.0.0 lib/lhs/test/stubbable_records.rb