Sha256: 9f5d19545e4b0b4d7e6a979879c9153a9fa47a0211af11fba97fe54dad586eef

Contents?: true

Size: 1.76 KB

Versions: 76

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  context 'pagination links' do
    before do
      class Customer < LHS::Record
        endpoint 'http://datastore/customer'
      end
    end

    let!(:request) do
      stub_request(:get, "http://datastore/customer#{query}")
        .to_return(body: body)
    end

    let(:query) { "?name=#{name}&page=#{page}" }

    let(:customers) do
      Customer.where(name: name, page: page)
    end

    context 'next and previous link is present' do
      let(:name) { 'Simpl' }
      let(:page) { 2 }
      let(:body) do
        {
          next: "http://datastore/customer?name=#{name}&page=3",
          previous: "http://datastore/customer?name=#{name}&page=1",
          items: [{ name: 'Simplificator' }]
        }.to_json
      end

      it 'tells me that there is a next link' do
        expect(customers.next?).to eq true
        expect(customers.previous?).to eq true
      end
    end

    context 'next link is present, previous is not' do
      let(:name) { 'Simpl' }
      let(:page) { 2 }
      let(:body) do
        {
          next: "http://datastore/customer?name=#{name}&page=3",
          items: [{ name: 'Simplificator' }]
        }.to_json
      end

      it 'tells me that there is a next link' do
        expect(customers.next?).to eq true
        expect(customers.previous?).to eq false
      end
    end

    context 'no next link and no previous link is present' do
      let(:name) { 'Simplificator' }
      let(:page) { 1 }
      let(:body) do
        {
          items: [{ name: 'Simplificator' }]
        }.to_json
      end

      it 'tells me that there is no next link' do
        expect(customers.next?).to eq false
        expect(customers.previous?).to eq false
      end
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

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