Skip to content

Commit

Permalink
Test logger interface instead of class
Browse files Browse the repository at this point in the history
Rails 7.1.0 introduces a new default logger class,
ActiveSupport::BroadcastLogger, which does not inherit from Logger.
(See: rails/rails#48615.)

Instead of testing for a specific class, we can test the interface.
  • Loading branch information
elliterate committed Oct 13, 2023
1 parent 75ac2f1 commit ba57f7c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/saml_idp/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def response_url
end

def log(msg)
if config.logger.class <= ::Logger
config.logger.info msg
else
if config.logger.respond_to?(:call)
config.logger.call msg
else
config.logger.info msg
end
end

Expand Down
17 changes: 17 additions & 0 deletions spec/lib/saml_idp/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ module SamlIdp
end
end

context 'a Logger-like logger is configured' do
let(:logger) do
Class.new {
def info(msg); end
}.new
end

before do
allow(logger).to receive(:info)
end

it 'logs an error message' do
expect(subject.valid?).to be false
expect(logger).to have_received(:info).with('Unable to find service provider for issuer ')
end
end

context 'a logger lambda is configured' do
let(:logger) { double }

Expand Down

0 comments on commit ba57f7c

Please sign in to comment.