Sha256: 10f4a205cbdcd8c1a456f4580d2a7c0e1b4d660e241c2f57703890df6af12077

Contents?: true

Size: 1.88 KB

Versions: 9

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'

module Reviewed
  class Product < Base
  end
end

describe Reviewed::Collection do
  use_vcr_cassette 'collection/products'

  let(:client) do
    Reviewed::Client.new(api_key: TEST_KEY, base_uri: TEST_URL)
  end

  before(:each) do
    @collection = client.products.all # creates a collection
  end

  describe 'collection data' do

    it 'is enumerable' do
      @collection.each do |product|
        product.class.should == Reviewed::Product
        product.id.should_not be_blank
      end
    end

    it 'fetches the first page by default' do
      @collection.current_page.should == 1
    end
  end

  describe 'next page' do

    it 'fetches the next page of results' do
      page2 = @collection.next_page
      page2.current_page.should == 2
    end
  end

  describe 'previous page' do

    it 'fetches the previous page of results' do
      page2 = @collection.next_page
      page1 = page2.previous_page
      @collection.current_page == page1.current_page
    end

    it 'returns nil if there is no previous page' do
      @collection.previous_page.should be_nil
    end
  end

  describe 'page attributes (pagination)' do

    it 'returns the total item count' do
      @collection.total.should > 1
    end

    it 'returns the total number of pages' do
      @collection.total_pages.should > 1
    end

    it 'indicates whether this is the first or last page' do
      @collection.first_page.should be_true
      @collection.last_page.should be_false
    end

    it 'indicates if the page number is out of bounds' do
      @collection.out_of_bounds.should be_false
    end

    it 'returns the offset' do
      @collection.offset.should == 0
    end

    it 'returns the limit value (max per page)' do
      @collection.per_page.should == 20
    end

    it 'returns the number of entries on the current page' do
      @collection.entries_on_page.should == 20
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
reviewed-0.1.29 spec/collection_spec.rb
reviewed-0.1.28 spec/collection_spec.rb
reviewed-0.1.27 spec/collection_spec.rb
reviewed-0.1.26 spec/collection_spec.rb
reviewed-0.1.25 spec/collection_spec.rb
reviewed-0.1.24 spec/collection_spec.rb
reviewed-0.1.23 spec/collection_spec.rb
reviewed-0.1.22 spec/collection_spec.rb
reviewed-0.1.21 spec/collection_spec.rb