Skip to content

Commit b911673

Browse files
committed
Fix oauth test dependencies leaks, call client directly.
1 parent 081c506 commit b911673

2 files changed

Lines changed: 22 additions & 31 deletions

File tree

lib/github_api/authorization.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def client
1717
# Strategy token
1818
def auth_code
1919
_verify_client
20-
@client.auth_code
20+
client.auth_code
2121
end
2222

2323
# Sends authorization request to GitHub.
@@ -33,13 +33,13 @@ def auth_code
3333
#
3434
def authorize_url(params = {})
3535
_verify_client
36-
@client.auth_code.authorize_url(params)
36+
client.auth_code.authorize_url(params)
3737
end
3838

3939
# Makes request to token endpoint and retrieves access token value
4040
def get_token(authorization_code, params = {})
4141
_verify_client
42-
@client.auth_code.get_token(authorization_code, params)
42+
client.auth_code.get_token(authorization_code, params)
4343
end
4444

4545
# Check whether authentication credentials are present

spec/github/authorization_spec.rb

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1+
# encoding: utf-8
2+
13
require 'spec_helper'
24

35
describe Github::Authorization do
4-
56
let(:client_id) { '234jl23j4l23j4l' }
67
let(:client_secret) { 'asasd79sdf9a7asfd7sfd97s' }
78
let(:code) { 'c9798sdf97df98ds'}
8-
let(:github) { Github.new }
9-
10-
it "should instantiate oauth2 instance" do
11-
github.client.should be_a OAuth2::Client
12-
end
13-
14-
it "should assign site from the options hash" do
15-
github.client.site.should == 'https://github.com'
16-
end
17-
18-
it "should assign 'authorize_url" do
19-
github.client.authorize_url.should == 'https://github.com/login/oauth/authorize'
20-
end
9+
let(:github) {
10+
Github.new :client_id => client_id, :client_secret => client_secret
11+
}
2112

22-
it "should assign 'token_url" do
23-
github.client.token_url.should == 'https://github.com/login/oauth/access_token'
13+
after do
14+
github.client_id, github.client_secret = nil, nil
15+
reset_authentication_for github
2416
end
2517

2618
context '.client' do
@@ -29,18 +21,22 @@
2921
it "should return OAuth2::Client instance" do
3022
github.client.should be_a OAuth2::Client
3123
end
32-
end
3324

34-
context '.auth_code' do
35-
let(:oauth) { OAuth2::Client.new(client_id, client_secret) }
25+
it "should assign site from the options hash" do
26+
github.client.site.should == 'https://github.com'
27+
end
3628

37-
before do
38-
github = Github.new :client_id => client_id, :client_secret => client_secret
29+
it "should assign 'authorize_url" do
30+
github.client.authorize_url.should == 'https://github.com/login/oauth/authorize'
3931
end
4032

41-
after do
42-
github.client_id, github.client_secret = nil, nil
33+
it "should assign 'token_url" do
34+
github.client.token_url.should == 'https://github.com/login/oauth/access_token'
4335
end
36+
end
37+
38+
context '.auth_code' do
39+
let(:oauth) { OAuth2::Client.new(client_id, client_secret) }
4440

4541
it "should throw an error if no client_id" do
4642
github.client_id = nil
@@ -61,10 +57,6 @@
6157
end
6258

6359
context "authorize_url" do
64-
before do
65-
github = Github.new :client_id => client_id, :client_secret => client_secret
66-
end
67-
6860
it "should respond to 'authorize_url' " do
6961
github.should respond_to :authorize_url
7062
end
@@ -84,7 +76,6 @@
8476

8577
context "get_token" do
8678
before do
87-
github = Github.new :client_id => client_id, :client_secret => client_secret
8879
stub_request(:post, 'https://github.com/login/oauth/access_token').
8980
to_return(:body => '', :status => 200, :headers => {})
9081
end

0 commit comments

Comments
 (0)