Skip to content

Commit e338317

Browse files
committed
Fix basic auth extraction.
1 parent bc40350 commit e338317

2 files changed

Lines changed: 21 additions & 27 deletions

File tree

lib/github_api/api.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ def initialize(options={}, &block)
5050
Github.configuration.property_names.each do |key|
5151
send("#{key}=", opts[key])
5252
end
53-
54-
if opts.key?(:login)
53+
if opts.key?(:login) && !opts[:login].nil?
5554
@login, @password = opts[:login], opts[:password]
56-
elsif opts.key?(:basic_auth)
55+
elsif opts.key?(:basic_auth) && !opts[:basic_auth].nil?
5756
@login, @password = extract_basic_auth(opts[:basic_auth])
5857
end
5958

spec/github/api_spec.rb

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,33 @@
22

33
require 'spec_helper'
44

5-
describe Github::API do
6-
subject { described_class.new(options) }
7-
8-
it { described_class.included_modules.should include Github::Authorization }
9-
it { described_class.included_modules.should include Github::MimeType }
10-
it { described_class.included_modules.should include Github::Request::Verbs }
11-
12-
context 'actions' do
13-
let(:options) { { } }
14-
let(:repos) { Github::Client::Repos }
15-
16-
it { should respond_to :api_methods_in }
17-
5+
RSpec.describe Github::API do
6+
context '#actions' do
187
it 'dynamically adds actions inspection to classes inheriting from api' do
19-
repos.should respond_to :actions
20-
repos.new.should respond_to :actions
8+
repos = Github::Client::Repos
9+
expect(repos).to respond_to(:actions)
10+
expect(repos.new).to respond_to(:actions)
2111
end
2212

2313
it 'ensures output contains api methods' do
24-
methods = [ 'method_a', 'method_b']
25-
repos.stub(:instance_methods).and_return methods
26-
expect(subject.api_methods_in(repos)).to eq(['method_a', 'method_b'])
14+
repos = Github::Client::Repos
15+
methods = [:method_a, :method_b]
16+
allow(repos).to receive(:instance_methods).and_return(methods)
17+
expect(repos.new.api_methods_in(repos)).to eq([:method_a, :method_b])
2718
end
2819
end
2920

30-
context 'process_basic_auth' do
31-
let(:options) { { :basic_auth => 'login:password' } }
21+
context '#extract_basic_auth' do
22+
let(:options) { { basic_auth: 'piotr:secret' } }
3223

33-
its(:login) { should eq 'login' }
34-
35-
its(:password) { should eq 'password' }
24+
it "extracts login from :basic_auth param" do
25+
api = Github::API.new(options)
26+
expect(api.login).to eq('piotr')
27+
end
3628

37-
its(:basic_auth) { should eq 'login:password' }
29+
it "extracts password from :basic_auth param" do
30+
api = Github::API.new(options)
31+
expect(api.password).to eq('secret')
32+
end
3833
end
3934
end # Github::API

0 commit comments

Comments
 (0)