Sha256: 1751a12b98e121cefc31e7347e18c059823ff5ab25ff9cb2b40f7e0c1ff31c87

Contents?: true

Size: 800 Bytes

Versions: 10

Compression:

Stored size: 800 Bytes

Contents

RSpec.describe Rails::Auth::ErrorPage::Middleware do
  let(:request)    { Rack::MockRequest.env_for("https://www.example.com") }
  let(:error_page) { "<h1> Unauthorized!!! </h1>" }

  subject(:middleware) { described_class.new(app, page_body: error_page) }

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

    it "renders the expected response" do
      response = middleware.call(request)
      expect(response.first).to eq code
    end
  end

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

    it "renders the error page" do
      code, _env, body = middleware.call(request)
      expect(code).to eq 403
      expect(body).to eq [error_page]
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails-auth-1.2.0 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-1.1.0 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-1.0.0 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-0.5.3 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-0.5.2 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-0.5.1 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-0.5.0 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-0.4.1 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-0.4.0 spec/rails/auth/error_page/middleware_spec.rb
rails-auth-0.3.0 spec/rails/auth/error_page/middleware_spec.rb