Sha256: bd41231374b807daa74cfadf8ff6af821259afc39fbfd2128aa14cbb18e764eb

Contents?: true

Size: 1.73 KB

Versions: 19

Compression:

Stored size: 1.73 KB

Contents

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

19 entries across 19 versions & 1 rubygems

Version Path
lhs-16.1.5 spec/record/pagination_links_spec.rb
lhs-16.1.4 spec/record/pagination_links_spec.rb
lhs-16.1.3 spec/record/pagination_links_spec.rb
lhs-16.1.2 spec/record/pagination_links_spec.rb
lhs-16.1.1 spec/record/pagination_links_spec.rb
lhs-16.1.0 spec/record/pagination_links_spec.rb
lhs-16.0.1 spec/record/pagination_links_spec.rb
lhs-16.0.0 spec/record/pagination_links_spec.rb
lhs-15.7.0 spec/record/pagination_links_spec.rb
lhs-15.6.1 spec/record/pagination_links_spec.rb
lhs-15.6.0 spec/record/pagination_links_spec.rb
lhs-15.5.1 spec/record/pagination_links_spec.rb
lhs-15.5.0 spec/record/pagination_links_spec.rb
lhs-15.4.1 spec/record/pagination_links_spec.rb
lhs-15.4.0 spec/record/pagination_links_spec.rb
lhs-15.4.0.pre.hasone.1 spec/record/pagination_links_spec.rb
lhs-15.3.3 spec/record/pagination_links_spec.rb
lhs-15.3.3.pre.fixoptions.1 spec/record/pagination_links_spec.rb
lhs-15.3.2 spec/record/pagination_links_spec.rb