Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Strategy is now 100% covered for specs.

  • Loading branch information...
commit 2b69439eee347971e402d618c775302147c25c69 1 parent 6afe5f4
Michael Bleigh mbleigh authored
Showing with 67 additions and 11 deletions.
  1. +7 −11 lib/omniauth/strategy.rb
  2. +60 −0 spec/omniauth/strategy_spec.rb
18 lib/omniauth/strategy.rb
View
@@ -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
@@ -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
60 spec/omniauth/strategy_spec.rb
View
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.