From 926095f93aa7a2a9f588216bd08f4cdba5116e5e Mon Sep 17 00:00:00 2001 From: Josh Lane Date: Sun, 29 Sep 2013 15:03:20 -0700 Subject: [PATCH] accept options as default arg values * prevents empty args from nulling out valid option values --- lib/omniauth/strategy.rb | 1 + spec/omniauth/strategy_spec.rb | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/omniauth/strategy.rb b/lib/omniauth/strategy.rb index 7425f2d..3201337 100644 --- a/lib/omniauth/strategy.rb +++ b/lib/omniauth/strategy.rb @@ -136,6 +136,7 @@ module OmniAuth options.name ||= self.class.to_s.split('::').last.downcase self.class.args.each do |arg| + break if args.empty? options[arg] = args.shift end diff --git a/spec/omniauth/strategy_spec.rb b/spec/omniauth/strategy_spec.rb index e90dcc2..68d114f 100644 --- a/spec/omniauth/strategy_spec.rb +++ b/spec/omniauth/strategy_spec.rb @@ -87,7 +87,8 @@ describe OmniAuth::Strategy do end describe ".args" do - subject{ c = Class.new; c.send :include, OmniAuth::Strategy; c } + subject { c = Class.new; c.send :include, OmniAuth::Strategy; c } + it "sets args to the specified argument if there is one" do subject.args [:abc, :def] expect(subject.args).to eq([:abc, :def]) @@ -98,6 +99,17 @@ describe OmniAuth::Strategy do c = Class.new(subject) expect(c.args).to eq([:abc, :def]) end + + it "accepts corresponding options as default arg values" do + subject.args [:a, :b] + subject.option :a, "1" + subject.option :b, "2" + + expect(subject.new(nil).options.a).to eq "1" + expect(subject.new(nil).options.b).to eq "2" + expect(subject.new(nil, "3", "4").options.b).to eq "4" + expect(subject.new(nil, nil, "4").options.a).to eq nil + end end context "fetcher procs" do @@ -700,7 +712,7 @@ describe OmniAuth::Strategy do end end - let(:strategy){ ExampleStrategy.new(app, :setup => setup_proc) } + let(:strategy) { ExampleStrategy.new(app, :setup => setup_proc) } it "does not call the app on a non-omniauth endpoint" do strategy.call(make_env('/somehwere/else'))