diff --git a/.travis.yml b/.travis.yml index b3a9e20..3d063ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ bundler_args: --without development before_install: - - gem update --system - - gem update bundler + - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true + - gem install bundler -v '1.17.3' +install: + - bundle _1.17.3_ install --jobs=3 --retry=3 cache: bundler env: global: diff --git a/Gemfile b/Gemfile index edb91a9..e92c9a7 100644 --- a/Gemfile +++ b/Gemfile @@ -13,14 +13,14 @@ end group :test do gem 'coveralls', :require => false - gem 'hashie', '>= 3.4.6', '< 3.7.0', :platforms => [:jruby_18] + gem 'hashie', '>= 3.4.6', '~> 4.0.0', :platforms => [:jruby_18] gem 'json', '~> 2.0.3', :platforms => %i[jruby_18 jruby_19 ruby_19] gem 'mime-types', '~> 3.1', :platforms => [:jruby_18] gem 'rack', '>= 2.0.6', :platforms => %i[jruby_18 jruby_19 ruby_19 ruby_20 ruby_21] gem 'rack-test' gem 'rest-client', '~> 2.0.0', :platforms => [:jruby_18] gem 'rspec', '~> 3.5.0' - gem 'rubocop', '>= 0.58.2', :platforms => %i[ruby_20 ruby_21 ruby_22 ruby_23 ruby_24] + gem 'rubocop', '>= 0.58.2', '< 0.69.0', :platforms => %i[ruby_20 ruby_21 ruby_22 ruby_23 ruby_24] gem 'tins', '~> 1.13.0', :platforms => %i[jruby_18 jruby_19 ruby_19] end diff --git a/lib/omniauth.rb b/lib/omniauth.rb index c53ee25..dc315ee 100644 --- a/lib/omniauth.rb +++ b/lib/omniauth.rb @@ -132,7 +132,7 @@ module OmniAuth end module Utils - module_function + module_function # rubocop:disable Layout/IndentationWidth def form_css "" diff --git a/lib/omniauth/builder.rb b/lib/omniauth/builder.rb index a513571..717b4be 100644 --- a/lib/omniauth/builder.rb +++ b/lib/omniauth/builder.rb @@ -1,24 +1,5 @@ module OmniAuth class Builder < ::Rack::Builder - def initialize(app, &block) - @options = nil - if rack14? || rack2? - super - else - @app = app - super(&block) - @ins << @app - end - end - - def rack14? - Rack.release.start_with?('1.') && (Rack.release.split('.')[1].to_i >= 4) - end - - def rack2? - Rack.release.start_with? '2.' - end - def on_failure(&block) OmniAuth.config.on_failure = block end @@ -40,7 +21,7 @@ module OmniAuth end def options(options = false) - return @options || {} if options == false + return @options ||= {} if options == false @options = options end diff --git a/omniauth.gemspec b/omniauth.gemspec index aab676d..cf0f624 100644 --- a/omniauth.gemspec +++ b/omniauth.gemspec @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'omniauth/version' Gem::Specification.new do |spec| - spec.add_dependency 'hashie', ['>= 3.4.6', '< 3.7.0'] + spec.add_dependency 'hashie', ['>= 3.4.6', '~> 4.0.0'] spec.add_dependency 'rack', ['>= 1.6.2', '< 3'] spec.add_development_dependency 'bundler', '~> 1.14' spec.add_development_dependency 'rake', '~> 12.0' diff --git a/spec/omniauth/builder_spec.rb b/spec/omniauth/builder_spec.rb index 92d13fb..4e04e38 100644 --- a/spec/omniauth/builder_spec.rb +++ b/spec/omniauth/builder_spec.rb @@ -47,4 +47,84 @@ describe OmniAuth::Builder do b.provider k end end + + describe '#on_failure' do + it 'passes the block to the config' do + prok = proc {} + + with_config_reset(:on_failure) do + OmniAuth::Builder.new(nil).on_failure(&prok) + + expect(OmniAuth.config.on_failure).to eq(prok) + end + end + end + + describe '#before_options_phase' do + it 'passes the block to the config' do + prok = proc {} + + with_config_reset(:before_options_phase) do + OmniAuth::Builder.new(nil).before_options_phase(&prok) + + expect(OmniAuth.config.before_options_phase).to eq(prok) + end + end + end + + describe '#before_request_phase' do + it 'passes the block to the config' do + prok = proc {} + + with_config_reset(:before_request_phase) do + OmniAuth::Builder.new(nil).before_request_phase(&prok) + + expect(OmniAuth.config.before_request_phase).to eq(prok) + end + end + end + + describe '#before_callback_phase' do + it 'passes the block to the config' do + prok = proc {} + + with_config_reset(:before_callback_phase) do + OmniAuth::Builder.new(nil).before_callback_phase(&prok) + + expect(OmniAuth.config.before_callback_phase).to eq(prok) + end + end + end + + describe '#configure' do + it 'passes the block to the config' do + prok = proc {} + allow(OmniAuth).to receive(:configure).and_call_original + + OmniAuth::Builder.new(nil).configure(&prok) + + expect(OmniAuth).to have_received(:configure) do |&block| + expect(block).to eq(prok) + end + end + end + + describe '#call' do + it 'passes env to to_app.call' do + app = lambda { |_env| [200, {}, []] } + builder = OmniAuth::Builder.new(app) + env = {'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/some/path'} + allow(app).to receive(:call).and_call_original + + builder.call(env) + + expect(app).to have_received(:call).with(env) + end + end + + def with_config_reset(option) + old_config = OmniAuth.config.send(option) + yield + OmniAuth.config.send("#{option}=", old_config) + end end