mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
DEV: Don’t replace Rails logger in specs (#29721)
Instead of replacing the Rails logger in specs, we can instead use `#broadcast_to` which has been introduced in Rails 7.
This commit is contained in:
@ -2,15 +2,16 @@
|
||||
|
||||
RSpec.describe CspReportsController do
|
||||
describe "#create" do
|
||||
let(:fake_logger) { FakeLogger.new }
|
||||
|
||||
before do
|
||||
SiteSetting.content_security_policy = true
|
||||
SiteSetting.content_security_policy_collect_reports = true
|
||||
|
||||
@orig_logger = Rails.logger
|
||||
Rails.logger = @fake_logger = FakeLogger.new
|
||||
Rails.logger.broadcast_to(fake_logger)
|
||||
end
|
||||
|
||||
after { Rails.logger = @orig_logger }
|
||||
after { Rails.logger.stop_broadcasting_to(fake_logger) }
|
||||
|
||||
def send_report
|
||||
post "/csp_reports",
|
||||
@ -73,7 +74,7 @@ RSpec.describe CspReportsController do
|
||||
|
||||
it "logs the violation report" do
|
||||
send_report
|
||||
expect(@fake_logger.warnings).to include(
|
||||
expect(fake_logger.warnings).to include(
|
||||
"CSP Violation: 'http://suspicio.us/assets.js' \n\nconsole.log('unsafe')",
|
||||
)
|
||||
end
|
||||
|
Reference in New Issue
Block a user