Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Hashie version 4.0.x #977

Merged
merged 12 commits into from
Nov 15, 2019
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +3 to +6
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bundler 2 doesn't work on ruby < 2.3

cache: bundler
env:
global:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def self.mock_auth_for(provider)
end

module Utils
module_function
module_function # rubocop:disable Layout/IndentationWidth

def form_css
"<style type='text/css'>#{OmniAuth.config.form_css}</style>"
Expand Down
21 changes: 1 addition & 20 deletions lib/omniauth/builder.rb
Original file line number Diff line number Diff line change
@@ -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

Comment on lines -3 to -21
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we've locked rack above 1.6, we don't need any of this anymore.

def on_failure(&block)
OmniAuth.config.on_failure = block
end
Expand All @@ -40,7 +21,7 @@ def configure(&block)
end

def options(options = false)
return @options || {} if options == false
return @options ||= {} if options == false

@options = options
end
Expand Down
2 changes: 1 addition & 1 deletion omniauth.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
80 changes: 80 additions & 0 deletions spec/omniauth/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,84 @@ class ExampleClass; end
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