Sha256: 66fbb77175cf5ef9e81bca1efc89a5fa93eadd55e35f4390504a65f26fd5bd44

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 KB

Contents

require File.join(File.dirname(__FILE__), "helpers", "spec_helper")

describe Videojuicer::Resource::Collection do

  before(:all) do
    @objects = [:foo]*100
    @collection = Videojuicer::Resource::Collection.new(@objects[0..9], 155, 10, 10)
  end
  
  it "is instantiated correctly" do    
    @collection.should be_kind_of(Videojuicer::Resource::Collection)
    @collection.total.should == 155
    @collection.offset.should == 10
    @collection.limit.should == 10
  end
  
  it "can count the number of pages" do
    @collection.page_count.should == 16
  end
  
  it "can tell the current page" do
    @collection.page_number.should == 2
  end
  
  it "reports page 1 when tested with a zero offset" do
    c = Videojuicer::Resource::Collection.new(@objects[0..9], 155, 0, 10)
    c.page_number.should == 1
  end
  
  it "reports page 1 when there are zero items" do
    c = Videojuicer::Resource::Collection.new(@objects[0..9], 0, 0, 10)
    c.page_number.should == 1
  end
  
  it "pagination copes with a nil limit" do
    collection = Videojuicer::Resource::Collection.new(@objects[0..9], 155, 17, nil)
    collection.page_count.should == 1
    collection.page_number.should == 1
  end
  
  it "provides a correct offset for a page number and limit when the page is 1" do
    offset = Videojuicer::Resource::Collection.offset_from_page_number 1, 20
    offset.should == 0
  end
  
  it "should provide a correct offset" do
    offset = Videojuicer::Resource::Collection.offset_from_page_number 2, 20
    offset.should == 20
  end
  
  it "should be able to take a string as a page and limit argument" do
    offset = Videojuicer::Resource::Collection.offset_from_page_number "2", "20"
    offset.should == 20
  end
  
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vj-sdk-0.8.0.1 spec/collection_spec.rb
vj-sdk-0.7.14 spec/collection_spec.rb
vj-sdk-0.7.13 spec/collection_spec.rb
vj-sdk-0.7.11 spec/collection_spec.rb
vj-sdk-0.7.10 spec/collection_spec.rb
vj-sdk-0.7.9 spec/collection_spec.rb
vj-sdk-0.7.8 spec/collection_spec.rb