Skip to content

Commit fe06458

Browse files
committed
Full test coverage for authorization module.
1 parent 0942064 commit fe06458

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

spec/github/authorization_spec.rb

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,43 @@
2323
github.client.token_url.should == 'https://github.com/login/oauth/access_token'
2424
end
2525

26+
context '.client' do
27+
it { github.should respond_to :client }
28+
29+
it "should return OAuth2::Client instance" do
30+
github.client.should be_a OAuth2::Client
31+
end
32+
end
33+
34+
context '.auth_code' do
35+
let(:oauth) { OAuth2::Client.new(client_id, client_secret) }
36+
37+
before do
38+
github = Github.new :client_id => client_id, :client_secret => client_secret
39+
end
40+
41+
after do
42+
github.client_id, github.client_secret = nil, nil
43+
end
44+
45+
it "should throw an error if no client_id" do
46+
github.client_id = nil
47+
expect { github.auth_code }.should raise_error(ArgumentError)
48+
end
49+
50+
it "should throw an error if no client_secret" do
51+
github.client_secret = nil
52+
expect { github.auth_code }.should raise_error(ArgumentError)
53+
end
54+
55+
it "should return authentication token code" do
56+
github.client_id = client_id
57+
github.client_secret = client_secret
58+
github.client.stub(:auth_code).and_return code
59+
github.auth_code.should == code
60+
end
61+
end
62+
2663
context "authorize_url" do
2764
before do
2865
github = Github.new :client_id => client_id, :client_secret => client_secret
@@ -68,11 +105,51 @@
68105
end
69106
end
70107

108+
context ".authenticated?" do
109+
it { github.should respond_to :authenticated? }
110+
111+
it "should return false if falied on basic authentication" do
112+
github.stub(:basic_authed?).and_return false
113+
github.authenticated?.should be_false
114+
end
115+
116+
it "should return true if basic authentication performed" do
117+
github.stub(:basic_authed?).and_return true
118+
github.authenticated?.should be_true
119+
end
120+
121+
it "should return true if basic authentication performed" do
122+
github.stub(:oauth_token?).and_return true
123+
github.authenticated?.should be_true
124+
end
125+
end
126+
127+
context ".basic_authed?" do
128+
it { github.should respond_to :basic_authed? }
129+
130+
it "should return false if login is missing" do
131+
github.stub(:login?).and_return false
132+
github.basic_authed?.should be_false
133+
end
134+
135+
it "should return true if login && password provided" do
136+
github.stub(:login?).and_return true
137+
github.stub(:password?).and_return true
138+
github.basic_authed?.should be_true
139+
end
140+
end
141+
71142
context "authentication" do
72143
it "should respond to 'authentication'" do
73144
github.should respond_to :authentication
74145
end
75146

147+
it "should return empty hash if no basic authentication params available" do
148+
github.stub(:login?).and_return false
149+
github.stub(:basic_auth?).and_return false
150+
github.authentication.should be_empty
151+
end
152+
76153
context 'basic_auth' do
77154
before do
78155
github = Github.new :basic_auth => 'github:pass'

0 commit comments

Comments
 (0)