mirror of
https://github.com/discourse/discourse.git
synced 2025-09-11 21:04:42 +08:00
DEV: Remove the use of stubs on Rails.logger
in our test suite.
This commit is contained in:
parent
9b01e2b855
commit
f26804394a
6 changed files with 79 additions and 37 deletions
|
@ -77,23 +77,28 @@ describe DiscourseHub do
|
|||
end
|
||||
|
||||
describe '.collection_action' do
|
||||
|
||||
it 'should log a warning if status is not 200' do
|
||||
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api")).
|
||||
to_return(status: 500, body: "", headers: {})
|
||||
|
||||
Rails.logger.expects(:warn)
|
||||
|
||||
DiscourseHub.collection_action(:get, "")
|
||||
before do
|
||||
@orig_logger = Rails.logger
|
||||
Rails.logger = @fake_logger = FakeLogger.new
|
||||
end
|
||||
|
||||
it 'should log an error if response is invalid JSON' do
|
||||
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api")).
|
||||
to_return(status: 200, body: "this is not valid JSON", headers: {})
|
||||
after do
|
||||
Rails.logger = @orig_logger
|
||||
end
|
||||
|
||||
Rails.logger.expects(:error)
|
||||
it 'should log correctly on error' do
|
||||
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api/test")).
|
||||
to_return(status: 500, body: "", headers: {})
|
||||
|
||||
DiscourseHub.collection_action(:get, "")
|
||||
DiscourseHub.collection_action(:get, '/test')
|
||||
|
||||
expect(Rails.logger.warnings).to eq([
|
||||
DiscourseHub.response_status_log_message('/test', 500),
|
||||
])
|
||||
|
||||
expect(Rails.logger.errors).to eq([
|
||||
DiscourseHub.response_body_log_message("")
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -275,15 +275,6 @@ describe Discourse do
|
|||
end
|
||||
|
||||
context '#deprecate' do
|
||||
|
||||
class FakeLogger
|
||||
attr_reader :warnings
|
||||
def warn(m)
|
||||
@warnings ||= []
|
||||
@warnings << m
|
||||
end
|
||||
end
|
||||
|
||||
def old_method(m)
|
||||
Discourse.deprecate(m)
|
||||
end
|
||||
|
@ -307,7 +298,7 @@ describe Discourse do
|
|||
expect(old_method_caller(k)).to include("discourse_spec")
|
||||
expect(old_method_caller(k)).to include(k)
|
||||
|
||||
expect(@fake_logger.warnings).to eq([old_method_caller(k)])
|
||||
expect(Rails.logger.warnings).to eq([old_method_caller(k)])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -103,14 +103,27 @@ describe Email::Processor do
|
|||
let(:mail2) { "From: #{from}\nTo: foo@foo.com\nSubject: BAR BAR\n\nBar bar bar bar?" }
|
||||
|
||||
it "sends a rejection email on an unrecognized error" do
|
||||
Email::Processor.any_instance.stubs(:can_send_rejection_email?).returns(true)
|
||||
Email::Receiver.any_instance.stubs(:process_internal).raises("boom")
|
||||
Rails.logger.expects(:error)
|
||||
begin
|
||||
@orig_logger = Rails.logger
|
||||
Rails.logger = @fake_logger = FakeLogger.new
|
||||
|
||||
Email::Processor.process!(mail)
|
||||
expect(IncomingEmail.last.error).to eq("boom")
|
||||
expect(IncomingEmail.last.rejection_message).to be_present
|
||||
expect(EmailLog.last.email_type).to eq("email_reject_unrecognized_error")
|
||||
Email::Processor.any_instance.stubs(:can_send_rejection_email?).returns(true)
|
||||
Email::Receiver.any_instance.stubs(:process_internal).raises("boom")
|
||||
|
||||
Email::Processor.process!(mail)
|
||||
|
||||
errors = Rails.logger.errors
|
||||
expect(errors.size).to eq(1)
|
||||
expect(errors.first).to include("boom")
|
||||
|
||||
incoming_email = IncomingEmail.last
|
||||
expect(incoming_email.error).to eq("boom")
|
||||
expect(incoming_email.rejection_message).to be_present
|
||||
|
||||
expect(EmailLog.last.email_type).to eq("email_reject_unrecognized_error")
|
||||
ensure
|
||||
Rails.logger = @orig_logger
|
||||
end
|
||||
end
|
||||
|
||||
it "sends more than one rejection email per day" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue