Permalink
Browse files

Adds shared options support in OmniAuth::Builder. Closes #584

  • Loading branch information...
1 parent 1a16151 commit ab3d87ce58319a82d5032c547cab2349a911d271 Michael Bleigh committed Apr 12, 2012
Showing with 27 additions and 1 deletion.
  1. +6 −0 lib/omniauth/builder.rb
  2. +21 −1 spec/omniauth/builder_spec.rb
@@ -23,6 +23,11 @@ def configure(&block)
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 @@ def provider(klass, *args, &block)
end
end
+ args.last.is_a?(Hash) ? args.push(options.merge(args.pop)) : args.push(options)
use middleware, *args, &block
end
@@ -17,12 +17,32 @@ class ::ExampleClass; end
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
end
}.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

0 comments on commit ab3d87c

Please sign in to comment.