bitbucket_rest_api2 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/lib/bitbucket_rest_api.rb +90 -0
- data/lib/bitbucket_rest_api/api.rb +106 -0
- data/lib/bitbucket_rest_api/api/actions.rb +35 -0
- data/lib/bitbucket_rest_api/api_factory.rb +30 -0
- data/lib/bitbucket_rest_api/authorization.rb +34 -0
- data/lib/bitbucket_rest_api/client.rb +56 -0
- data/lib/bitbucket_rest_api/configuration.rb +106 -0
- data/lib/bitbucket_rest_api/connection.rb +98 -0
- data/lib/bitbucket_rest_api/constants.rb +58 -0
- data/lib/bitbucket_rest_api/core_ext/array.rb +7 -0
- data/lib/bitbucket_rest_api/core_ext/hash.rb +46 -0
- data/lib/bitbucket_rest_api/deprecation.rb +39 -0
- data/lib/bitbucket_rest_api/error.rb +38 -0
- data/lib/bitbucket_rest_api/error/bad_events.rb +9 -0
- data/lib/bitbucket_rest_api/error/bad_request.rb +12 -0
- data/lib/bitbucket_rest_api/error/blank_value.rb +9 -0
- data/lib/bitbucket_rest_api/error/client_error.rb +20 -0
- data/lib/bitbucket_rest_api/error/forbidden.rb +12 -0
- data/lib/bitbucket_rest_api/error/internal_server_error.rb +12 -0
- data/lib/bitbucket_rest_api/error/invalid_options.rb +18 -0
- data/lib/bitbucket_rest_api/error/no_events.rb +9 -0
- data/lib/bitbucket_rest_api/error/not_found.rb +12 -0
- data/lib/bitbucket_rest_api/error/required_params.rb +18 -0
- data/lib/bitbucket_rest_api/error/service_error.rb +19 -0
- data/lib/bitbucket_rest_api/error/service_unavailable.rb +12 -0
- data/lib/bitbucket_rest_api/error/unauthorized.rb +12 -0
- data/lib/bitbucket_rest_api/error/unknown_value.rb +18 -0
- data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +12 -0
- data/lib/bitbucket_rest_api/error/validations.rb +18 -0
- data/lib/bitbucket_rest_api/invitations.rb +15 -0
- data/lib/bitbucket_rest_api/issues.rb +230 -0
- data/lib/bitbucket_rest_api/issues/comments.rb +118 -0
- data/lib/bitbucket_rest_api/issues/components.rb +106 -0
- data/lib/bitbucket_rest_api/issues/milestones.rb +107 -0
- data/lib/bitbucket_rest_api/normalizer.rb +27 -0
- data/lib/bitbucket_rest_api/parameter_filter.rb +32 -0
- data/lib/bitbucket_rest_api/repos.rb +264 -0
- data/lib/bitbucket_rest_api/repos/changesets.rb +54 -0
- data/lib/bitbucket_rest_api/repos/commits.rb +40 -0
- data/lib/bitbucket_rest_api/repos/default_reviewers.rb +59 -0
- data/lib/bitbucket_rest_api/repos/download.rb +21 -0
- data/lib/bitbucket_rest_api/repos/following.rb +39 -0
- data/lib/bitbucket_rest_api/repos/forks.rb +69 -0
- data/lib/bitbucket_rest_api/repos/keys.rb +87 -0
- data/lib/bitbucket_rest_api/repos/pull_request.rb +160 -0
- data/lib/bitbucket_rest_api/repos/services.rb +103 -0
- data/lib/bitbucket_rest_api/repos/sources.rb +39 -0
- data/lib/bitbucket_rest_api/repos/webhooks.rb +96 -0
- data/lib/bitbucket_rest_api/request.rb +76 -0
- data/lib/bitbucket_rest_api/request/basic_auth.rb +31 -0
- data/lib/bitbucket_rest_api/request/jsonize.rb +46 -0
- data/lib/bitbucket_rest_api/request/oauth.rb +53 -0
- data/lib/bitbucket_rest_api/response.rb +28 -0
- data/lib/bitbucket_rest_api/response/helpers.rb +21 -0
- data/lib/bitbucket_rest_api/response/jsonize.rb +30 -0
- data/lib/bitbucket_rest_api/response/mashify.rb +24 -0
- data/lib/bitbucket_rest_api/response/raise_error.rb +31 -0
- data/lib/bitbucket_rest_api/response/xmlize.rb +26 -0
- data/lib/bitbucket_rest_api/result.rb +140 -0
- data/lib/bitbucket_rest_api/user.rb +101 -0
- data/lib/bitbucket_rest_api/users.rb +24 -0
- data/lib/bitbucket_rest_api/users/account.rb +53 -0
- data/lib/bitbucket_rest_api/utils/url.rb +56 -0
- data/lib/bitbucket_rest_api/validations.rb +25 -0
- data/lib/bitbucket_rest_api/validations/format.rb +24 -0
- data/lib/bitbucket_rest_api/validations/presence.rb +25 -0
- data/lib/bitbucket_rest_api/validations/required.rb +44 -0
- data/lib/bitbucket_rest_api/validations/token.rb +43 -0
- data/lib/bitbucket_rest_api/version.rb +11 -0
- data/spec/bitbucket_rest_api/api/actions_spec.rb +17 -0
- data/spec/bitbucket_rest_api/api_factory_spec.rb +30 -0
- data/spec/bitbucket_rest_api/api_spec.rb +86 -0
- data/spec/bitbucket_rest_api/authorization_spec.rb +72 -0
- data/spec/bitbucket_rest_api/client_spec.rb +15 -0
- data/spec/bitbucket_rest_api/core_ext/array_spec.rb +12 -0
- data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +49 -0
- data/spec/bitbucket_rest_api/deprecation_spec.rb +30 -0
- data/spec/bitbucket_rest_api/error/bad_events_spec.rb +10 -0
- data/spec/bitbucket_rest_api/error/blank_value_spec.rb +13 -0
- data/spec/bitbucket_rest_api/error/no_events_spec.rb +10 -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 +88 -0
- data/spec/bitbucket_rest_api/issues/milestones_spec.rb +88 -0
- data/spec/bitbucket_rest_api/issues_spec.rb +90 -0
- data/spec/bitbucket_rest_api/normalizer_spec.rb +30 -0
- data/spec/bitbucket_rest_api/parameter_filter_spec.rb +41 -0
- data/spec/bitbucket_rest_api/repos/changesets_spec.rb +43 -0
- data/spec/bitbucket_rest_api/repos/commits_spec.rb +20 -0
- data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +64 -0
- data/spec/bitbucket_rest_api/repos/download_spec.rb +9 -0
- data/spec/bitbucket_rest_api/repos/following_spec.rb +52 -0
- data/spec/bitbucket_rest_api/repos/forks_spec.rb +45 -0
- data/spec/bitbucket_rest_api/repos/keys_spec.rb +72 -0
- data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +288 -0
- data/spec/bitbucket_rest_api/repos/sources_spec.rb +77 -0
- data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
- data/spec/bitbucket_rest_api/repos_spec.rb +157 -0
- data/spec/bitbucket_rest_api/request/jsonize_spec.rb +18 -0
- data/spec/bitbucket_rest_api/request/oauth_spec.rb +27 -0
- data/spec/bitbucket_rest_api/request_spec.rb +81 -0
- data/spec/bitbucket_rest_api/response/jsonize_spec.rb +12 -0
- data/spec/bitbucket_rest_api/response/mashify_spec.rb +32 -0
- data/spec/bitbucket_rest_api/response/raise_error_spec.rb +41 -0
- data/spec/bitbucket_rest_api/user_spec.rb +77 -0
- data/spec/bitbucket_rest_api/utils/url_spec.rb +33 -0
- data/spec/bitbucket_rest_api/validations/format_spec.rb +29 -0
- data/spec/bitbucket_rest_api/validations/presence_spec.rb +12 -0
- data/spec/bitbucket_rest_api/validations/required_spec.rb +43 -0
- data/spec/bitbucket_rest_api/validations/token_spec.rb +16 -0
- data/spec/bitbucket_rest_api_spec.rb +17 -0
- data/spec/spec_helper.rb +24 -0
- metadata +373 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket::Client do
|
4
|
+
let(:client) { described_class.new }
|
5
|
+
|
6
|
+
it "returns the a new object of the correct class" do
|
7
|
+
expect(client.issues).to be_a BitBucket::Issues
|
8
|
+
expect(client.repos).to be_a BitBucket::Repos
|
9
|
+
expect(client.users).to be_a BitBucket::Users
|
10
|
+
expect(client.user_api).to be_a BitBucket::User
|
11
|
+
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
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bitbucket_rest_api/core_ext/array'
|
3
|
+
|
4
|
+
describe Array do
|
5
|
+
let(:array) { [:a, :b, :c, :d, { key: :value }] }
|
6
|
+
|
7
|
+
describe '#extract_options!' do
|
8
|
+
it 'selects a hash from the arguments list' do
|
9
|
+
expect(array.extract_options!).to eq({ key: :value })
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Hash do
|
6
|
+
|
7
|
+
before do
|
8
|
+
BitBucket.new
|
9
|
+
@hash = { :a => 1, :b => 2, :c => 'e'}
|
10
|
+
@serialized = "a=1&b=2&c=e"
|
11
|
+
@nested_hash = { 'a' => { 'b' => {'c' => 1 } } }
|
12
|
+
@symbols = { :a => { :b => { :c => 1 } } }
|
13
|
+
end
|
14
|
+
|
15
|
+
context '#symbolize_keys' do
|
16
|
+
it 'should respond to symbolize_keys' do
|
17
|
+
expect(@nested_hash).to respond_to :symbolize_keys
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context '#symbolize_keys!' do
|
22
|
+
it 'should respond to symbolize_keys!' do
|
23
|
+
expect(@nested_hash).to respond_to :symbolize_keys!
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should convert nested keys to symbols' do
|
27
|
+
expect(@nested_hash.symbolize_keys!).to eq @symbols
|
28
|
+
|
29
|
+
@nested_hash_with_array = { 'a' => { 'b' => [{'c' => 1}] } }
|
30
|
+
expect(@nested_hash_with_array.symbolize_keys!).to eq({:a=>{:b=>[{:c=>1}]}})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '#serialize' do
|
35
|
+
it 'should respond to serialize' do
|
36
|
+
expect(@nested_hash).to respond_to :serialize
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should serialize hash' do
|
40
|
+
expect(@hash.serialize).to eq @serialized
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context '#deep_key?' do
|
45
|
+
it 'should find key inside nested hash' do
|
46
|
+
expect(@nested_hash.has_deep_key?('c')).to be_truthy
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end # Hash
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket do
|
4
|
+
let(:method) { 'create_repos'}
|
5
|
+
let(:alt_method) { 'repos.create'}
|
6
|
+
|
7
|
+
it { expect(described_class.constants).to include :DEPRECATION_PREFIX }
|
8
|
+
|
9
|
+
context '.deprecate' do
|
10
|
+
before do
|
11
|
+
BitBucket.deprecation_tracker = []
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'tracks messages' do
|
15
|
+
expect(BitBucket).to receive(:warn).once()
|
16
|
+
BitBucket.deprecate(method)
|
17
|
+
BitBucket.deprecate(method)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'prints the message through Kernel' do
|
21
|
+
expect(BitBucket).to receive(:warn).once()
|
22
|
+
BitBucket.deprecate method
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'prints the message through Kernel' do
|
27
|
+
expect(BitBucket).to receive(:warn)
|
28
|
+
BitBucket.warn_deprecation method
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket::Error::BadEvents do
|
4
|
+
context 'an event that does not exist is passed in BitBucket::Repos::Webhooks#create or BitBucket::Repos::Webhooks#edit' do
|
5
|
+
it 'should raise an error with a message' do
|
6
|
+
expect { raise described_class.new('bad:event') }.
|
7
|
+
to raise_error(BitBucket::Error::BadEvents, "The event: 'bad:event', does not exist :(")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket::Error::BlankValue do
|
4
|
+
context 'an event that does not exist is passed in BitBucket::Repos::Webhooks#create or BitBucket::Repos::Webhooks#edit' do
|
5
|
+
it 'should raise an error with a message' do
|
6
|
+
expect { raise described_class.new('required_key') }.
|
7
|
+
to raise_error(
|
8
|
+
BitBucket::Error::BlankValue,
|
9
|
+
"The value for: 'required_key', cannot be blank :("
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket::Error::NoEvents do
|
4
|
+
context 'no events are passed in BitBucket::Repos::Webhooks#create or BitBucket::Repos::Webhooks#edit' do
|
5
|
+
it 'should raise an error with a message' do
|
6
|
+
expect { raise described_class.new }.
|
7
|
+
to raise_error(BitBucket::Error::NoEvents, "At least one event is required, none given :(")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket::Invitations do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#invitations' do
|
7
|
+
before do
|
8
|
+
expect(subject).to receive(:request).with(
|
9
|
+
:post,
|
10
|
+
"/2.0/invitations/mock_username/mock_repo/mock_email_address",
|
11
|
+
{ :permission => 'read' },
|
12
|
+
{}
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sends a POST request for an invitation belonging to the given repo' do
|
17
|
+
subject.invite('mock_username', 'mock_repo', 'mock_email_address', 'read')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket::Issues::Comments do
|
4
|
+
let(:comments) { described_class.new }
|
5
|
+
|
6
|
+
describe '.list' do
|
7
|
+
before do
|
8
|
+
expect(comments).to receive(:request).with(
|
9
|
+
:get,
|
10
|
+
'/2.0/repositories/mock_username/mock_repo/issues/mock_issue_id/comments/',
|
11
|
+
{},
|
12
|
+
{}
|
13
|
+
).and_return(['comment1', 'comment2', 'comment3'])
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'without a block' do
|
17
|
+
it 'should make a GET request for the given issue' do
|
18
|
+
comments.list('mock_username', 'mock_repo', 'mock_issue_id')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a block' do
|
23
|
+
it 'should make a GET request for the given issue' do
|
24
|
+
comments.list('mock_username', 'mock_repo', 'mock_issue_id') { |comment| comment }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.get' do
|
30
|
+
before do
|
31
|
+
expect(comments).to receive(:request).with(
|
32
|
+
:get,
|
33
|
+
'/2.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
|
34
|
+
{},
|
35
|
+
{}
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should make a GET request for the given comment' do
|
40
|
+
comments.get('mock_username', 'mock_repo', 'mock_comment_id')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '.create' do
|
45
|
+
before do
|
46
|
+
expect(comments).to receive(:request).with(
|
47
|
+
:post,
|
48
|
+
'/2.0/repositories/mock_username/mock_repo/issues/mock_issue_id/comments/',
|
49
|
+
{'content' => 'mock_comment'},
|
50
|
+
{}
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should send a POST request for the given issue' do
|
55
|
+
comments.create('mock_username', 'mock_repo', 'mock_issue_id', 'content' => 'mock_comment')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '.edit' do
|
60
|
+
before do
|
61
|
+
expect(comments).to receive(:request).with(
|
62
|
+
:put,
|
63
|
+
'/2.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
|
64
|
+
{'content' => 'new_mock_comment'},
|
65
|
+
{}
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should send a PUT request for the given comment' do
|
70
|
+
comments.edit('mock_username', 'mock_repo', 'mock_comment_id', 'content' => 'new_mock_comment')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '.delete' do
|
75
|
+
before do
|
76
|
+
expect(comments).to receive(:request).with(
|
77
|
+
:delete,
|
78
|
+
'/2.0/repositories/mock_username/mock_repo/issues/comments/mock_comment_id',
|
79
|
+
{},
|
80
|
+
{}
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should make a DELETE request for the given comment' do
|
85
|
+
comments.delete('mock_username', 'mock_repo', 'mock_comment_id')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket::Issues::Components do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#list' do
|
7
|
+
before do
|
8
|
+
expect(subject).to receive(:request).with(
|
9
|
+
:get,
|
10
|
+
'/2.0/repositories/mock_username/mock_repo/issues/components',
|
11
|
+
{},
|
12
|
+
{}
|
13
|
+
).and_return(['component1', 'component2', 'component3'])
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'without a block' do
|
17
|
+
it 'makes a GET request for the components belonging to the given repo' do
|
18
|
+
subject.list('mock_username', 'mock_repo')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a block' do
|
23
|
+
it 'makes a GET request for the components belonging to the given repo' do
|
24
|
+
subject.list('mock_username', '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_username/mock_repo/issues/components/mock_component_id',
|
34
|
+
{},
|
35
|
+
{}
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'makes a GET request for the given component belonging to the given repo' do
|
40
|
+
subject.get('mock_username', 'mock_repo', 'mock_component_id')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#create' do
|
45
|
+
before do
|
46
|
+
expect(subject).to receive(:request).with(
|
47
|
+
:post,
|
48
|
+
'/2.0/repositories/mock_username/mock_repo/issues/components',
|
49
|
+
{ 'name' => 'mock_name' },
|
50
|
+
{}
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'makes a POST request for a new component that will belong to the given repo' do
|
55
|
+
subject.create('mock_username', 'mock_repo', name: 'mock_name')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#update' do
|
60
|
+
before do
|
61
|
+
expect(subject).to receive(:request).with(
|
62
|
+
:put,
|
63
|
+
'/2.0/repositories/mock_username/mock_repo/issues/components/mock_component_id',
|
64
|
+
{ 'name' => 'mock_name' },
|
65
|
+
{}
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'makes a PUT request for the given component belonging to the given repo' do
|
70
|
+
subject.update('mock_username', 'mock_repo', 'mock_component_id', name: 'mock_name')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#delete' do
|
75
|
+
before do
|
76
|
+
expect(subject).to receive(:request).with(
|
77
|
+
:delete,
|
78
|
+
'/2.0/repositories/mock_username/mock_repo/issues/components/mock_component_id',
|
79
|
+
{},
|
80
|
+
{}
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'makes a PUT request for the given component belonging to the given repo' do
|
85
|
+
subject.delete('mock_username', 'mock_repo', 'mock_component_id')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BitBucket::Issues::Milestones do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#list' do
|
7
|
+
before do
|
8
|
+
expect(subject).to receive(:request).with(
|
9
|
+
:get,
|
10
|
+
'/2.0/repositories/mock_username/mock_repo/issues/milestones',
|
11
|
+
{},
|
12
|
+
{}
|
13
|
+
).and_return(['milsetone1', 'milestone2', 'milestone3'])
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'without a block' do
|
17
|
+
it 'makes a GET request for the milestones belonging to the given repo' do
|
18
|
+
subject.list('mock_username', 'mock_repo')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a block' do
|
23
|
+
it 'makes a GET request for the milestones belonging to the given repo' do
|
24
|
+
subject.list('mock_username', 'mock_repo') { |milestone| milestone }
|
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_username/mock_repo/issues/milestones/mock_milestone_id',
|
34
|
+
{},
|
35
|
+
{}
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'makes a GET request for the given milestone belonging to the given repo' do
|
40
|
+
subject.get('mock_username', 'mock_repo', 'mock_milestone_id')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#create' do
|
45
|
+
before do
|
46
|
+
expect(subject).to receive(:request).with(
|
47
|
+
:post,
|
48
|
+
'/2.0/repositories/mock_username/mock_repo/issues/milestones',
|
49
|
+
{ 'name' => 'mock_name' },
|
50
|
+
{}
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'makes a POST request for a new milestone that will belong to the given repo' do
|
55
|
+
subject.create('mock_username', 'mock_repo', name: 'mock_name')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#update' do
|
60
|
+
before do
|
61
|
+
expect(subject).to receive(:request).with(
|
62
|
+
:put,
|
63
|
+
'/2.0/repositories/mock_username/mock_repo/issues/milestones/mock_milestone_id',
|
64
|
+
{ 'name' => 'mock_name' },
|
65
|
+
{}
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'makes a PUT request for the given milestone belonging to the given repo' do
|
70
|
+
subject.update('mock_username', 'mock_repo', 'mock_milestone_id', name: 'mock_name')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#delete' do
|
75
|
+
before do
|
76
|
+
expect(subject).to receive(:request).with(
|
77
|
+
:delete,
|
78
|
+
'/2.0/repositories/mock_username/mock_repo/issues/milestones/mock_milestone_id',
|
79
|
+
{},
|
80
|
+
{}
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'makes a PUT request for the given milestone belonging to the given repo' do
|
85
|
+
subject.delete('mock_username', 'mock_repo', 'mock_milestone_id')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe BitBucket::Issues do
|
5
|
+
let(:issue) { BitBucket::Issues.new }
|
6
|
+
|
7
|
+
describe '.create' do
|
8
|
+
before do
|
9
|
+
expect(issue).to receive(:request).with(
|
10
|
+
:post,
|
11
|
+
'/2.0/repositories/mock_username/mock_repo/issues/',
|
12
|
+
{ 'title' => 'mock_issue' },
|
13
|
+
{}
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should send a POST request to create the issue' do
|
18
|
+
issue.create('mock_username', 'mock_repo', { 'title' => 'mock_issue' })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.edit' do
|
23
|
+
before do
|
24
|
+
expect(issue).to receive(:request).with(
|
25
|
+
:put,
|
26
|
+
'/2.0/repositories/mock_username/mock_repo/issues/1/',
|
27
|
+
{ 'title' => 'new_title' },
|
28
|
+
{}
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should send a PUT request for the given issue' do
|
33
|
+
issue.edit('mock_username', 'mock_repo', 1, { 'title' => 'new_title' })
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.get' do
|
38
|
+
before do
|
39
|
+
expect(issue).to receive(:request).with(
|
40
|
+
:get,
|
41
|
+
'/2.0/repositories/mock_username/mock_repo/issues/1',
|
42
|
+
{},
|
43
|
+
{}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should send a GET request for the given issue' do
|
48
|
+
issue.get('mock_username', 'mock_repo', 1, {})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.delete' do
|
53
|
+
before do
|
54
|
+
expect(issue).to receive(:request).with(
|
55
|
+
:delete,
|
56
|
+
'/2.0/repositories/mock_username/mock_repo/issues/1',
|
57
|
+
{},
|
58
|
+
{}
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should send a DELETE request for the given issue' do
|
63
|
+
issue.delete('mock_username', 'mock_repo', 1)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '.list_repo' do
|
68
|
+
before do
|
69
|
+
expect(issue).to receive(:request).with(
|
70
|
+
:get,
|
71
|
+
'/2.0/repositories/mock_username/mock_repo/issues',
|
72
|
+
{},
|
73
|
+
{}
|
74
|
+
).and_return(OpenStruct.new(:issues => [])).twice
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should send a GET request for the issues for that repo' do
|
78
|
+
issue.list_repo('mock_username', 'mock_repo')
|
79
|
+
issue.list_repo('mock_username', 'mock_repo') { |issue| issue }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "getter methods" do
|
84
|
+
it "returns an object of the correct class" do
|
85
|
+
expect(issue.comments).to be_a BitBucket::Issues::Comments
|
86
|
+
expect(issue.components).to be_a BitBucket::Issues::Components
|
87
|
+
expect(issue.milestones).to be_a BitBucket::Issues::Milestones
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|