Sha256: 815298da8e6839c2c0460641ae972fca5839b9972b0ebb6b2377aa5f13fd2730

Contents?: true

Size: 1.3 KB

Versions: 55

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require 'rails_helper'
require 'webrick'

describe LHS::Record do

  before do
    class User < LHS::Record
      endpoint 'http://example.com/users'
      configuration(
        limit_key: 'limit',
        items_key: 'items',
        pagination_strategy: 'link'
      )
    end
  end

  context 'explicit pagination parameters for retrieving pages' do
    it 'uses explicit parameters when retrieving pages' do
      stub_request(:get, "http://example.com/users?limit=100")
        .to_return(body: {
          items: 100.times.map { |_| { name: WEBrick::Utils.random_string(10) } },
          limit: 100,
          next: { href: 'http://example.com/users?from_user_id=100&limit=100' }
        }.to_json)

      stub_request(:get, 'http://example.com/users?from_user_id=100&limit=100')
        .to_return(body: {
          items: 3.times.map { |_| { name: WEBrick::Utils.random_string(10) } },
          limit: 100,
          next: { href: 'http://example.com/users?from_user_id=200&limit=100' }
        }.to_json)

      stub_request(:get, 'http://example.com/users?from_user_id=200&limit=100')
        .to_return(body: {
          items: [],
          limit: 100
        }.to_json)

      users = User.all.fetch
      expect(users.total).to eq 103
      expect(users.count).to eq 103
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

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