Sha256: 4de8ca73f19a885567a018300c4c9e466e13f05679117978f5a984f40d31fd13

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

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

  def auth_hash(auth = { "provider" => "github" })
    {
      'omniauth.auth' => OmniAuth::AuthHash.new(auth)
    }
  end

  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("/", {}, auth_hash)
    strategy.valid?.should be_true
  end

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

  it "authenticates successfully when OpenSesame::Member is found" do
    @env_with_params = env_with_params("/", {}, auth_hash("provider" => "github", "uid" => "123", "info" => { "nickname" => "rickybobby" }))

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

  it "fails authentication when OpenSesame::Member is not found" do
    @env_with_params = env_with_params("/", {}, auth_hash("provider" => "github", "uid" => "123", "info" => { "nickname" => "rickybobby" }))
    OpenSesame::Member.should_receive(:find).with("rickybobby").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.4.0 spec/lib/open_sesame/github_warden_spec.rb
opensesame-0.3.0 spec/lib/open_sesame/github_warden_spec.rb
opensesame-0.2.0 spec/lib/open_sesame/github_warden_spec.rb