Sha256: cb6c19e48c455dc035445abbfae0a479217e83c4b65558fce6c5c5da1a6f83a8

Contents?: true

Size: 1.48 KB

Versions: 48

Compression:

Stored size: 1.48 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

        nxt.size.should == 1
        nxt.should_not == current
      end

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

        prev.size.should == 1
        prev.should_not == 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
        subject.next.should == 3
      end

      it "should decrease page option and not call fetch" do
        subject.prev.should == 1
      end

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

        it "should do nothing on #prev" do
          subject.prev.should == []
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
zendesk_api-1.3.9 spec/live/collection_spec.rb
zendesk_api-1.3.8 spec/live/collection_spec.rb
zendesk_api-1.3.7 spec/live/collection_spec.rb
zendesk_api-1.2.10 spec/live/collection_spec.rb
zendesk_api-1.2.9 spec/live/collection_spec.rb
zendesk_api-0.3.14 spec/live/collection_spec.rb
zendesk_api-1.2.8 spec/live/collection_spec.rb
zendesk_api-1.3.5 spec/live/collection_spec.rb
zendesk_api-1.2.7 spec/live/collection_spec.rb
zendesk_api-1.3.4 spec/live/collection_spec.rb
zendesk_api-1.3.2 spec/live/collection_spec.rb
zendesk_api-1.3.1 spec/live/collection_spec.rb
zendesk_api-1.3.0 spec/live/collection_spec.rb
zendesk_api-1.3.0.rc3 spec/live/collection_spec.rb
zendesk_api-1.2.6 spec/live/collection_spec.rb
zendesk_api-1.3.0.rc2 spec/live/collection_spec.rb
zendesk_api-1.3.0.rc1 spec/live/collection_spec.rb
zendesk_api-1.2.5 spec/live/collection_spec.rb
zendesk_api-1.2.4 spec/live/collection_spec.rb
zendesk_api-1.2.3 spec/live/collection_spec.rb