Sha256: ee6516f179144b7f9ca4befa8713eaf10e5ceb3273a0910d972fb56824c06bf6

Contents?: true

Size: 1.95 KB

Versions: 3

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'

describe FbGraph::Collection, '.new' do

  it 'should return an array with pagination info' do
    mock_graph :get, 'platform/statuses', 'pages/statuses/platform_private', :access_token => 'access_token' do
      collection = FbGraph::Page.new('platform', :access_token => 'access_token').statuses.collection
      collection.should be_kind_of(Array)
      collection.previous.should be_kind_of(Hash)
      collection.next.should be_kind_of(Hash)
    end
  end

  it 'should allow blank data' do
    patterns = [
      FbGraph::Collection.new,
      FbGraph::Collection.new({}),
      FbGraph::Collection.new({:count => 5}),
      FbGraph::Collection.new(nil)
    ]
    patterns.each do |collection|
      collection.should be_kind_of(Array)
      collection.previous.should be_kind_of(Hash)
      collection.next.should be_kind_of(Hash)
      collection.should be_blank
      collection.previous.should be_blank
      collection.next.should be_blank
    end
  end

  it 'should fetch count as total_count' do
    collection = FbGraph::Collection.new({:count => 5})
    collection.total_count.should == 5
  end

  it 'should accept Array' do
    collection = FbGraph::Collection.new([1, 2, 3])
    collection.total_count.should == 3
    collection.should == [1, 2, 3]
    collection.previous.should be_blank
    collection.next.should be_blank
  end

  it 'should raise error for invalid input' do
    lambda do
      FbGraph::Collection.new("STRING")
    end.should raise_error(ArgumentError, 'Invalid collection')
  end

  it 'should handle paging params' do
    mock_graph :get, 'post_id/comments', 'posts/comments/with_paging_params' do
      comments = FbGraph::Post.new('post_id').comments
      comments.should be_instance_of FbGraph::Connection
      comments.should be_a FbGraph::Collection
      comments.collection.next.should include :limit, :offset, :__after_id
      comments.collection.previous.should include :limit, :offset, :__before_id
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fb_graph-2.7.0 spec/fb_graph/collection_spec.rb
fb_graph-2.6.7 spec/fb_graph/collection_spec.rb
fb_graph-2.6.6 spec/fb_graph/collection_spec.rb