Sha256: ecd425110686369bca489c929aca06b4b0078a9d16a313304a0317d42d982b4a

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

RSpec.describe SoapyCake::AdminBatched do
  let(:admin) { double('admin') }

  before :each do
    allow(SoapyCake::Admin).to receive(:new).and_return(admin)

    stub_const('SoapyCake::AdminBatched::BatchedRequest::LIMIT', 2)
  end

  it 'returns an enumerator and uses batched CAKE calls' do
    expect(admin).to receive(:offers)
      .with(advertiser: 1, start_at_row: 1, row_limit: 2).and_return(%i(a b))
    expect(admin).to receive(:offers)
      .with(advertiser: 1, start_at_row: 3, row_limit: 2).and_return(%i(c))

    result = subject.offers(advertiser: 1)

    expect(result).to be_a(Enumerator)
    expect(result.to_a).to eq(%i(a b c))
  end

  it 'can use a custom limit' do
    expect(admin).to receive(:offers)
      .with(advertiser: 1, start_at_row: 1, row_limit: 100).and_return(%i(a b))

    expect(subject.offers({ advertiser: 1 }, 100).to_a).to eq(%i(a b))
  end

  context 'errors' do
    it 'fails with an invalid method' do
      expect { subject.something }.to raise_error(/Invalid method something/)
    end

    it 'fails when row_limit is set' do
      expect { subject.offers(row_limit: 123) }.to raise_error(/Cannot set .* in batched mode/)
    end

    it 'fails when start_at_row is set' do
      expect { subject.offers(start_at_row: 123) }.to raise_error(/Cannot set .* in batched mode/)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
soapy_cake-1.11.4 spec/lib/soapy_cake/admin_batched_spec.rb
soapy_cake-1.11.3 spec/lib/soapy_cake/admin_batched_spec.rb
soapy_cake-1.11.2 spec/lib/soapy_cake/admin_batched_spec.rb
soapy_cake-1.11.1 spec/lib/soapy_cake/admin_batched_spec.rb