Sha256: 2b0171516fd0ee48294d24986228d01393bd983e7f0f3b056c7886bc3d0e9b5a

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

require '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

1 entries across 1 versions & 1 rubygems

Version Path
fb_graph-1.7.1 spec/fb_graph/connections/accounts_spec.rb