Sha256: 980e328df1672a8975216523611947da17e0afb7130b5d6ab27eaecf2993198c

Contents?: true

Size: 1.51 KB

Versions: 12

Compression:

Stored size: 1.51 KB

Contents

require '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(:all) do
      VCR.use_cassette('collection_fetch_users') do
        subject.per_page(1).page(2)
        subject.fetch(true)
      end
    end

    context "pagination with no options" do
      use_vcr_cassette

      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" do
      use_vcr_cassette

      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

12 entries across 12 versions & 1 rubygems

Version Path
zendesk_api-0.1.11 live/collection_spec.rb
zendesk_api-0.1.10 live/collection_spec.rb
zendesk_api-0.1.9 live/collection_spec.rb
zendesk_api-0.1.8 live/collection_spec.rb
zendesk_api-0.1.7 live/collection_spec.rb
zendesk_api-0.1.6 live/collection_spec.rb
zendesk_api-0.1.5 live/collection_spec.rb
zendesk_api-0.1.4 live/collection_spec.rb
zendesk_api-0.1.3 live/collection_spec.rb
zendesk_api-0.1.2 live/collection_spec.rb
zendesk_api-0.1.1 live/collection_spec.rb
zendesk_api-0.0.9 live/collection_spec.rb