Skip to content

Commit dd3ea6f

Browse files
committed
Merge pull request #60 from cltweedie/improving_coverage
Improving coverage
2 parents 0148c64 + 69612b2 commit dd3ea6f

24 files changed

+260
-112
lines changed

bitbucket_rest_api.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ Gem::Specification.new do |gem|
2323
gem.add_dependency 'simple_oauth'
2424

2525
gem.add_development_dependency 'rspec', '>= 0'
26+
gem.add_development_dependency 'rack-test'
2627
gem.add_development_dependency 'webmock', '~> 1.8.0'
2728
gem.add_development_dependency 'vcr', '~> 2.2.0'
2829
gem.add_development_dependency 'simplecov', '~> 0.6.1'
2930
gem.add_development_dependency 'rake'
3031
gem.add_development_dependency 'bundler'
31-
gem.add_development_dependency 'pry-debugger'
32+
gem.add_development_dependency 'pry-byebug'
3233
gem.add_development_dependency 'mocha'
3334
end

lib/bitbucket_rest_api/api.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'bitbucket_rest_api/request'
77
require 'bitbucket_rest_api/core_ext/hash'
88
require 'bitbucket_rest_api/core_ext/array'
9-
require 'bitbucket_rest_api/compatibility'
109
require 'bitbucket_rest_api/api/actions'
1110
require 'bitbucket_rest_api/api_factory'
1211

lib/bitbucket_rest_api/api/actions.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,5 @@ def api_methods_in(klass)
3131
methods
3232
end
3333

34-
def append_arguments(method)
35-
_method = self.method(method)
36-
if _method.arity == 0
37-
args = "()"
38-
elsif _method.arity > 0
39-
args = "(few)"
40-
else
41-
args = "(else)"
42-
end
43-
args
44-
end
45-
4634
end # API
4735
end # BitBucket

lib/bitbucket_rest_api/client.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def issues(options = {})
1616

1717
# An API for users to manage their own tokens.
1818
def oauth(options = {})
19-
raise "Unimpletmented"
20-
#@oauth ||= ApiFactory.new 'Authorizations', options
19+
@oauth ||= ApiFactory.new 'Request::OAuth', options
2120
end
2221
alias :authorizations :oauth
2322

@@ -27,8 +26,7 @@ def teams(options = {})
2726
end
2827

2928
def pull_requests(options = {})
30-
raise "Unimplemented"
31-
#@pull_requests ||= ApiFactory.new 'PullRequests', options
29+
@pull_requests ||= ApiFactory.new 'Repos::PullRequest', options
3230
end
3331

3432
def repos(options = {})

lib/bitbucket_rest_api/compatibility.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/bitbucket_rest_api/repos.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ def services
6969
@services ||= ApiFactory.new 'Repos::Services'
7070
end
7171
def forks
72-
@services ||= ApiFactory.new 'Repos::Forks'
72+
@forks ||= ApiFactory.new 'Repos::Forks'
7373
end
7474
def commits
75-
@services ||=ApiFactory.new 'Repos::Commits'
75+
@commits ||=ApiFactory.new 'Repos::Commits'
7676
end
7777
def download
78-
@services ||=ApiFactory.new "Repos::Download"
78+
@download ||=ApiFactory.new "Repos::Download"
7979
end
8080

8181
# Access to Repos::PullRequests API

lib/bitbucket_rest_api/repos/download.rb

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

33
module BitBucket
44
class Repos::Download < API
5-
REQUIRED_KEY_PARAM_NAMES = %w[ commit_hash ].freeze
6-
def get(user_name, repo_name, params={})
7-
_update_user_repo_params(user_name, repo_name)
8-
_validate_user_repo_params(user, repo) unless user? && repo?
9-
# normalize! params
10-
# assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params)
11-
12-
#https://bitbucket.org/jhanley85/eternum_canvas_demo/get/fd931f96f12d.zip
13-
"https://bitbucket.org/#{user}/#{repo.downcase}/get/#{params[:commit_hash]}.tar.gz"
5+
REQUIRED_KEY_PARAM_NAMES = %w[ commit_hash ].freeze
6+
def get(user_name, repo_name, params={})
7+
_update_user_repo_params(user_name, repo_name)
8+
_validate_user_repo_params(user, repo) unless user? && repo?
9+
# normalize! params
10+
# assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params)
11+
12+
#https://bitbucket.org/jhanley85/eternum_canvas_demo/get/fd931f96f12d.zip
13+
"https://bitbucket.org/#{user}/#{repo.downcase}/get/#{params[:commit_hash]}.tar.gz"
1414
end
15-
16-
17-
15+
16+
17+
1818

1919

2020
end # Repos::Keys

lib/bitbucket_rest_api/request/oauth.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ class OAuth < Faraday::Middleware
1313

1414
def call(env)
1515
# Extract parameters from the query
16+
request = Rack::Request.new env
17+
env[:url] = URI.parse(request.url) if env[:url].nil?
1618
params = { }.update query_params(env[:url])
1719

1820
if (@token and @secret) and (!@token.empty? and !@secret.empty?)
1921
access_token = ::OAuth::AccessToken.new(@consumer, @token, @secret)
2022
env[:url].query = build_query params
21-
23+
2224
puts oauth_helper.header
2325
puts oauth_helper.header.class
2426
env[:request_headers].merge!(AUTH_HEADER => oauth_helper.header)
2527
end
26-
28+
2729
env[:url].query = build_query params
2830

2931

spec/bitbucket_rest_api/authorization_spec.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
describe BitBucket::Authorization do
44
let(:oauth_api) { BitBucket::API.new(oauth_token: 'example_oauth_token') }
55
let(:basic_auth_api) { BitBucket::API.new(basic_auth: 'example_login:example_password') }
6+
let(:basic_auth_api_hash) do
7+
BitBucket::API.new(
8+
basic_auth: { login: 'example_login', password: 'example_password' })
9+
end
610
let(:login_and_password_api) do
711
BitBucket::API.new(
812
login: 'example_login',
@@ -12,43 +16,52 @@
1216
end
1317

1418
describe '#authenticated?' do
15-
context 'context: oauth authentication' do
16-
it 'should return true of oauth is used' do
19+
context 'oauth authentication' do
20+
it 'should return true if oauth is used' do
1721
expect(oauth_api.authenticated?).to eq(true)
1822
end
1923
end
2024

21-
context 'context: basic authentication' do
25+
context 'basic authentication' do
2226
it 'should return true if basic authentication is used' do
2327
expect(basic_auth_api.authenticated?).to eq(true)
2428
end
2529
end
2630
end
2731

2832
describe '#basic_authed?' do
29-
context 'context: with basic_auth' do
33+
context 'with basic_auth' do
3034
it 'should return true if basic_auth is set' do
3135
expect(basic_auth_api.basic_authed?).to eq(true)
36+
expect(basic_auth_api_hash.basic_authed?).to eq(true)
3237
end
3338
end
3439

35-
context 'context: with login and password' do
40+
context 'with login and password' do
3641
it 'should return true if a login and password are set' do
3742
expect(login_and_password_api.basic_authed?).to eq(true)
3843
end
3944
end
4045
end
4146

4247
describe '#authentication' do
43-
context 'context: with basic_auth' do
48+
context 'with basic_auth as a string' do
4449
it 'should return a hash containing the value for :basic_auth' do
4550
expectation = { basic_auth: 'example_login:example_password' }
4651

4752
expect(basic_auth_api.authentication).to eq(expectation)
4853
end
4954
end
5055

51-
context 'context: with login and password' do
56+
context 'with basic_auth as a hash' do
57+
it 'should return a hash containing the value for :basic_auth' do
58+
expectation = { basic_auth: { login: 'example_login', password: 'example_password'} }
59+
60+
expect(basic_auth_api_hash.authentication).to eq(expectation)
61+
end
62+
end
63+
64+
context 'with login and password' do
5265
it 'should return a hash containing values for :login and :password' do
5366
expectation = { login: 'example_login', password: 'example_password' }
5467

spec/bitbucket_rest_api/client_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
expect(client.users).to be_a BitBucket::Users
1010
expect(client.user_api).to be_a BitBucket::User
1111
expect(client.invitations).to be_a BitBucket::Invitations
12+
expect(client.pull_requests).to be_a BitBucket::Repos::PullRequest
13+
expect(client.oauth).to be_a BitBucket::Request::OAuth
1214
end
1315
end

0 commit comments

Comments
 (0)