bitbuckets 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +7 -0
- data/README.md +169 -0
- data/Rakefile +1 -0
- data/lib/bitbucket_rest_api.rb +86 -0
- data/lib/bitbucket_rest_api/api.rb +104 -0
- data/lib/bitbucket_rest_api/api/actions.rb +32 -0
- data/lib/bitbucket_rest_api/api_factory.rb +29 -0
- data/lib/bitbucket_rest_api/authorization.rb +31 -0
- data/lib/bitbucket_rest_api/client.rb +53 -0
- data/lib/bitbucket_rest_api/configuration.rb +103 -0
- data/lib/bitbucket_rest_api/connection.rb +97 -0
- data/lib/bitbucket_rest_api/constants.rb +57 -0
- data/lib/bitbucket_rest_api/core_ext/array.rb +6 -0
- data/lib/bitbucket_rest_api/core_ext/hash.rb +58 -0
- data/lib/bitbucket_rest_api/deprecation.rb +36 -0
- data/lib/bitbucket_rest_api/error.rb +37 -0
- data/lib/bitbucket_rest_api/error/bad_events.rb +10 -0
- data/lib/bitbucket_rest_api/error/bad_request.rb +11 -0
- data/lib/bitbucket_rest_api/error/blank_value.rb +10 -0
- data/lib/bitbucket_rest_api/error/client_error.rb +19 -0
- data/lib/bitbucket_rest_api/error/forbidden.rb +11 -0
- data/lib/bitbucket_rest_api/error/internal_server_error.rb +11 -0
- data/lib/bitbucket_rest_api/error/invalid_options.rb +17 -0
- data/lib/bitbucket_rest_api/error/no_events.rb +10 -0
- data/lib/bitbucket_rest_api/error/not_found.rb +11 -0
- data/lib/bitbucket_rest_api/error/required_params.rb +17 -0
- data/lib/bitbucket_rest_api/error/service_error.rb +18 -0
- data/lib/bitbucket_rest_api/error/service_unavailable.rb +11 -0
- data/lib/bitbucket_rest_api/error/unauthorized.rb +11 -0
- data/lib/bitbucket_rest_api/error/unknown_value.rb +17 -0
- data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +11 -0
- data/lib/bitbucket_rest_api/error/validations.rb +17 -0
- data/lib/bitbucket_rest_api/invitations.rb +14 -0
- data/lib/bitbucket_rest_api/issues.rb +229 -0
- data/lib/bitbucket_rest_api/issues/comments.rb +116 -0
- data/lib/bitbucket_rest_api/issues/components.rb +105 -0
- data/lib/bitbucket_rest_api/issues/milestones.rb +105 -0
- data/lib/bitbucket_rest_api/normalizer.rb +24 -0
- data/lib/bitbucket_rest_api/parameter_filter.rb +29 -0
- data/lib/bitbucket_rest_api/repos.rb +276 -0
- data/lib/bitbucket_rest_api/repos/changesets.rb +52 -0
- data/lib/bitbucket_rest_api/repos/commits.rb +38 -0
- data/lib/bitbucket_rest_api/repos/components.rb +35 -0
- data/lib/bitbucket_rest_api/repos/default_reviewers.rb +60 -0
- data/lib/bitbucket_rest_api/repos/download.rb +15 -0
- data/lib/bitbucket_rest_api/repos/following.rb +38 -0
- data/lib/bitbucket_rest_api/repos/forks.rb +66 -0
- data/lib/bitbucket_rest_api/repos/keys.rb +86 -0
- data/lib/bitbucket_rest_api/repos/pull_request.rb +158 -0
- data/lib/bitbucket_rest_api/repos/services.rb +101 -0
- data/lib/bitbucket_rest_api/repos/sources.rb +36 -0
- data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
- data/lib/bitbucket_rest_api/request.rb +71 -0
- data/lib/bitbucket_rest_api/request/basic_auth.rb +30 -0
- data/lib/bitbucket_rest_api/request/jsonize.rb +39 -0
- data/lib/bitbucket_rest_api/request/oauth.rb +50 -0
- data/lib/bitbucket_rest_api/response.rb +26 -0
- data/lib/bitbucket_rest_api/response/helpers.rb +18 -0
- data/lib/bitbucket_rest_api/response/jsonize.rb +25 -0
- data/lib/bitbucket_rest_api/response/mashify.rb +23 -0
- data/lib/bitbucket_rest_api/response/raise_error.rb +28 -0
- data/lib/bitbucket_rest_api/response/xmlize.rb +25 -0
- data/lib/bitbucket_rest_api/result.rb +136 -0
- data/lib/bitbucket_rest_api/teams.rb +91 -0
- data/lib/bitbucket_rest_api/user.rb +87 -0
- data/lib/bitbucket_rest_api/users.rb +20 -0
- data/lib/bitbucket_rest_api/users/account.rb +50 -0
- data/lib/bitbucket_rest_api/utils/url.rb +61 -0
- data/lib/bitbucket_rest_api/validations.rb +23 -0
- data/lib/bitbucket_rest_api/validations/format.rb +21 -0
- data/lib/bitbucket_rest_api/validations/presence.rb +21 -0
- data/lib/bitbucket_rest_api/validations/required.rb +37 -0
- data/lib/bitbucket_rest_api/validations/token.rb +38 -0
- data/lib/bitbucket_rest_api/version.rb +10 -0
- data/lib/bitbuckets.rb +2 -0
- data/spec/bitbucket_rest_api/api/actions_spec.rb +18 -0
- data/spec/bitbucket_rest_api/api_factory_spec.rb +28 -0
- data/spec/bitbucket_rest_api/api_spec.rb +87 -0
- data/spec/bitbucket_rest_api/authorization_spec.rb +74 -0
- data/spec/bitbucket_rest_api/client_spec.rb +17 -0
- data/spec/bitbucket_rest_api/core_ext/array_spec.rb +13 -0
- data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +47 -0
- data/spec/bitbucket_rest_api/deprecation_spec.rb +31 -0
- data/spec/bitbucket_rest_api/error/bad_events_spec.rb +11 -0
- data/spec/bitbucket_rest_api/error/blank_value_spec.rb +14 -0
- data/spec/bitbucket_rest_api/error/no_events_spec.rb +11 -0
- data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
- data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues/components_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues/milestones_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues_spec.rb +91 -0
- data/spec/bitbucket_rest_api/normalizer_spec.rb +29 -0
- data/spec/bitbucket_rest_api/parameter_filter_spec.rb +42 -0
- data/spec/bitbucket_rest_api/repos/changesets_spec.rb +44 -0
- data/spec/bitbucket_rest_api/repos/commits_spec.rb +21 -0
- data/spec/bitbucket_rest_api/repos/components_spec.rb +43 -0
- data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +65 -0
- data/spec/bitbucket_rest_api/repos/download_spec.rb +10 -0
- data/spec/bitbucket_rest_api/repos/following_spec.rb +53 -0
- data/spec/bitbucket_rest_api/repos/forks_spec.rb +46 -0
- data/spec/bitbucket_rest_api/repos/keys_spec.rb +73 -0
- data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +283 -0
- data/spec/bitbucket_rest_api/repos/sources_spec.rb +78 -0
- data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
- data/spec/bitbucket_rest_api/repos_spec.rb +158 -0
- data/spec/bitbucket_rest_api/request/jsonize_spec.rb +19 -0
- data/spec/bitbucket_rest_api/request/oauth_spec.rb +26 -0
- data/spec/bitbucket_rest_api/request_spec.rb +88 -0
- data/spec/bitbucket_rest_api/response/jsonize_spec.rb +13 -0
- data/spec/bitbucket_rest_api/response/mashify_spec.rb +33 -0
- data/spec/bitbucket_rest_api/response/raise_error_spec.rb +42 -0
- data/spec/bitbucket_rest_api/teams_spec.rb +136 -0
- data/spec/bitbucket_rest_api/user_spec.rb +78 -0
- data/spec/bitbucket_rest_api/utils/url_spec.rb +34 -0
- data/spec/bitbucket_rest_api/validations/format_spec.rb +30 -0
- data/spec/bitbucket_rest_api/validations/presence_spec.rb +13 -0
- data/spec/bitbucket_rest_api/validations/required_spec.rb +44 -0
- data/spec/bitbucket_rest_api/validations/token_spec.rb +17 -0
- data/spec/bitbucket_rest_api_spec.rb +17 -0
- data/spec/spec_helper.rb +24 -0
- metadata +358 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
describe BitBucket::Issues do
|
6
|
+
let(:issue) { BitBucket::Issues.new }
|
7
|
+
|
8
|
+
describe '.create' do
|
9
|
+
before do
|
10
|
+
expect(issue).to receive(:request).with(
|
11
|
+
:post,
|
12
|
+
'/1.0/repositories/mock_username/mock_repo/issues/',
|
13
|
+
{ 'title' => 'mock_issue' },
|
14
|
+
{}
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should send a POST request to create the issue' do
|
19
|
+
issue.create('mock_username', 'mock_repo', 'title' => 'mock_issue')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.edit' do
|
24
|
+
before do
|
25
|
+
expect(issue).to receive(:request).with(
|
26
|
+
:put,
|
27
|
+
'/1.0/repositories/mock_username/mock_repo/issues/1/',
|
28
|
+
{ 'title' => 'new_title' },
|
29
|
+
{}
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should send a PUT request for the given issue' do
|
34
|
+
issue.edit('mock_username', 'mock_repo', 1, 'title' => 'new_title')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.get' do
|
39
|
+
before do
|
40
|
+
expect(issue).to receive(:request).with(
|
41
|
+
:get,
|
42
|
+
'/1.0/repositories/mock_username/mock_repo/issues/1',
|
43
|
+
{},
|
44
|
+
{}
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should send a GET request for the given issue' do
|
49
|
+
issue.get('mock_username', 'mock_repo', 1, {})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.delete' do
|
54
|
+
before do
|
55
|
+
expect(issue).to receive(:request).with(
|
56
|
+
:delete,
|
57
|
+
'/1.0/repositories/mock_username/mock_repo/issues/1',
|
58
|
+
{},
|
59
|
+
{}
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should send a DELETE request for the given issue' do
|
64
|
+
issue.delete('mock_username', 'mock_repo', 1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '.list_repo' do
|
69
|
+
before do
|
70
|
+
expect(issue).to receive(:request).with(
|
71
|
+
:get,
|
72
|
+
'/1.0/repositories/mock_username/mock_repo/issues',
|
73
|
+
{},
|
74
|
+
{}
|
75
|
+
).and_return(OpenStruct.new(issues: [])).twice
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should send a GET request for the issues for that repo' do
|
79
|
+
issue.list_repo('mock_username', 'mock_repo')
|
80
|
+
issue.list_repo('mock_username', 'mock_repo') { |issue| issue }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'getter methods' do
|
85
|
+
it 'returns an object of the correct class' do
|
86
|
+
expect(issue.comments).to be_a BitBucket::Issues::Comments
|
87
|
+
expect(issue.components).to be_a BitBucket::Issues::Components
|
88
|
+
expect(issue.milestones).to be_a BitBucket::Issues::Milestones
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'bitbucket_rest_api/core_ext/hash'
|
4
|
+
|
5
|
+
describe BitBucket::Normalizer, '#normalize!' do
|
6
|
+
let(:hash) { { 'a' => { :b => { 'c' => 1 }, 'd' => ['a', { e: 2 }] } } }
|
7
|
+
|
8
|
+
let(:klass) do
|
9
|
+
Class.new do
|
10
|
+
include BitBucket::Normalizer
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject(:instance) { klass.new }
|
15
|
+
|
16
|
+
context '#normalize!' do
|
17
|
+
it 'converts hash keys to string' do
|
18
|
+
%w[a b c].each do |key|
|
19
|
+
expect(subject.normalize!(hash).has_deep_key?(key)).to eq(true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should stringify all the keys inside nested hash' do
|
24
|
+
actual = subject.normalize! hash
|
25
|
+
expected = { 'a' => { 'b' => { 'c' => 1 }, 'd' => ['a', { 'e' => 2 }] } }
|
26
|
+
expect(actual).to eq expected
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end # BitBucket::Normalizer
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'bitbucket_rest_api/core_ext/hash'
|
4
|
+
|
5
|
+
describe BitBucket::ParameterFilter, '#filter!' do
|
6
|
+
let(:hash) { { a: { b: { c: 1 } } } }
|
7
|
+
let(:array) { [{ a: { b: { c: 1 } } }, { d: { e: 2 } }] }
|
8
|
+
|
9
|
+
let(:klass) do
|
10
|
+
Class.new do
|
11
|
+
include BitBucket::ParameterFilter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
subject(:instance) { klass.new }
|
16
|
+
|
17
|
+
it 'removes unwanted keys from hash' do
|
18
|
+
instance.filter!([:a], hash)
|
19
|
+
expect(hash.has_deep_key?(:a)).to eq(true)
|
20
|
+
expect(hash.has_deep_key?(:b)).to eq(false)
|
21
|
+
expect(hash.has_deep_key?(:c)).to eq(false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'removes unwanted keys from array of hashes' do
|
25
|
+
instance.filter!(%i[a d], array)
|
26
|
+
expect(array[0].has_deep_key?(:a)).to eq(true)
|
27
|
+
expect(array[0].has_deep_key?(:b)).to eq(false)
|
28
|
+
expect(array[0].has_deep_key?(:c)).to eq(false)
|
29
|
+
expect(array[1].has_deep_key?(:d)).to eq(true)
|
30
|
+
expect(array[1].has_deep_key?(:e)).to eq(false)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'recursively filters inputs tree' do
|
34
|
+
instance.filter!(%i[a b], hash)
|
35
|
+
expect(hash.has_deep_key?(:c)).to eq(false)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'filters inputs tree only on top level' do
|
39
|
+
instance.filter!(%i[a b], hash, recursive: false)
|
40
|
+
expect(hash.has_deep_key?(:c)).to eq(true)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BitBucket::Repos::Changesets do
|
5
|
+
let(:changesets) { BitBucket::Repos::Changesets.new }
|
6
|
+
|
7
|
+
describe '.list' do
|
8
|
+
before do
|
9
|
+
expect(changesets).to receive(:request).with(
|
10
|
+
:get,
|
11
|
+
'/1.0/repositories/mock_username/mock_repo/changesets',
|
12
|
+
{},
|
13
|
+
{}
|
14
|
+
).and_return(%w[changset1 changeset2 changeset3])
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'without a block' do
|
18
|
+
it 'should send a GET request for the changesets belonging to the given repo' do
|
19
|
+
changesets.list('mock_username', 'mock_repo')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with a block' do
|
24
|
+
it 'should send a GET request for the changesets belonging to the given repo' do
|
25
|
+
changesets.list('mock_username', 'mock_repo') { |changeset| changeset }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.get' do
|
31
|
+
before do
|
32
|
+
expect(changesets).to receive(:request).with(
|
33
|
+
:get,
|
34
|
+
'/1.0/repositories/mock_username/mock_repo/changesets/test_sha',
|
35
|
+
{},
|
36
|
+
{}
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should send a GET request for a particular changeset belonging to the given repo' do
|
41
|
+
changesets.get('mock_username', 'mock_repo', 'test_sha')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BitBucket::Repos::Commits do
|
5
|
+
let(:commits) { BitBucket::Repos::Commits.new }
|
6
|
+
|
7
|
+
describe '.list' do
|
8
|
+
before do
|
9
|
+
expect(commits).to receive(:request).with(
|
10
|
+
:get,
|
11
|
+
'/2.0/repositories/mock_username/mock_repo/commits',
|
12
|
+
{},
|
13
|
+
{}
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should send a GET request for the commits belonging to the given repo' do
|
18
|
+
commits.list('mock_username', 'mock_repo')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BitBucket::Repos::Components do
|
5
|
+
subject { described_class.new }
|
6
|
+
describe '#list' do
|
7
|
+
before do
|
8
|
+
expect(subject).to receive(:request).with(
|
9
|
+
:get,
|
10
|
+
'/2.0/repositories/mock_user/mock_repo/components',
|
11
|
+
{},
|
12
|
+
{}
|
13
|
+
).and_return('values' => %w[component1 component2 component3])
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'without a block' do
|
17
|
+
it 'makes a GET request for all components defined in the issue tracker' do
|
18
|
+
subject.list('mock_user', 'mock_repo')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a block' do
|
23
|
+
it 'makes a GET request for all components defined in the issue tracker' do
|
24
|
+
subject.list('mock_user', 'mock_repo') { |component| component }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#get' do
|
30
|
+
before do
|
31
|
+
expect(subject).to receive(:request).with(
|
32
|
+
:get,
|
33
|
+
'/2.0/repositories/mock_user/mock_repo/components/1',
|
34
|
+
{},
|
35
|
+
{}
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'makes a GET request for all components defined in the issue tracker' do
|
40
|
+
subject.get('mock_user', 'mock_repo', 1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BitBucket::Repos::DefaultReviewers do
|
5
|
+
subject { described_class.new }
|
6
|
+
describe '#list' do
|
7
|
+
before do
|
8
|
+
expect(subject).to receive(:request).with(
|
9
|
+
:get,
|
10
|
+
'/2.0/repositories/mock_user/mock_repo/default-reviewers',
|
11
|
+
{},
|
12
|
+
{}
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'makes a GET request for all default reviewers belonging to the repo' do
|
17
|
+
subject.list('mock_user', 'mock_repo')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#get' do
|
22
|
+
before do
|
23
|
+
expect(subject).to receive(:request).with(
|
24
|
+
:get,
|
25
|
+
'/2.0/repositories/mock_user/mock_repo/default-reviewers/mock_reviewer',
|
26
|
+
{},
|
27
|
+
{}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'makes a GET request for a default reviewer by username' do
|
32
|
+
subject.get('mock_user', 'mock_repo', 'mock_reviewer')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#add' do
|
37
|
+
before do
|
38
|
+
expect(subject).to receive(:request).with(
|
39
|
+
:put,
|
40
|
+
'/2.0/repositories/mock_user/mock_repo/default-reviewers/mock_reviewer',
|
41
|
+
{},
|
42
|
+
{}
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'makes a PUT request to add the new reviewer to the default reviewers list' do
|
47
|
+
subject.add('mock_user', 'mock_repo', 'mock_reviewer')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#remove' do
|
52
|
+
before do
|
53
|
+
expect(subject).to receive(:request).with(
|
54
|
+
:delete,
|
55
|
+
'/2.0/repositories/mock_user/mock_repo/default-reviewers/mock_reviewer',
|
56
|
+
{},
|
57
|
+
{}
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'makes a DELETE request to remove a reviewer from the list' do
|
62
|
+
subject.remove('mock_user', 'mock_repo', 'mock_reviewer')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BitBucket::Repos::Download do
|
5
|
+
describe '.get' do
|
6
|
+
it 'should send a GET request for the download link for the given repo' do
|
7
|
+
skip 'this is a regression test and the method is not finished being written'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BitBucket::Repos::Following do
|
5
|
+
let(:following) { BitBucket::Repos::Following.new }
|
6
|
+
|
7
|
+
describe '.followers' do
|
8
|
+
before do
|
9
|
+
expect(following).to receive(:request).with(
|
10
|
+
:get,
|
11
|
+
'/1.0/repositories/mock_username/mock_repo/followers/',
|
12
|
+
{},
|
13
|
+
{}
|
14
|
+
).and_return(%w[follower1 follower2 follower3])
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'without a block' do
|
18
|
+
it 'should send a GET request for the followers belonging to the given repo' do
|
19
|
+
following.followers('mock_username', 'mock_repo')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with a block' do
|
24
|
+
it 'should send a GET request for the followers belonging to the given repo' do
|
25
|
+
following.followers('mock_username', 'mock_repo') { |follower| follower }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: implement this method in the User class where it belongs
|
31
|
+
describe '.followed' do
|
32
|
+
before do
|
33
|
+
expect(following).to receive(:request).with(
|
34
|
+
:get,
|
35
|
+
'/1.0/user/follows',
|
36
|
+
{},
|
37
|
+
{}
|
38
|
+
).and_return(%w[followed1 followed2 followed3])
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'without a block' do
|
42
|
+
it 'should send a GET request for the followers belonging to a particular user' do
|
43
|
+
following.followed
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with a block' do
|
48
|
+
it 'should send a GET request for the followers belonging to a particular user' do
|
49
|
+
following.followed { |followed| followed }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BitBucket::Repos::Forks do
|
5
|
+
let(:forks) { BitBucket::Repos::Forks.new }
|
6
|
+
|
7
|
+
describe '.list' do
|
8
|
+
before do
|
9
|
+
expect(forks).to receive(:request).with(
|
10
|
+
:get,
|
11
|
+
'/2.0/repositories/mock_username/mock_repo/forks/',
|
12
|
+
{},
|
13
|
+
{}
|
14
|
+
).and_return(%w[fork1 fork2 fork3])
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'without a block' do
|
18
|
+
it 'sends a GET request for the forks of the given repo' do
|
19
|
+
forks.list('mock_username', 'mock_repo')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with a block' do
|
24
|
+
it 'sends a GET request for the forks of the given repo' do
|
25
|
+
forks.list('mock_username', 'mock_repo') { |fork| fork }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: make sure this is documented in the README since it is not so
|
31
|
+
# in the official API docs
|
32
|
+
describe '.create' do
|
33
|
+
before do
|
34
|
+
expect(forks).to receive(:request).with(
|
35
|
+
:post,
|
36
|
+
'/1.0/repositories/mock_username/mock_repo/fork',
|
37
|
+
{ 'name' => 'mock_fork_name' },
|
38
|
+
{}
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should send a POST request to create a fork of the given repo' do
|
43
|
+
forks.create('mock_username', 'mock_repo', 'name' => 'mock_fork_name')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|