Sha256: 41e2af5238efca14c6e9490e9b00552c01b0d1d48026ddfc7079232181c9b2bd

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

RSpec.describe Rails::Auth::Monitor::Middleware do
  let(:request) { Rack::MockRequest.env_for("https://www.example.com") }

  describe "access granted" do
    let(:code) { 200 }
    let(:app)  { ->(env) { [code, env, "Hello, world!"] } }

    it "fires the callback with the env and true" do
      callback_fired = false

      middleware = described_class.new(app, lambda do |env, success|
        callback_fired = true
        expect(env).to be_a Hash
        expect(success).to eq true
      end)

      response = middleware.call(request)
      expect(callback_fired).to eq true
      expect(response.first).to eq code
    end
  end

  describe "access denied" do
    let(:app) { ->(_env) { raise(Rails::Auth::NotAuthorizedError, "not authorized!") } }

    it "renders the error page" do
      callback_fired = false

      middleware = described_class.new(app, lambda do |env, success|
        callback_fired = true
        expect(env).to be_a Hash
        expect(success).to eq false
      end)

      expect { middleware.call(request) }.to raise_error(Rails::Auth::NotAuthorizedError)
      expect(callback_fired).to eq true
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rails-auth-2.1.4 spec/rails/auth/monitor/middleware_spec.rb
rails-auth-2.1.3 spec/rails/auth/monitor/middleware_spec.rb
rails-auth-2.1.2 spec/rails/auth/monitor/middleware_spec.rb
rails-auth-2.1.1 spec/rails/auth/monitor/middleware_spec.rb
rails-auth-2.1.0 spec/rails/auth/monitor/middleware_spec.rb
rails-auth-2.0.3 spec/rails/auth/monitor/middleware_spec.rb
rails-auth-2.0.2 spec/rails/auth/monitor/middleware_spec.rb
rails-auth-2.0.1 spec/rails/auth/monitor/middleware_spec.rb