mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Merge pull request #874 from michaelherold/silence-mash-logger
Silence Hashie::Mash logger on Hashie 3.5.0+
This commit is contained in:
commit
0edc7ec1db
5 changed files with 126 additions and 5 deletions
|
@ -1,11 +1,11 @@
|
|||
require 'hashie/mash'
|
||||
require 'omniauth/key_store'
|
||||
|
||||
module OmniAuth
|
||||
# The AuthHash is a normalized schema returned by all OmniAuth
|
||||
# strategies. It maps as much user information as the provider
|
||||
# is able to provide into the InfoHash (stored as the `'info'`
|
||||
# key).
|
||||
class AuthHash < Hashie::Mash
|
||||
class AuthHash < OmniAuth::KeyStore
|
||||
def self.subkey_class
|
||||
Hashie::Mash
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ module OmniAuth
|
|||
super
|
||||
end
|
||||
|
||||
class InfoHash < Hashie::Mash
|
||||
class InfoHash < OmniAuth::KeyStore
|
||||
def self.subkey_class
|
||||
Hashie::Mash
|
||||
end
|
||||
|
|
22
lib/omniauth/key_store.rb
Normal file
22
lib/omniauth/key_store.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'hashie/mash'
|
||||
|
||||
module OmniAuth
|
||||
# Generic helper hash that allows method access on deeply nested keys.
|
||||
class KeyStore < ::Hashie::Mash
|
||||
# Disables warnings on Hashie 3.5.0+ for overwritten keys
|
||||
def self.override_logging
|
||||
require 'hashie/version'
|
||||
return unless Gem::Version.new(Hashie::VERSION) >= Gem::Version.new('3.5.0')
|
||||
|
||||
if respond_to?(:disable_warnings)
|
||||
disable_warnings
|
||||
else
|
||||
define_method(:log_built_in_message) { |*| }
|
||||
private :log_built_in_message
|
||||
end
|
||||
end
|
||||
|
||||
# Disable on loading of the class
|
||||
override_logging
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
require 'hashie/mash'
|
||||
require 'omniauth/key_store'
|
||||
|
||||
module OmniAuth
|
||||
class NoSessionError < StandardError; end
|
||||
|
@ -480,7 +480,7 @@ module OmniAuth
|
|||
end
|
||||
end
|
||||
|
||||
class Options < Hashie::Mash; end
|
||||
class Options < OmniAuth::KeyStore; end
|
||||
|
||||
protected
|
||||
|
||||
|
|
|
@ -105,5 +105,25 @@ describe OmniAuth::AuthHash do
|
|||
expect(OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome')).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
require 'hashie/version'
|
||||
if Gem::Version.new(Hashie::VERSION) >= Gem::Version.new('3.5.1')
|
||||
context 'with Hashie 3.5.1+' do
|
||||
around(:each) do |example|
|
||||
original_logger = Hashie.logger
|
||||
example.run
|
||||
Hashie.logger = original_logger
|
||||
end
|
||||
|
||||
it 'does not log anything in Hashie 3.5.1+' do
|
||||
logger = double('Logger')
|
||||
expect(logger).not_to receive(:warn)
|
||||
|
||||
Hashie.logger = logger
|
||||
|
||||
subject.name = 'test'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
79
spec/omniauth/key_store_spec.rb
Normal file
79
spec/omniauth/key_store_spec.rb
Normal file
|
@ -0,0 +1,79 @@
|
|||
require 'helper'
|
||||
|
||||
RSpec.describe OmniAuth::KeyStore do
|
||||
let(:logger) { double('Logger') }
|
||||
|
||||
around(:each) do |example|
|
||||
patched = monkey_patch_logger
|
||||
example.run
|
||||
remove_logger(patched)
|
||||
end
|
||||
|
||||
context 'on Hashie < 3.5.0' do
|
||||
let(:version) { '3.4.0' }
|
||||
|
||||
it 'does not log anything to the console' do
|
||||
stub_const('Hashie::VERSION', version)
|
||||
OmniAuth::KeyStore.override_logging
|
||||
expect(logger).not_to receive(:info)
|
||||
OmniAuth::KeyStore.new(:id => 1234)
|
||||
end
|
||||
end
|
||||
|
||||
context 'on Hashie 3.5.0 and 3.5.1' do
|
||||
let(:version) { '3.5.0' }
|
||||
|
||||
it 'does not log anything to the console' do
|
||||
stub_const('Hashie::VERSION', version)
|
||||
OmniAuth::KeyStore.override_logging
|
||||
expect(logger).not_to receive(:info)
|
||||
OmniAuth::KeyStore.new(:id => 1234)
|
||||
end
|
||||
end
|
||||
|
||||
context 'on Hashie 3.5.2+' do
|
||||
let(:version) { '3.5.2' }
|
||||
|
||||
around(:each) do |example|
|
||||
patching = monkey_patch_unreleased_interface
|
||||
example.run
|
||||
remove_monkey_patch(patching)
|
||||
end
|
||||
|
||||
it 'does not log anything to the console' do
|
||||
stub_const('Hashie::VERSION', version)
|
||||
OmniAuth::KeyStore.override_logging
|
||||
expect(logger).not_to receive(:info)
|
||||
OmniAuth::KeyStore.new(:id => 1234)
|
||||
end
|
||||
end
|
||||
|
||||
def monkey_patch_unreleased_interface
|
||||
return false if OmniAuth::KeyStore.class.respond_to?(:disable_warnings, true)
|
||||
|
||||
OmniAuth::KeyStore.define_singleton_method(:disable_warnings) {}
|
||||
OmniAuth::KeyStore.define_singleton_method(:log_built_in_message) { |*| }
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def monkey_patch_logger
|
||||
return unless Hashie.respond_to?(:logger)
|
||||
|
||||
original_logger = Hashie.logger
|
||||
Hashie.logger = logger
|
||||
original_logger
|
||||
end
|
||||
|
||||
def remove_logger(logger)
|
||||
return unless logger
|
||||
|
||||
Hashie.logger = logger
|
||||
end
|
||||
|
||||
def remove_monkey_patch(perform)
|
||||
return unless perform
|
||||
|
||||
OmniAuth::KeyStore.singleton_class.__send__(:remove_method, :disable_warnings)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue