Sha256: 907ae75e882c77cc050f8c3d33c8f3548244ed68f6cb170379d4b6f332dced50

Contents?: true

Size: 1.67 KB

Versions: 23

Compression:

Stored size: 1.67 KB

Contents

require 'rails_helper'
require 'webrick'

describe LHS::Record do

  before(:each) do
    class Location < LHS::Record
      endpoint 'http://uberall/locations'
      configuration(
        limit_key: { body: %i[response max], parameter: :max },
        pagination_key: { body: %i[response offset], parameter: :offset },
        total_key: %i[response count],
        items_key: %i[response locations],
        pagination_strategy: :offset
      )
    end
  end

  context 'explicit pagination paramters for retreiving pages' do

    it 'uses explicit parameters when retreiving pages' do
      stub_request(:get, "http://uberall/locations?max=100")
        .to_return(body: {
          response: {
            locations: 10.times.map { |_| { name: WEBrick::Utils.random_string(10) } },
            max: 10,
            offset: 0,
            count: 30
          }
        }.to_json)

      stub_request(:get, "http://uberall/locations?max=10&offset=10")
        .to_return(body: {
          response: {
            locations: 10.times.map { |_| { name: WEBrick::Utils.random_string(10) } },
            max: 10,
            offset: 10,
            count: 30
          }
        }.to_json)

      stub_request(:get, "http://uberall/locations?max=10&offset=20")
        .to_return(body: {
          response: {
            locations: 10.times.map { |_| { name: WEBrick::Utils.random_string(10) } },
            max: 10,
            offset: 20,
            count: 30
          }
        }.to_json)

      locations = Location.all.fetch
      expect(locations.length).to eq 30
      expect(locations.count).to eq 30
      expect(locations.offset).to eq 20
      expect(locations.limit).to eq 10
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
lhs-15.3.1 spec/pagination/parameters_spec.rb
lhs-15.3.1.pre.fixlhc.1 spec/pagination/parameters_spec.rb
lhs-15.3.0 spec/pagination/parameters_spec.rb
lhs-15.2.5 spec/pagination/parameters_spec.rb
lhs-15.2.4 spec/pagination/parameters_spec.rb
lhs-15.2.3 spec/pagination/parameters_spec.rb
lhs-15.2.3.pre.favorites.1 spec/pagination/parameters_spec.rb
lhs-15.2.2.pre.favorites.1 spec/pagination/parameters_spec.rb
lhs-15.2.2 spec/pagination/parameters_spec.rb
lhs-15.2.1 spec/pagination/parameters_spec.rb
lhs-15.2.0 spec/pagination/parameters_spec.rb
lhs-15.1.1 spec/pagination/parameters_spec.rb
lhs-15.1.0 spec/pagination/parameters_spec.rb
lhs-15.0.2 spec/pagination/parameters_spec.rb
lhs-15.0.1 spec/pagination/parameters_spec.rb
lhs-15.0.0 spec/pagination/parameters_spec.rb
lhs-14.6.5 spec/pagination/parameters_spec.rb
lhs-14.6.4 spec/pagination/parameters_spec.rb
lhs-14.6.3 spec/pagination/parameters_spec.rb
lhs-14.6.2 spec/pagination/parameters_spec.rb