Sha256: abdbe31a8a1bc60067a1708e139d180bb165ec3b23ff56167c9fbebb10155cf2

Contents?: true

Size: 903 Bytes

Versions: 1

Compression:

Stored size: 903 Bytes

Contents

require 'spec_helper'
require 'switch_user/user_loader'

class User
  def self.find_by_id(id)
  end
end

describe SwitchUser::UserLoader do
  let(:user) { stub(:user) }

  it "raises an exception if we are passed an invalid scope" do
    expect { SwitchUser::UserLoader.new("useeer", 1) }.to raise_error(SwitchUser::InvalidScope)
  end

  it "loads a user" do
    User.stub(:find_by_id).with(1).and_return(user)

    loader = SwitchUser::UserLoader.new("user", 1)

    loader.load.should == user
  end

  it "returns nil if no user is found" do
    loader = SwitchUser::UserLoader.new("user", 2)
    loader.load.should == nil
  end

  it "loads a user with an alternate identifier column" do
    User.stub(:find_by_email).with(2).and_return(user)
    SwitchUser.available_users_identifiers = {:user => :email}

    loader = SwitchUser::UserLoader.new("user", 2)
    loader.load.should == user
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
switch_user-0.9.0 spec/switch_user/user_loader_spec.rb