discourse/spec/lib/middleware/discourse_public_exceptions_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
2022-03-01 17:50:50 +00:00

34 lines
740 B
Ruby

# frozen_string_literal: true
describe Middleware::DiscoursePublicExceptions do
before do
@orig_logger = Rails.logger
Rails.logger = @fake_logger = FakeLogger.new
end
after do
Rails.logger = @orig_logger
end
def env(opts = {})
{
"HTTP_HOST" => "http://test.com",
"REQUEST_URI" => "/path?bla=1",
"REQUEST_METHOD" => "GET",
"rack.input" => ""
}.merge(opts)
end
it "should not log for invalid mime type requests" do
ex = Middleware::DiscoursePublicExceptions.new("/test")
ex.call(env(
"HTTP_ACCEPT" => "../broken../",
"action_dispatch.exception" => ActionController::RoutingError.new("abc")
))
expect(@fake_logger.warnings.length).to eq(0)
end
end