Sha256: bac4eb27c30653592419d335b4a4d9e3b7c9f8167784898e14e840382f895c5e

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

require File.join(File.dirname(__FILE__), '../../spec_helper')

describe FbGraph::Connections::Accounts, '#accounts' do
  context 'when included by FbGraph::User' do
    before do
      fake_json(:get, 'matake/accounts', 'users/accounts/matake_public', :status => [401, 'Unauthorized'])
      fake_json(:get, 'matake/accounts?access_token=access_token', 'users/accounts/matake_private')
      fake_json(:get, 'matake/accounts?access_token=access_token_with_manage_pages_permission', 'users/accounts/matake_private_with_manage_pages_permission')
    end

    context 'when no access_token given' do
      it 'should raise FbGraph::Unauthorized' do
        lambda do
          FbGraph::User.new('matake').accounts
        end.should raise_exception(FbGraph::Unauthorized)
      end
    end

    context 'when access_token is given' do
      it 'should return accounts as FbGraph::Page' do
        accounts = FbGraph::User.new('matake', :access_token => 'access_token').accounts
        accounts.class.should == FbGraph::Connection
        accounts.first.should == FbGraph::Page.new(
          '140478125968442',
          :access_token => 'access_token',
          :name => 'OAuth.jp',
          :category => 'Technology'
        )
        accounts.each do |account|
          account.should be_instance_of(FbGraph::Page)
        end
      end

      context 'when manage_pages permission given' do
        it 'should has special access_token behalf of the page' do
          accounts = FbGraph::User.new('matake', :access_token => 'access_token_with_manage_pages_permission').accounts
          accounts.first.should == FbGraph::Page.new(
            '140478125968442',
            :access_token => 'access_token_for_oauth_jp',
            :name => 'OAuth.jp',
            :category => 'Technology'
          )
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fb_graph-1.7.0 spec/fb_graph/connections/accounts_spec.rb
fb_graph-1.7.0.alpha2 spec/fb_graph/connections/accounts_spec.rb
fb_graph-1.6.9 spec/fb_graph/connections/accounts_spec.rb
fb_graph-1.7.0.alpha spec/fb_graph/connections/accounts_spec.rb
fb_graph-1.6.8 spec/fb_graph/connections/accounts_spec.rb