mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
parent
0ca87084a2
commit
90875e4600
2 changed files with 10 additions and 34 deletions
|
@ -84,10 +84,7 @@ module OmniAuth
|
|||
return @args || existing
|
||||
end
|
||||
|
||||
DATA_METHODS = [:uid, :info, :extra, :credentials]
|
||||
CALLBACK_METHODS = [:initialized, :request_phase, :callback_phase]
|
||||
|
||||
(DATA_METHODS + CALLBACK_METHODS).each do |fetcher|
|
||||
%w(uid info extra credentials).each do |fetcher|
|
||||
class_eval <<-RUBY
|
||||
def #{fetcher}(&block)
|
||||
return @#{fetcher}_proc unless block_given?
|
||||
|
@ -101,10 +98,11 @@ module OmniAuth
|
|||
end
|
||||
|
||||
def compile_stack(ancestors, method, context)
|
||||
stack = ancestors.reverse.inject([]) do |a, ancestor|
|
||||
stack = ancestors.inject([]) do |a, ancestor|
|
||||
a << context.instance_eval(&ancestor.send(method)) if ancestor.respond_to?(method) && ancestor.send(method)
|
||||
a
|
||||
end
|
||||
stack.reverse!
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -138,8 +136,6 @@ module OmniAuth
|
|||
raise ArgumentError, "Received wrong number of arguments. #{args.inspect}" unless args.empty?
|
||||
|
||||
yield options if block_given?
|
||||
|
||||
self.class.initialized_stack(self)
|
||||
end
|
||||
|
||||
def inspect
|
||||
|
@ -275,7 +271,7 @@ module OmniAuth
|
|||
# perform any information gathering you need to be able to authenticate
|
||||
# the user in this phase.
|
||||
def request_phase
|
||||
self.class.request_phase_stack(self)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def uid
|
||||
|
@ -323,7 +319,6 @@ module OmniAuth
|
|||
end
|
||||
|
||||
def callback_phase
|
||||
self.class.callback_phase_stack(self)
|
||||
self.env['omniauth.auth'] = auth_hash
|
||||
call_app!
|
||||
end
|
||||
|
|
|
@ -110,7 +110,7 @@ describe OmniAuth::Strategy do
|
|||
|
||||
context 'fetcher procs' do
|
||||
subject{ fresh_strategy }
|
||||
%w(uid info credentials extra initialized request_phase callback_phase).each do |fetcher|
|
||||
%w(uid info credentials extra).each do |fetcher|
|
||||
it ".#{fetcher} should be able to set and retrieve a proc" do
|
||||
proc = lambda{ "Hello" }
|
||||
subject.send(fetcher, &proc)
|
||||
|
@ -130,30 +130,11 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
context 'callback stacks' do
|
||||
subject{ fresh_strategy }
|
||||
|
||||
describe '.initialized' do
|
||||
it 'should be called after initialization' do
|
||||
subject.initialized{ raise("Called!") }
|
||||
lambda{ subject.new(app) }.should raise_error("Called!")
|
||||
end
|
||||
end
|
||||
|
||||
describe '.request_phase' do
|
||||
it 'should be called when #request_phase is called' do
|
||||
subject.request_phase{ raise("Called!") }
|
||||
lambda{ subject.new(app).request_phase }.should raise_error("Called!")
|
||||
end
|
||||
end
|
||||
|
||||
describe '.callback_phase' do
|
||||
it 'should be called before the rest of the callback_phase' do
|
||||
subject.callback_phase{ raise("Called!") }
|
||||
instance = subject.new(app)
|
||||
instance.should_receive(:auth_hash).exactly(0).times
|
||||
lambda{ instance.callback_phase }.should raise_error("Called!")
|
||||
end
|
||||
%w(request_phase).each do |abstract_method|
|
||||
it "#{abstract_method} should raise a NotImplementedError" do
|
||||
strat = Class.new
|
||||
strat.send :include, OmniAuth::Strategy
|
||||
lambda{ strat.new(app).send(abstract_method) }.should raise_error(NotImplementedError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue