Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept options as default arg values #701

Merged
merged 1 commit into from Sep 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/omniauth/strategy.rb
Expand Up @@ -136,6 +136,7 @@ def initialize(app, *args, &block)
options.name ||= self.class.to_s.split('::').last.downcase

self.class.args.each do |arg|
break if args.empty?
options[arg] = args.shift
end

Expand Down
16 changes: 14 additions & 2 deletions spec/omniauth/strategy_spec.rb
Expand Up @@ -87,7 +87,8 @@ def make_env(path = '/auth/test', props = {})
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])
Expand All @@ -98,6 +99,17 @@ def make_env(path = '/auth/test', props = {})
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
Expand Down Expand Up @@ -700,7 +712,7 @@ def make_env(path = '/auth/test', props = {})
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'))
Expand Down