Sha256: 87e40ae581f00ca34ac4b824ca59d320c8426eead6ab6b048dd3ca0b91f23ce8

Contents?: true

Size: 1.53 KB

Versions: 130

Compression:

Stored size: 1.53 KB

Contents

require 'rails_helper'

describe LHS::Collection do
  let(:total) { 443 }

  let(:limit) { 100 }

  def api_response(ids, offset)
    records = ids.map { |i| { id: i } }
    {
      items: records,
      total: total,
      limit: limit,
      offset: offset
    }.to_json
  end

  let(:datastore) { 'http://local.ch/v2' }

  before(:each) do
    LHC.config.placeholder('datastore', datastore)
    class Record < LHS::Record
      endpoint ':datastore/:campaign_id/feedbacks'
      endpoint ':datastore/feedbacks'
    end
  end

  context 'find_each' do
    it 'processes each record by fetching records in batches' do
      stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=1").to_return(status: 200, body: api_response((1..100).to_a, 1))
      stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=101").to_return(status: 200, body: api_response((101..200).to_a, 101))
      stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=201").to_return(status: 200, body: api_response((201..300).to_a, 201))
      stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=301").to_return(status: 200, body: api_response((301..400).to_a, 301))
      stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=401").to_return(status: 200, body: api_response((401..total).to_a, 401))
      count = 0
      Record.find_each do |record|
        count += 1
        expect(record.id).to eq(count)
        expect(record).to be_kind_of Record
        expect(record._proxy).to be_kind_of LHS::Item
      end
      expect(count).to eq total
    end
  end
end

Version data entries

130 entries across 130 versions & 1 rubygems

Version Path
lhs-14.6.5 spec/record/find_each_spec.rb
lhs-14.6.4 spec/record/find_each_spec.rb
lhs-14.6.3 spec/record/find_each_spec.rb
lhs-14.6.2 spec/record/find_each_spec.rb
lhs-14.6.1 spec/record/find_each_spec.rb
lhs-14.6.0 spec/record/find_each_spec.rb
lhs-14.5.0 spec/record/find_each_spec.rb
lhs-14.4.0 spec/record/find_each_spec.rb
lhs-14.3.4 spec/record/find_each_spec.rb
lhs-14.3.3 spec/record/find_each_spec.rb
lhs-14.3.2 spec/record/find_each_spec.rb
lhs-14.3.1 spec/record/find_each_spec.rb
lhs-14.3.0 spec/record/find_each_spec.rb
lhs-14.2.0 spec/record/find_each_spec.rb
lhs-14.1.1 spec/record/find_each_spec.rb
lhs-14.1.0 spec/record/find_each_spec.rb
lhs-14.0.3 spec/record/find_each_spec.rb
lhs-14.0.2 spec/record/find_each_spec.rb
lhs-14.0.1 spec/record/find_each_spec.rb
lhs-14.0.0 spec/record/find_each_spec.rb