Sha256: b1013ac56f70645600608d88b994ab03706bb3f0025006d1bba68f0d6e874148

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 KB

Contents

require 'rails_helper'

describe LHS::Record do

  context 'last' do

    context 'for not paginated endpoints' do

      before do
        class Sector < LHS::Record
          endpoint 'http://services/sectors'
        end

        stub_request(:get, "http://services/sectors?limit=1")
          .to_return(
            body: [{ number: 1 }, { number: 2 }, { number: 3 }].to_json
          )
      end

      it 'returns the last record from the already complete collection' do
        sector = Sector.last
        expect(sector).to be_kind_of Sector
        expect(sector.number).to eq 3
      end
    end

    context 'for paginated endpoints' do

      before do
        class Place < LHS::Record
          endpoint 'http://datastore/places'
        end

        stub_request(:get, "http://datastore/places?limit=1")
          .to_return(
            body: {
              items: [
                { id: 'first-1', company_name: 'Localsearch AG' }
              ],
              total: 500,
              limit: 1,
              offset: 0
            }.to_json
          )

        stub_request(:get, "http://datastore/places?limit=1&offset=499")
          .to_return(
            body: {
              items: [
                { id: 'last-500', company_name: 'Curious GmbH' }
              ],
              total: 500,
              limit: 1,
              offset: 0
            }.to_json
          )
      end

      it 'returns the last record from the already complete collection' do
        place = Place.last
        expect(place).to be_kind_of Place
        expect(place.id).to eq 'last-500'
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lhs-16.1.5 spec/record/last_spec.rb
lhs-16.1.4 spec/record/last_spec.rb
lhs-16.1.3 spec/record/last_spec.rb
lhs-16.1.2 spec/record/last_spec.rb
lhs-16.1.1 spec/record/last_spec.rb
lhs-16.1.0 spec/record/last_spec.rb
lhs-16.0.1 spec/record/last_spec.rb
lhs-16.0.0 spec/record/last_spec.rb
lhs-15.7.0 spec/record/last_spec.rb
lhs-15.6.1 spec/record/last_spec.rb
lhs-15.6.0 spec/record/last_spec.rb
lhs-15.5.1 spec/record/last_spec.rb
lhs-15.5.0 spec/record/last_spec.rb