Class: LHS::Test::Stub

Inherits:
Object
  • Object
show all
Extended by:
WebMock::API
Defined in:
lib/lhs/test/stub.rb

Constant Summary collapse

DEFAULT_LIMIT =
LHS::Pagination::Base::DEFAULT_LIMIT

Class Method Summary collapse

Class Method Details

.all(url, items, options = {}) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lhs/test/stub.rb', line 11

def self.all(url, items, options = {})
  items.each_slice(DEFAULT_LIMIT).with_index do |(*batch), index|
    uri = LocalUri::URI.new(url)
    uri.query.merge!(limit: DEFAULT_LIMIT)
    uri.query.merge!(offset: DEFAULT_LIMIT * index) unless index.zero?
    stub_request(:get, uri.to_s)
      .with(options)
      .to_return(
        body: {
          items: batch,
          offset: index * DEFAULT_LIMIT,
          total: items.length
        }.to_json
      )
  end
end