Sha256: 44641115002e2915aa83857ab7e10e268e659de89fc3099af2a2ed676d5e9dd8

Contents?: true

Size: 1.52 KB

Versions: 36

Compression:

Stored size: 1.52 KB

Contents

require 'core/spec_helper'

describe ZendeskAPI::Collection do
  subject do
    ZendeskAPI::Collection.new(client, ZendeskAPI::TestResource)
  end

  context "with real data" do
    subject do
      ZendeskAPI::Collection.new(client, ZendeskAPI::User)
    end

    before(:each) do
      VCR.use_cassette('collection_fetch_users') do
        subject.per_page(1).page(2)
        subject.fetch(true)
      end
    end

    context "pagination with no options", :vcr do
      before(:each) { subject.per_page(nil).page(nil) }

      it "should find the next page by calling fetch" do
        current = subject.to_a.dup
        nxt = subject.next

        expect(nxt.size).to eq(1)
        expect(nxt).to_not eq(current)
      end

      it "should find the prev page by calling fetch" do
        current = subject.to_a.dup
        prev = subject.prev

        expect(prev.size).to eq(1)
        expect(prev).to_not eq(current)
      end
    end

    context "pagination with options", :vcr do
      before(:each) { subject.per_page(1).page(2) }

      it "should increase page option and not call fetch" do
        expect(subject.next).to eq(3)
      end

      it "should decrease page option and not call fetch" do
        expect(subject.prev).to eq(1)
      end

      context "with page == 1" do
        before do
          subject.page(1)
          subject.clear_cache
          expect(subject).to_not receive(:fetch)
        end

        it "should do nothing on #prev" do
          expect(subject.prev).to eq([])
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
zendesk_api-1.13.1 spec/live/collection_spec.rb
zendesk_api-1.12.1 spec/live/collection_spec.rb
zendesk_api-1.12.0 spec/live/collection_spec.rb
zendesk_api-1.11.7 spec/live/collection_spec.rb
zendesk_api-1.11.6 spec/live/collection_spec.rb
zendesk_api-1.11.5 spec/live/collection_spec.rb
zendesk_api-1.11.4 spec/live/collection_spec.rb
zendesk_api-1.11.3 spec/live/collection_spec.rb
zendesk_api-1.11.2 spec/live/collection_spec.rb
zendesk_api-1.11.1 spec/live/collection_spec.rb
zendesk_api-1.11.0 spec/live/collection_spec.rb
zendesk_api-1.10.0 spec/live/collection_spec.rb
zendesk_api-1.9.6 spec/live/collection_spec.rb
zendesk_api-1.9.5 spec/live/collection_spec.rb
zendesk_api-1.9.4 spec/live/collection_spec.rb
zendesk_api-1.9.3 spec/live/collection_spec.rb
zendesk_api-1.9.2 spec/live/collection_spec.rb
zendesk_api-1.9.1 spec/live/collection_spec.rb
zendesk_api-1.9.0 spec/live/collection_spec.rb
zendesk_api-1.8.0 spec/live/collection_spec.rb