Sha256: 6c12f2b61bec8d663678c9725c748ae2af3d38ffcd20c620f6ae67809e333627

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe OpenSesame::GithubWarden do

  let(:strategy) { OpenSesame::GithubWarden.new(@env_with_params) }

  it "is not valid without omniauth hash" do
    @env_with_params = env_with_params("/", {}, 'omniauth.auth' => nil)
    strategy.valid?.should be_false
  end

  it "is not valid without github provider in omniauth hash" do
    @env_with_params = env_with_params("/", {}, 'omniauth.auth' => {})
    strategy.valid?.should be_false
  end

  it "is valid with github provider in omniauth hash" do
    @env_with_params = env_with_params("/", {}, 'omniauth.auth' => { "provider" => "github" })
    strategy.valid?.should be_true
  end

  it "returns omniauth auth_hash" do
    @env_with_params = env_with_params("/", {}, 'omniauth.auth' => { "provider" => "github" })
    strategy.auth_hash.should eq("provider" => "github")
  end

  it "authenticates successfully when OpenSesame::Member is found" do
    @env_with_params = env_with_params("/", {}, 'omniauth.auth' => { "provider" => "github", "uid" => "123" })

    OpenSesame::Member.should_receive(:find).with("123").and_return(OpenSesame::Member.new(:id => "123"))
    strategy.authenticate!
    strategy.result.should == :success
  end

  it "fails authentication when OpenSesame::Member is not found" do
    @env_with_params = env_with_params("/", {}, 'omniauth.auth' => { "provider" => "github", "uid" => "123" })
    OpenSesame::Member.should_receive(:find).with("123").and_return(nil)

    strategy.authenticate!
    strategy.result.should == :failure
    strategy.message.should == 'Sorry, you do not have access'
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opensesame-0.1.2 spec/lib/open_sesame/github_warden_spec.rb
opensesame-0.1.1 spec/lib/open_sesame/github_warden_spec.rb
opensesame-0.1.0 spec/lib/open_sesame/github_warden_spec.rb