accept options as default arg values
* prevents empty args from nulling out valid option values
This commit is contained in:
parent
83284ce6c2
commit
926095f93a
|
@ -136,6 +136,7 @@ module OmniAuth
|
||||||
options.name ||= self.class.to_s.split('::').last.downcase
|
options.name ||= self.class.to_s.split('::').last.downcase
|
||||||
|
|
||||||
self.class.args.each do |arg|
|
self.class.args.each do |arg|
|
||||||
|
break if args.empty?
|
||||||
options[arg] = args.shift
|
options[arg] = args.shift
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,8 @@ describe OmniAuth::Strategy do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".args" do
|
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
|
it "sets args to the specified argument if there is one" do
|
||||||
subject.args [:abc, :def]
|
subject.args [:abc, :def]
|
||||||
expect(subject.args).to eq([:abc, :def])
|
expect(subject.args).to eq([:abc, :def])
|
||||||
|
@ -98,6 +99,17 @@ describe OmniAuth::Strategy do
|
||||||
c = Class.new(subject)
|
c = Class.new(subject)
|
||||||
expect(c.args).to eq([:abc, :def])
|
expect(c.args).to eq([:abc, :def])
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "fetcher procs" do
|
context "fetcher procs" do
|
||||||
|
@ -700,7 +712,7 @@ describe OmniAuth::Strategy do
|
||||||
end
|
end
|
||||||
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
|
it "does not call the app on a non-omniauth endpoint" do
|
||||||
strategy.call(make_env('/somehwere/else'))
|
strategy.call(make_env('/somehwere/else'))
|
||||||
|
|
Loading…
Reference in New Issue