Skip to content

Commit

Permalink
Merge 8dbc435 into cc0f552
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbyMcWho committed Nov 11, 2019
2 parents cc0f552 + 8dbc435 commit eb00ca4
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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.14'
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.70.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
18 changes: 10 additions & 8 deletions lib/omniauth/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ def initialize(app, &block)
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
Expand Down Expand Up @@ -63,5 +55,15 @@ def provider(klass, *args, &block)
def call(env)
to_app.call(env)
end

private

def rack14?
Rack.release.start_with?('1.') && (Rack.release.split('.')[1].to_i >= 4)
end

def rack2?
Rack.release.start_with? '2.'
end
end
end
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
102 changes: 102 additions & 0 deletions spec/omniauth/builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
require 'helper'

describe OmniAuth::Builder do
describe '#initialize' do
let(:app) { lambda { |_env| [200, {}, []] } }
let(:prok) { proc {} }
let(:builder) { OmniAuth::Builder }

it 'calls original when rack 1.4' do
allow(Rack).to receive(:release).and_return('1.4.0')

expect(builder).to receive(:new).with(app, &prok).and_call_original

builder.new(app, &prok)
end

it 'calls original when rack 2' do
allow(Rack).to receive(:release).and_return('2.0.0')

expect(builder).to receive(:new).with(app, &prok).and_call_original

builder.new(app, &prok)
end
end

describe '#provider' do
it 'translates a symbol to a constant' do
expect(OmniAuth::Strategies).to receive(:const_get).with('MyStrategy').and_return(Class.new)
Expand Down Expand Up @@ -47,4 +69,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

0 comments on commit eb00ca4

Please sign in to comment.