Sha256: ddcfce14782acb8a9555613b7c500d70aea72bacffbeac421b92cdff9d80cf1a

Contents?: true

Size: 1.96 KB

Versions: 76

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'

describe FbGraph::AdUser do
  subject { ad_user }
  let(:ad_user) { FbGraph::AdUser.new(attributes[:uid], attributes) }
  let(:role) { FbGraph::AdUser::ROLES[:admin] }
  let(:permissions) { [1,3,4,7] }
  let :attributes do
    {
      :uid => '123456',
      :permissions => permissions,
      :role => role
    }
  end

  it 'should setup all supported attributes' do
    ad_user.identifier.should == "123456"
    ad_user.permissions.should == permissions
    ad_user.role.should == role
  end

  describe 'role' do
    FbGraph::AdUser::ROLES.keys.each do |role|
      context "when #{role} role given" do
        let(:role) { FbGraph::AdUser::ROLES[role] }
        its(:"#{role}_access?") { should be_true }
        (FbGraph::AdUser::ROLES.keys - [role]).each do |no_access|
          its(:"#{no_access}_access?") { should be_false }
        end
      end
    end
  end

  describe 'permissions' do
    FbGraph::AdUser::PERMISSIONS.keys.each do |permission|
      context "when #{permission} permission given" do
        let(:permissions) { [FbGraph::AdUser::PERMISSIONS[permission]] }
        its(:"#{permission}_access?") { should be_true }
        (FbGraph::AdUser::PERMISSIONS.keys - [permission]).each do |no_access|
          its(:"#{no_access}_access?") { should be_false }
        end
      end
    end
  end

  describe ".fetch" do
    let(:ad_user) do
      FbGraph::AdUser.new(
        "579612276",
        :permissions => permissions,
        :role => role
      )
    end

    it "should fetch the regular User and add the AdUser attributes" do
      mock_graph :get, '579612276', 'users/me_private', :access_token => 'access_token' do
        fetched_user = ad_user.fetch(:access_token => 'access_token')

        fetched_user.identifier.should == "579612276"
        fetched_user.first_name = "Nov"
        fetched_user.last_name = "Matake"
        fetched_user.permissions.should == permissions
        fetched_user.role.should == role
      end
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
fb_graph-2.7.17 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.16 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.15 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.14 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.13 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.12 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.11 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.10 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.9 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.8 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.7 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.6 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.5 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.4 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.3 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.2 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.1 spec/fb_graph/ad_user_spec.rb
fb_graph-2.7.0 spec/fb_graph/ad_user_spec.rb
fb_graph-2.6.7 spec/fb_graph/ad_user_spec.rb
fb_graph-2.6.6 spec/fb_graph/ad_user_spec.rb