Adds shared options support in OmniAuth::Builder. Closes #584
This commit is contained in:
parent
1a16151ab6
commit
ab3d87ce58
|
@ -23,6 +23,11 @@ module OmniAuth
|
|||
OmniAuth.configure(&block)
|
||||
end
|
||||
|
||||
def options(options = false)
|
||||
return @options || {} if options == false
|
||||
@options = options
|
||||
end
|
||||
|
||||
def provider(klass, *args, &block)
|
||||
if klass.is_a?(Class)
|
||||
middleware = klass
|
||||
|
@ -34,6 +39,7 @@ module OmniAuth
|
|||
end
|
||||
end
|
||||
|
||||
args.last.is_a?(Hash) ? args.push(options.merge(args.pop)) : args.push(options)
|
||||
use middleware, *args, &block
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ describe OmniAuth::Builder do
|
|||
end }.should_not raise_error
|
||||
end
|
||||
|
||||
it "should raise a helpful LoadError messgae if it can't find the class" do
|
||||
it "should raise a helpful LoadError message if it can't find the class" do
|
||||
expect {
|
||||
OmniAuth::Builder.new(nil) do
|
||||
provider :lorax
|
||||
|
@ -25,4 +25,24 @@ describe OmniAuth::Builder do
|
|||
}.to raise_error(LoadError, "Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#options' do
|
||||
it 'should merge provided options in' do
|
||||
k = Class.new
|
||||
b = OmniAuth::Builder.new(nil)
|
||||
b.should_receive(:use).with(k, :foo => 'bar', :baz => 'tik')
|
||||
|
||||
b.options :foo => 'bar'
|
||||
b.provider k, :baz => 'tik'
|
||||
end
|
||||
|
||||
it 'should add an argument if no options are provided' do
|
||||
k = Class.new
|
||||
b = OmniAuth::Builder.new(nil)
|
||||
b.should_receive(:use).with(k, :foo => 'bar')
|
||||
|
||||
b.options :foo => 'bar'
|
||||
b.provider k
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue