Sha256: db736a9a36acf61f17f79d6788833bbae51b66ea49b1f00234c99468c1e0ec01

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

RSpec.describe Rails::Auth::Env do
  let(:rack_env)          { Rack::MockRequest.env_for("https://www.example.com") }
  let(:example_authority) { "some-authority" }

  subject(:example_env) { described_class.new(rack_env) }

  it "stores authorization state in the Rack environment" do
    expect(example_env).not_to be_authorized
    expect(example_env.to_rack.key?(described_class::AUTHORIZED_ENV_KEY)).to eq false
    expect(example_env.to_rack.key?(described_class::ALLOWED_BY_ENV_KEY)).to eq false

    example_env.authorize(example_authority)
    expect(example_env).to be_authorized
    expect(example_env.to_rack[described_class::AUTHORIZED_ENV_KEY]).to eq true
    expect(example_env.to_rack[described_class::ALLOWED_BY_ENV_KEY]).to eq example_authority
  end

  it "stores authorizers in the Rack environment" do
    expect(example_env.allowed_by).to be_nil
    expect(example_env.to_rack.key?(described_class::ALLOWED_BY_ENV_KEY)).to eq false

    example_env.allowed_by = example_authority
    expect(example_env.allowed_by).to eq example_authority
    expect(example_env.to_rack[described_class::ALLOWED_BY_ENV_KEY]).to eq example_authority
  end

  # TODO: this could probably be a bit more extensive
  it "stores credentials in the Rack enviroment" do
    expect(example_env.credentials).to be_a Rails::Auth::Credentials
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails-auth-3.2.0 spec/rails/auth/env_spec.rb
rails-auth-3.1.0 spec/rails/auth/env_spec.rb
rails-auth-3.0.0 spec/rails/auth/env_spec.rb
rails-auth-2.2.2 spec/rails/auth/env_spec.rb
rails-auth-2.2.1 spec/rails/auth/env_spec.rb
rails-auth-2.2.0 spec/rails/auth/env_spec.rb