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
zogoo committed Jan 3, 2024
1 parent 75ac2f1 commit 822343b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 4 additions & 4 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 Expand Up @@ -198,4 +198,4 @@ def service_provider_finder
end
private :service_provider_finder
end
end
end
19 changes: 18 additions & 1 deletion 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 Expand Up @@ -138,4 +155,4 @@ module SamlIdp
end
end
end
end
end

0 comments on commit 822343b

Please sign in to comment.