Skip to content

Commit

Permalink
Strategy is now 100% covered for specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Sep 27, 2011
1 parent 6afe5f4 commit 2b69439
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/omniauth/strategy.rb
Expand Up @@ -253,8 +253,14 @@ def info
raise NotImplementedError
end

def auth_hash
hash = AuthHash.new(:provider => name, :uid => uid)
hash.info = info unless options.skip_info?
hash
end

def callback_phase
@env['omniauth.auth'] = auth_hash
self.env['omniauth.auth'] = auth_hash
call_app!
end

Expand Down Expand Up @@ -294,16 +300,6 @@ def call_app!(env = @env)
@app.call(env)
end

def auth_hash
hash = AuthHash.new(
:provider => name,
:uid => uid
)
hash.info = info unless options.skip_info?

hash
end

def full_host
case OmniAuth.config.full_host
when String
Expand Down
60 changes: 60 additions & 0 deletions spec/omniauth/strategy_spec.rb
Expand Up @@ -81,6 +81,39 @@ def make_env(path = '/auth/test', props = {})
end
end

%w(request_phase uid info).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

describe '#auth_hash' do
subject do
klass = Class.new
klass.send :include, OmniAuth::Strategy
klass.option :name, 'auth_hasher'
klass
end
let(:instance){ subject.new(app) }

it 'should call through to uid and info' do
instance.should_receive :uid
instance.should_receive :info
instance.auth_hash
end

it 'should return an AuthHash' do
instance.stub!(:uid).and_return('123')
instance.stub!(:info).and_return(:name => 'Hal Awesome')
hash = instance.auth_hash
hash.should be_kind_of(OmniAuth::AuthHash)
hash.uid.should == '123'
hash.info.name.should == 'Hal Awesome'
end
end

describe '#initialize' do
context 'options extraction' do
it 'should be the last argument if the last argument is a Hash' do
Expand All @@ -104,12 +137,39 @@ def make_env(path = '/auth/test', props = {})
end
end

it '#call should duplicate and call' do
klass = Class.new
klass.send :include, OmniAuth::Strategy
instance = klass.new(app)
instance.should_receive(:dup).and_return(instance)
instance.call({'rack.session' => {}})
end

describe '#inspect' do
it 'should just be the class name in Ruby inspect format' do
ExampleStrategy.new(app).inspect.should == '#<ExampleStrategy>'
end
end

describe '#redirect' do
it 'should use javascript if :iframe is true' do
response = ExampleStrategy.new(app, :iframe => true).redirect("http://abc.com")
response.last.body.first.should be_include("top.location.href")
end
end

describe '#callback_phase' do
subject{ k = Class.new; k.send :include, OmniAuth::Strategy; k.new(app) }

it 'should set the auth hash' do
env = make_env
subject.stub!(:env).and_return(env)
subject.stub!(:auth_hash).and_return("AUTH HASH")
subject.callback_phase
env['omniauth.auth'].should == "AUTH HASH"
end
end

describe '#full_host' do
let(:strategy){ ExampleStrategy.new(app, {}) }
it 'should not freak out if there is a pipe in the URL' do
Expand Down

0 comments on commit 2b69439

Please sign in to comment.