mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: logspam due to 404s on CSS files
We had a missing formats: string on our render partial that caused logs to spam when CSS files got 404s. Due to magic discourse_public_exceptions.rb was actually returning the correct 404 cause it switched format when rendering the error.
This commit is contained in:
@@ -144,6 +144,40 @@ RSpec.describe ApplicationController do
|
||||
expect(response.body).to_not include('google.com/search')
|
||||
end
|
||||
|
||||
describe 'no logspam' do
|
||||
|
||||
before do
|
||||
@orig_logger = Rails.logger
|
||||
Rails.logger = @fake_logger = FakeLogger.new
|
||||
end
|
||||
|
||||
after do
|
||||
Rails.logger = @orig_logger
|
||||
end
|
||||
|
||||
it 'should handle 404 to a css file' do
|
||||
|
||||
$redis.del("page_not_found_topics")
|
||||
|
||||
topic1 = Fabricate(:topic)
|
||||
get '/stylesheets/mobile_1_4cd559272273fe6d3c7db620c617d596a5fdf240.css', headers: { 'HTTP_ACCEPT' => 'text/css,*/*,q=0.1' }
|
||||
expect(response.status).to eq(404)
|
||||
expect(response.body).to include(topic1.title)
|
||||
|
||||
topic2 = Fabricate(:topic)
|
||||
get '/stylesheets/mobile_1_4cd559272273fe6d3c7db620c617d596a5fdf240.css', headers: { 'HTTP_ACCEPT' => 'text/css,*/*,q=0.1' }
|
||||
expect(response.status).to eq(404)
|
||||
expect(response.body).to include(topic1.title)
|
||||
expect(response.body).to_not include(topic2.title)
|
||||
|
||||
expect(Rails.logger.fatals.length).to eq(0)
|
||||
expect(Rails.logger.errors.length).to eq(0)
|
||||
expect(Rails.logger.warnings.length).to eq(0)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
it 'should cache results' do
|
||||
$redis.del("page_not_found_topics")
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
class FakeLogger
|
||||
attr_reader :warnings, :errors, :infos
|
||||
attr_reader :warnings, :errors, :infos, :fatals
|
||||
|
||||
def initialize
|
||||
@warnings = []
|
||||
@errors = []
|
||||
@infos = []
|
||||
@fatals = []
|
||||
end
|
||||
|
||||
def info(message = nil)
|
||||
@@ -18,4 +19,11 @@ class FakeLogger
|
||||
def error(message)
|
||||
@errors << message
|
||||
end
|
||||
|
||||
def fatal(message)
|
||||
@fatals << message
|
||||
end
|
||||
|
||||
def formatter
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user