1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Block in Strategy.configure can return nil

This commit is contained in:
Nash Bridges 2013-03-14 18:38:21 +02:00
parent e515908f10
commit 9d4801fc9b
2 changed files with 20 additions and 6 deletions

View file

@ -50,8 +50,11 @@ module OmniAuth
# configure foo: 'bar'
# end
def configure(options = nil)
yield default_options and return unless options
default_options.deep_merge!(options)
if block_given?
yield default_options
else
default_options.deep_merge!(options)
end
end
# Directly declare a default option for your class. This is a useful from

View file

@ -28,11 +28,22 @@ describe OmniAuth::Strategy do
describe ".configure" do
subject { klass = Class.new; klass.send :include, OmniAuth::Strategy; klass }
it "takes a block and allow for default options setting" do
subject.configure do |c|
c.wakka = 'doo'
context "when block is passed" do
it "allows for default options setting" do
subject.configure do |c|
c.wakka = 'doo'
end
expect(subject.default_options["wakka"]).to eq("doo")
end
it "works when block doesn't evaluate to true" do
environment_variable = nil
subject.configure do |c|
c.abc = '123'
c.hgi = environment_variable
end
expect(subject.default_options["abc"]).to eq("123")
end
expect(subject.default_options["wakka"]).to eq("doo")
end
it "takes a hash and deep merge it" do