mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 17:33:27 +08:00
DEV: Remove the use of stubs on Rails.logger
in our test suite.
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user