forked from omniauth/omniauth-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgraded to RSpec3, fixes omniauth#52
- Updated all test cases to rspec3 spec syntax
- Loading branch information
Pramod
committed
Dec 17, 2015
1 parent
45f2fc7
commit 22176c9
Showing
2 changed files
with
33 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
require 'spec_helper' | ||
|
||
describe OmniAuth::Strategies::GitHub do | ||
let(:access_token) { stub('AccessToken', :options => {}) } | ||
let(:parsed_response) { stub('ParsedResponse') } | ||
let(:response) { stub('Response', :parsed => parsed_response) } | ||
let(:access_token) { double('AccessToken', :options => {}) } | ||
let(:parsed_response) { double('ParsedResponse') } | ||
let(:response) { double('Response', :parsed => parsed_response) } | ||
|
||
let(:enterprise_site) { 'https://some.other.site.com/api/v3' } | ||
let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' } | ||
|
@@ -25,117 +25,117 @@ | |
end | ||
|
||
before(:each) do | ||
subject.stub!(:access_token).and_return(access_token) | ||
allow(subject).to receive(:access_token).and_return(access_token) | ||
end | ||
|
||
context "client options" do | ||
it 'should have correct site' do | ||
subject.options.client_options.site.should eq("https://api.github.com") | ||
expect(subject.options.client_options.site).to eq("https://api.github.com") | ||
end | ||
|
||
it 'should have correct authorize url' do | ||
subject.options.client_options.authorize_url.should eq('https://github.com/login/oauth/authorize') | ||
expect(subject.options.client_options.authorize_url).to eq('https://github.com/login/oauth/authorize') | ||
end | ||
|
||
it 'should have correct token url' do | ||
subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token') | ||
expect(subject.options.client_options.token_url).to eq('https://github.com/login/oauth/access_token') | ||
end | ||
|
||
describe "should be overrideable" do | ||
it "for site" do | ||
enterprise.options.client_options.site.should eq(enterprise_site) | ||
expect(enterprise.options.client_options.site).to eq(enterprise_site) | ||
end | ||
|
||
it "for authorize url" do | ||
enterprise.options.client_options.authorize_url.should eq(enterprise_authorize_url) | ||
expect(enterprise.options.client_options.authorize_url).to eq(enterprise_authorize_url) | ||
end | ||
|
||
it "for token url" do | ||
enterprise.options.client_options.token_url.should eq(enterprise_token_url) | ||
expect(enterprise.options.client_options.token_url).to eq(enterprise_token_url) | ||
end | ||
end | ||
end | ||
|
||
context "#email_access_allowed?" do | ||
it "should not allow email if scope is nil" do | ||
subject.options['scope'].should be_nil | ||
subject.should_not be_email_access_allowed | ||
expect(subject.options['scope']).to be_nil | ||
expect(subject).not_to be_email_access_allowed | ||
end | ||
|
||
it "should allow email if scope is user" do | ||
subject.options['scope'] = 'user' | ||
subject.should be_email_access_allowed | ||
expect(subject).to be_email_access_allowed | ||
end | ||
|
||
it "should allow email if scope is a bunch of stuff including user" do | ||
subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist' | ||
subject.should be_email_access_allowed | ||
expect(subject).to be_email_access_allowed | ||
end | ||
|
||
it "should not allow email if scope does not grant email access" do | ||
subject.options['scope'] = 'repo,user:follow' | ||
subject.should_not be_email_access_allowed | ||
expect(subject).not_to be_email_access_allowed | ||
end | ||
|
||
it "should assume email access not allowed if scope is something currently not documented " do | ||
subject.options['scope'] = 'currently_not_documented' | ||
subject.should_not be_email_access_allowed | ||
expect(subject).not_to be_email_access_allowed | ||
end | ||
end | ||
|
||
context "#email" do | ||
it "should return email from raw_info if available" do | ||
subject.stub!(:raw_info).and_return({'email' => '[email protected]'}) | ||
subject.email.should eq('[email protected]') | ||
allow(subject).to receive(:raw_info).and_return({'email' => '[email protected]'}) | ||
expect(subject.email).to eq('[email protected]') | ||
end | ||
|
||
it "should return nil if there is no raw_info and email access is not allowed" do | ||
subject.stub!(:raw_info).and_return({}) | ||
subject.email.should be_nil | ||
allow(subject).to receive(:raw_info).and_return({}) | ||
expect(subject.email).to be_nil | ||
end | ||
|
||
it "should not return the primary email if there is no raw_info and email access is allowed" do | ||
emails = [ | ||
{ 'email' => '[email protected]', 'primary' => false }, | ||
{ 'email' => '[email protected]', 'primary' => true } | ||
] | ||
subject.stub!(:raw_info).and_return({}) | ||
allow(subject).to receive(:raw_info).and_return({}) | ||
subject.options['scope'] = 'user' | ||
subject.stub!(:emails).and_return(emails) | ||
subject.email.should eq(nil) | ||
allow(subject).to receive(:emails).and_return(emails) | ||
expect(subject.email).to eq(nil) | ||
end | ||
|
||
it "should not return the first email if there is no raw_info and email access is allowed" do | ||
emails = [ | ||
{ 'email' => '[email protected]', 'primary' => false }, | ||
{ 'email' => '[email protected]', 'primary' => false } | ||
] | ||
subject.stub!(:raw_info).and_return({}) | ||
allow(subject).to receive(:raw_info).and_return({}) | ||
subject.options['scope'] = 'user' | ||
subject.stub!(:emails).and_return(emails) | ||
subject.email.should eq(nil) | ||
allow(subject).to receive(:emails).and_return(emails) | ||
expect(subject.email).to eq(nil) | ||
end | ||
end | ||
|
||
context "#raw_info" do | ||
it "should use relative paths" do | ||
access_token.should_receive(:get).with('user').and_return(response) | ||
subject.raw_info.should eq(parsed_response) | ||
expect(access_token).to receive(:get).with('user').and_return(response) | ||
expect(subject.raw_info).to eq(parsed_response) | ||
end | ||
end | ||
|
||
context "#emails" do | ||
it "should use relative paths" do | ||
access_token.should_receive(:get).with('user/emails', :headers=>{"Accept"=>"application/vnd.github.v3"}).and_return(response) | ||
expect(access_token).to receive(:get).with('user/emails', :headers=>{"Accept"=>"application/vnd.github.v3"}).and_return(response) | ||
subject.options['scope'] = 'user' | ||
subject.emails.should eq(parsed_response) | ||
expect(subject.emails).to eq(parsed_response) | ||
end | ||
end | ||
|
||
context '#info.urls' do | ||
it 'should use html_url from raw_info' do | ||
subject.stub(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' }) | ||
subject.info['urls']['GitHub'].should == 'http://enterprise/me' | ||
allow(subject).to receive(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' }) | ||
expect(subject.info['urls']['GitHub']).to eq('http://enterprise/me') | ||
end | ||
end | ||
|
||
|