Sha256: 9d038dca38bc2cf21a9952d03be1afc7e5d0fa857aba899c18287eb761f69e24

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

require "spec_helper"

describe "strategies" do

  class TestHelper
    include JekyllAuth::Helpers

    def initialize(path=nil)
      @path = path
    end

    def request
      Rack::Request.new("PATH_INFO" => @path)
    end
  end

  before(:each) do
    JekyllAuth.instance_variable_set("@config", nil)
    @helper = TestHelper.new
    ENV["GITHUB_ORG_ID"] = nil
    ENV["GITHUB_TEAM_ID"] = nil
    ENV["GITHUB_TEAMS_ID"] = nil
  end

  it "should return nil if no ID is set" do
    expect(@helper.authentication_strategy).to eql(nil)
  end

  it "should detect the org strategy" do
    with_env("GITHUB_ORG_ID", "some_org") do
      expect(@helper.authentication_strategy).to eql(:org)
    end
  end

  it "should detect the team strategy" do
    with_env("GITHUB_TEAM_ID", "1234") do
      expect(@helper.authentication_strategy).to eql(:team)
    end
  end

  it "should detect the teams strategy" do
    with_env("GITHUB_TEAM_IDS", "1234,5678") do
      expect(@helper.authentication_strategy).to eql(:teams)
    end
  end

  it "should know if a path is whitelisted" do
    File.write(JekyllAuth.config_file, "jekyll_auth:\n  whitelist:\n   - drafts?\n")

    helper = TestHelper.new("/foo")
    expect(helper.whitelisted?).to eql(false)

    helper = TestHelper.new("/draft")
    expect(helper.whitelisted?).to eql(true)
  end

  it "should not err out if there is no whitelist" do
    helper = TestHelper.new("/drafts")
    JekyllAuth.instance_variable_set("@config", {})
    expect(helper.whitelisted?).to eql(false)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-auth-1.0.3 spec/jekyll_auth_helpers_spec.rb
jekyll-auth-1.0.2 spec/jekyll_auth_helpers_spec.rb
jekyll-auth-1.0.1 spec/jekyll_auth_helpers_spec.rb
jekyll-auth-1.0.0 spec/jekyll_auth_helpers_spec.rb