bitbucket_rest_api2 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +7 -0
  3. data/README.md +169 -0
  4. data/lib/bitbucket_rest_api.rb +90 -0
  5. data/lib/bitbucket_rest_api/api.rb +106 -0
  6. data/lib/bitbucket_rest_api/api/actions.rb +35 -0
  7. data/lib/bitbucket_rest_api/api_factory.rb +30 -0
  8. data/lib/bitbucket_rest_api/authorization.rb +34 -0
  9. data/lib/bitbucket_rest_api/client.rb +56 -0
  10. data/lib/bitbucket_rest_api/configuration.rb +106 -0
  11. data/lib/bitbucket_rest_api/connection.rb +98 -0
  12. data/lib/bitbucket_rest_api/constants.rb +58 -0
  13. data/lib/bitbucket_rest_api/core_ext/array.rb +7 -0
  14. data/lib/bitbucket_rest_api/core_ext/hash.rb +46 -0
  15. data/lib/bitbucket_rest_api/deprecation.rb +39 -0
  16. data/lib/bitbucket_rest_api/error.rb +38 -0
  17. data/lib/bitbucket_rest_api/error/bad_events.rb +9 -0
  18. data/lib/bitbucket_rest_api/error/bad_request.rb +12 -0
  19. data/lib/bitbucket_rest_api/error/blank_value.rb +9 -0
  20. data/lib/bitbucket_rest_api/error/client_error.rb +20 -0
  21. data/lib/bitbucket_rest_api/error/forbidden.rb +12 -0
  22. data/lib/bitbucket_rest_api/error/internal_server_error.rb +12 -0
  23. data/lib/bitbucket_rest_api/error/invalid_options.rb +18 -0
  24. data/lib/bitbucket_rest_api/error/no_events.rb +9 -0
  25. data/lib/bitbucket_rest_api/error/not_found.rb +12 -0
  26. data/lib/bitbucket_rest_api/error/required_params.rb +18 -0
  27. data/lib/bitbucket_rest_api/error/service_error.rb +19 -0
  28. data/lib/bitbucket_rest_api/error/service_unavailable.rb +12 -0
  29. data/lib/bitbucket_rest_api/error/unauthorized.rb +12 -0
  30. data/lib/bitbucket_rest_api/error/unknown_value.rb +18 -0
  31. data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +12 -0
  32. data/lib/bitbucket_rest_api/error/validations.rb +18 -0
  33. data/lib/bitbucket_rest_api/invitations.rb +15 -0
  34. data/lib/bitbucket_rest_api/issues.rb +230 -0
  35. data/lib/bitbucket_rest_api/issues/comments.rb +118 -0
  36. data/lib/bitbucket_rest_api/issues/components.rb +106 -0
  37. data/lib/bitbucket_rest_api/issues/milestones.rb +107 -0
  38. data/lib/bitbucket_rest_api/normalizer.rb +27 -0
  39. data/lib/bitbucket_rest_api/parameter_filter.rb +32 -0
  40. data/lib/bitbucket_rest_api/repos.rb +264 -0
  41. data/lib/bitbucket_rest_api/repos/changesets.rb +54 -0
  42. data/lib/bitbucket_rest_api/repos/commits.rb +40 -0
  43. data/lib/bitbucket_rest_api/repos/default_reviewers.rb +59 -0
  44. data/lib/bitbucket_rest_api/repos/download.rb +21 -0
  45. data/lib/bitbucket_rest_api/repos/following.rb +39 -0
  46. data/lib/bitbucket_rest_api/repos/forks.rb +69 -0
  47. data/lib/bitbucket_rest_api/repos/keys.rb +87 -0
  48. data/lib/bitbucket_rest_api/repos/pull_request.rb +160 -0
  49. data/lib/bitbucket_rest_api/repos/services.rb +103 -0
  50. data/lib/bitbucket_rest_api/repos/sources.rb +39 -0
  51. data/lib/bitbucket_rest_api/repos/webhooks.rb +96 -0
  52. data/lib/bitbucket_rest_api/request.rb +76 -0
  53. data/lib/bitbucket_rest_api/request/basic_auth.rb +31 -0
  54. data/lib/bitbucket_rest_api/request/jsonize.rb +46 -0
  55. data/lib/bitbucket_rest_api/request/oauth.rb +53 -0
  56. data/lib/bitbucket_rest_api/response.rb +28 -0
  57. data/lib/bitbucket_rest_api/response/helpers.rb +21 -0
  58. data/lib/bitbucket_rest_api/response/jsonize.rb +30 -0
  59. data/lib/bitbucket_rest_api/response/mashify.rb +24 -0
  60. data/lib/bitbucket_rest_api/response/raise_error.rb +31 -0
  61. data/lib/bitbucket_rest_api/response/xmlize.rb +26 -0
  62. data/lib/bitbucket_rest_api/result.rb +140 -0
  63. data/lib/bitbucket_rest_api/user.rb +101 -0
  64. data/lib/bitbucket_rest_api/users.rb +24 -0
  65. data/lib/bitbucket_rest_api/users/account.rb +53 -0
  66. data/lib/bitbucket_rest_api/utils/url.rb +56 -0
  67. data/lib/bitbucket_rest_api/validations.rb +25 -0
  68. data/lib/bitbucket_rest_api/validations/format.rb +24 -0
  69. data/lib/bitbucket_rest_api/validations/presence.rb +25 -0
  70. data/lib/bitbucket_rest_api/validations/required.rb +44 -0
  71. data/lib/bitbucket_rest_api/validations/token.rb +43 -0
  72. data/lib/bitbucket_rest_api/version.rb +11 -0
  73. data/spec/bitbucket_rest_api/api/actions_spec.rb +17 -0
  74. data/spec/bitbucket_rest_api/api_factory_spec.rb +30 -0
  75. data/spec/bitbucket_rest_api/api_spec.rb +86 -0
  76. data/spec/bitbucket_rest_api/authorization_spec.rb +72 -0
  77. data/spec/bitbucket_rest_api/client_spec.rb +15 -0
  78. data/spec/bitbucket_rest_api/core_ext/array_spec.rb +12 -0
  79. data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +49 -0
  80. data/spec/bitbucket_rest_api/deprecation_spec.rb +30 -0
  81. data/spec/bitbucket_rest_api/error/bad_events_spec.rb +10 -0
  82. data/spec/bitbucket_rest_api/error/blank_value_spec.rb +13 -0
  83. data/spec/bitbucket_rest_api/error/no_events_spec.rb +10 -0
  84. data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
  85. data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
  86. data/spec/bitbucket_rest_api/issues/components_spec.rb +88 -0
  87. data/spec/bitbucket_rest_api/issues/milestones_spec.rb +88 -0
  88. data/spec/bitbucket_rest_api/issues_spec.rb +90 -0
  89. data/spec/bitbucket_rest_api/normalizer_spec.rb +30 -0
  90. data/spec/bitbucket_rest_api/parameter_filter_spec.rb +41 -0
  91. data/spec/bitbucket_rest_api/repos/changesets_spec.rb +43 -0
  92. data/spec/bitbucket_rest_api/repos/commits_spec.rb +20 -0
  93. data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +64 -0
  94. data/spec/bitbucket_rest_api/repos/download_spec.rb +9 -0
  95. data/spec/bitbucket_rest_api/repos/following_spec.rb +52 -0
  96. data/spec/bitbucket_rest_api/repos/forks_spec.rb +45 -0
  97. data/spec/bitbucket_rest_api/repos/keys_spec.rb +72 -0
  98. data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +288 -0
  99. data/spec/bitbucket_rest_api/repos/sources_spec.rb +77 -0
  100. data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
  101. data/spec/bitbucket_rest_api/repos_spec.rb +157 -0
  102. data/spec/bitbucket_rest_api/request/jsonize_spec.rb +18 -0
  103. data/spec/bitbucket_rest_api/request/oauth_spec.rb +27 -0
  104. data/spec/bitbucket_rest_api/request_spec.rb +81 -0
  105. data/spec/bitbucket_rest_api/response/jsonize_spec.rb +12 -0
  106. data/spec/bitbucket_rest_api/response/mashify_spec.rb +32 -0
  107. data/spec/bitbucket_rest_api/response/raise_error_spec.rb +41 -0
  108. data/spec/bitbucket_rest_api/user_spec.rb +77 -0
  109. data/spec/bitbucket_rest_api/utils/url_spec.rb +33 -0
  110. data/spec/bitbucket_rest_api/validations/format_spec.rb +29 -0
  111. data/spec/bitbucket_rest_api/validations/presence_spec.rb +12 -0
  112. data/spec/bitbucket_rest_api/validations/required_spec.rb +43 -0
  113. data/spec/bitbucket_rest_api/validations/token_spec.rb +16 -0
  114. data/spec/bitbucket_rest_api_spec.rb +17 -0
  115. data/spec/spec_helper.rb +24 -0
  116. metadata +373 -0
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Request::Jsonize do
4
+ let(:jsonize) { described_class.new(lambda { |env| env }) }
5
+ before do
6
+ @env = {
7
+ body: {key1: 'val1'},
8
+ request_headers: {
9
+ 'Content-Type' => 'application/json; charset=utf-8'
10
+ }
11
+ }
12
+ end
13
+
14
+ it "converts the body to json" do
15
+ expected = {body: "{\"key1\":\"val1\"}", request_headers: {"Content-Type"=>"application/json; charset=utf-8"}}
16
+ expect(jsonize.call(@env)).to eq expected
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'rack/test'
3
+
4
+ describe BitBucket::Request::OAuth do
5
+ include Rack::Test::Methods
6
+
7
+
8
+ let(:app) { ->(env) { [200, env, "app"] } }
9
+
10
+ let (:middleware) { BitBucket::Request::OAuth.new(app) }
11
+
12
+ let(:request) { Rack::MockRequest.new(middleware) }
13
+
14
+ it "add url key to env hash with URI value" do
15
+ query_string = "key1=val1&key2=val2"
16
+ code, env = middleware.call Rack::MockRequest.env_for("/?#{query_string}", {method: :post})
17
+ expect(code).to eq 200
18
+ expect(env[:url].query).to eq query_string
19
+ end
20
+
21
+ it "creates a empty hash if query of URI is empty" do
22
+ code, env = middleware.call Rack::MockRequest.env_for("/", {method: :get})
23
+ expect(code).to eq 200
24
+ expect(middleware.query_params(env[:url])).to eq({})
25
+ end
26
+ end
27
+
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+ require 'bitbucket_rest_api/request'
3
+
4
+ describe BitBucket::Request do
5
+ let(:fake_api) { (Class.new { include BitBucket::Request })}
6
+ let(:faraday_connection) { Faraday.new(:url => 'https://api.bitbucket.org') }
7
+
8
+ describe "request" do
9
+ it "raises an ArgumentError if an unsupported HTTP verb is used" do
10
+ expect { fake_api.new.request(:i_am_a_teapot, {}, '/') }.to raise_error(ArgumentError)
11
+ end
12
+
13
+ context "with a connection" do
14
+ before do
15
+ (fake_api).any_instance.stubs(:connection).returns(faraday_connection)
16
+ (fake_api).any_instance.stubs(:new_access_token).returns("12345")
17
+ end
18
+
19
+ it "supports get" do
20
+ stub_request(:get, "https://api.bitbucket.org/2.0/endpoint").
21
+ with(:headers => {
22
+ 'Accept' => '*/*',
23
+ 'Accept-Encoding' => 'gzip;q=2.0,deflate;q=0.6,identity;q=0.3',
24
+ 'Authorization' => 'Bearer 12345',
25
+ 'User-Agent' => 'Faraday v0.9.2'
26
+ })
27
+
28
+ fake_api.new.request(:get, '/2.0/endpoint', {}, {})
29
+ end
30
+
31
+ it "supports put" do
32
+ stub_request(:put, "https://api.bitbucket.org/2.0/endpoint").
33
+ with(:body => "{\"data\":{\"key\":\"value\"}}",
34
+ :headers => {
35
+ 'Accept' => '*/*',
36
+ 'Content-Type'=>'application/x-www-form-urlencoded',
37
+ 'Authorization' => 'Bearer 12345',
38
+ 'User-Agent' => 'Faraday v0.9.2'
39
+ })
40
+
41
+ fake_api.new.request(:put, '/2.0/endpoint', { 'data' => { 'key' => 'value'} }, {})
42
+ end
43
+
44
+ it "supports patch" do
45
+ stub_request(:patch, "https://api.bitbucket.org/2.0/endpoint").
46
+ with(:body => "{\"data\":{\"key\":\"value\"}}",
47
+ :headers => {
48
+ 'Accept' => '*/*',
49
+ 'Content-Type'=>'application/x-www-form-urlencoded',
50
+ 'Authorization' => 'Bearer 12345',
51
+ 'User-Agent' => 'Faraday v0.9.2'
52
+ })
53
+
54
+ fake_api.new.request(:patch, '/2.0/endpoint', { 'data' => { 'key' => 'value'} }, {})
55
+ end
56
+
57
+ it "supports delete" do
58
+ stub_request(:delete, "https://api.bitbucket.org/2.0/endpoint").
59
+ with(:headers => {
60
+ 'Accept' => '*/*',
61
+ 'Authorization' => 'Bearer 12345',
62
+ 'User-Agent' => 'Faraday v0.9.2'
63
+ })
64
+ fake_api.new.request(:delete, '/2.0/endpoint', {}, {})
65
+ end
66
+
67
+ it "supports post" do
68
+ stub_request(:post, "https://api.bitbucket.org/2.0/endpoint").
69
+ with(:body => "{\"data\":{\"key\":\"value\"}}",
70
+ :headers => {
71
+ 'Accept' => '*/*',
72
+ 'Content-Type'=>'application/x-www-form-urlencoded',
73
+ 'Authorization' => 'Bearer 12345',
74
+ 'User-Agent' => 'Faraday v0.9.2'
75
+ })
76
+
77
+ fake_api.new.request(:post, '/2.0/endpoint', { 'data' => { 'key' => 'value'} }, {})
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Response::Jsonize do
4
+ let(:jsonize) { described_class.new }
5
+ before do
6
+ @body = "{\"key1\":\"val1\"}"
7
+ end
8
+
9
+ it "parses the json and returns a hash" do
10
+ expect(jsonize.parse(@body)).to eq({"key1"=>"val1"})
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Response::Mashify do
4
+ # let(:mashify) { described_class.new }
5
+ describe 'parse' do
6
+ before do
7
+ @mashify = BitBucket::Response::Mashify.new
8
+ @string = "Fantastic week!"
9
+ @array = ['Monday', 'Tuesday']
10
+ @hash = {one: 'one', two: 'two', three: 'three'}
11
+ @array_with_hash = ['banana', 'apple', {:third => 'mango'}]
12
+ end
13
+ it 'parses a hash an returns a hashie mash' do
14
+ hashie_mash = @mashify.parse(@hash)
15
+ expect(hashie_mash.one).to eq("one")
16
+ end
17
+
18
+ it 'parses a hash that is within an array' do
19
+ array_hashie_mash = @mashify.parse(@array_with_hash)
20
+ expect(array_hashie_mash[2].third).to eq("mango")
21
+ end
22
+
23
+ it 'returns same object if the object does not contain a hash' do
24
+ string = @mashify.parse(@string)
25
+ array = @mashify.parse(@array)
26
+
27
+ expect(string).to eq(@string)
28
+ expect(array.length).to eq(2)
29
+ expect(array[0]).to eq("Monday")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Response::RaiseError do
4
+ describe '.on_complete' do
5
+ before do
6
+ @raise_error = BitBucket::Response::RaiseError.new
7
+ end
8
+
9
+ it 'raises a BadRequest error on 400 status code' do
10
+ expect{ @raise_error.on_complete({status: 400}) }.to raise_error BitBucket::Error::BadRequest
11
+ end
12
+
13
+ it 'raises an Unauthorized error on 401 status code' do
14
+ expect{ @raise_error.on_complete({status: 401}) }.to raise_error BitBucket::Error::Unauthorized
15
+ end
16
+
17
+ it 'raises a Forbidden error on 403 status code' do
18
+ expect{ @raise_error.on_complete({status: 403}) }.to raise_error BitBucket::Error::Forbidden
19
+ end
20
+
21
+ it 'raises a NotFound error on 404 status code' do
22
+ expect{ @raise_error.on_complete({status: 404}) }.to raise_error BitBucket::Error::NotFound
23
+ end
24
+
25
+ it 'raises an UnprocessableEntity error on 422 status code' do
26
+ expect{ @raise_error.on_complete({status: 422}) }.to raise_error BitBucket::Error::UnprocessableEntity
27
+ end
28
+
29
+ it 'raises an InternalServerError error on 500 status code' do
30
+ expect{ @raise_error.on_complete({status: 500}) }.to raise_error BitBucket::Error::InternalServerError
31
+ end
32
+
33
+ it 'raises a ServiceUnavailable error on 503 status code' do
34
+ expect{ @raise_error.on_complete({status: 503}) }.to raise_error BitBucket::Error::ServiceUnavailable
35
+ end
36
+
37
+ it 'raises a ServiceError when another status code' do
38
+ expect{ @raise_error.on_complete({status: 501}) }.to raise_error BitBucket::Error::ServiceError
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::User do
4
+ let(:options) do
5
+ {
6
+ client_id: 'example_client_id',
7
+ client_secret: 'example_client_secret',
8
+ oauth_token: 'example_oauth_token',
9
+ oauth_secret: 'example_oauth_secret',
10
+ adapter: :net_http
11
+ }
12
+ end
13
+
14
+ before do
15
+ @user = BitBucket::User.new(options)
16
+ end
17
+
18
+ describe '#profile' do
19
+ it 'sends the request to the right url' do
20
+ expect(@user).to receive(:request).with(:get, '/2.0/user', {}, {})
21
+ @user.profile
22
+ end
23
+ end
24
+
25
+ describe '#update' do
26
+ let(:params) do
27
+ { first_name: 'first-name', last_name: 'last-name', avatar: '' }
28
+ end
29
+
30
+ it 'sends the request to the right url' do
31
+ expect(@user).to receive(:request).with(:put, '/2.0/user', params, {})
32
+ @user.update(params)
33
+ end
34
+ end
35
+
36
+ describe '#privileges' do
37
+ it 'sends the request to the right url' do
38
+ expect(@user).to receive(:request).with(:get, '/2.0/user/privileges', {}, {})
39
+ @user.privileges
40
+ end
41
+ end
42
+
43
+ describe '#follows' do
44
+ it 'sends the request to the right url' do
45
+ expect(@user).to receive(:request).with(:get, '/2.0/user/follows', {}, {})
46
+ @user.follows
47
+ end
48
+ end
49
+
50
+ describe '#repositories' do
51
+ it 'sends the request to the right url' do
52
+ expect(@user).to receive(:request).with(:get, '/2.0/user/repositories', {}, {})
53
+ @user.repositories
54
+ end
55
+ end
56
+
57
+ describe '#repos' do
58
+ it 'sends the request to the right url' do
59
+ expect(@user).to receive(:request).with(:get, '/2.0/user/repositories', {}, {})
60
+ @user.repos
61
+ end
62
+ end
63
+
64
+ describe '#overview' do
65
+ it 'sends the request to the right url' do
66
+ expect(@user).to receive(:request).with(:get, '/2.0/user/repositories/overview', {}, {})
67
+ @user.overview
68
+ end
69
+ end
70
+
71
+ describe '#dashboard' do
72
+ it 'sends the request to the right url' do
73
+ expect(@user).to receive(:request).with(:get, '/2.0/user/repositories/dashboard', {}, {})
74
+ @user.dashboard
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Utils::Url do
4
+ before do
5
+ @url_util = BitBucket::Utils::Url
6
+ end
7
+
8
+ describe '.build_query' do
9
+ it 'builds a query string from a params hash' do
10
+ expect(@url_util.build_query({key1: "val1", key2: "val2"})).to eq "key1=val1&key2=val2"
11
+ end
12
+
13
+ it 'builds a query string from a params hash when one value is an array' do
14
+ expect(@url_util.build_query({key1: "val1", key2: ["val2", "val3"]})).to eq "key1=val1&key2=val2&key2=val3"
15
+ end
16
+ end
17
+
18
+ describe '.parse_query' do
19
+ it 'builds a params hash from a query string' do
20
+ expect(@url_util.parse_query("key1=val1&key2=val2")).to eq({"key1" => "val1", "key2" => "val2"})
21
+ end
22
+
23
+ it 'builds a params hash from a query string when given multiple values for the same param' do
24
+ expect(@url_util.parse_query("key1=val1&key2=val2&key2=val3&key2=val4")).to eq({"key1" => "val1", "key2" => ["val2", "val3", "val4"]})
25
+ end
26
+ end
27
+
28
+ describe '.parse_query_for_param' do
29
+ it 'returns a value a query string given the key' do
30
+ expect(@url_util.parse_query_for_param("key1=val1&key2=val2", "key2")).to eq("val2")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Validations::Format do
4
+ let(:format) { Class.new.extend(described_class) }
5
+ before do
6
+ @permitted = {"param1" => ["val1", "val2"], "param2" => /^regexp$/}
7
+ end
8
+
9
+ describe ".assert_valid_values" do
10
+ it "raises an UnknownValue error when provided an unpermitted parameter" do
11
+ params = {"param1" => "unpermitted_value"}
12
+ expect{
13
+ format.assert_valid_values(@permitted, params)
14
+ }.to raise_error BitBucket::Error::UnknownValue
15
+
16
+ params = {"param2" => "unpermitted_value"}
17
+ expect{
18
+ format.assert_valid_values(@permitted, params)
19
+ }.to raise_error BitBucket::Error::UnknownValue
20
+ end
21
+
22
+ it "returns the params when provided with only permitted parameters" do
23
+ params = {"param1" => "val1", "param2" => "regexp"}
24
+ expect(
25
+ format.assert_valid_values(@permitted, params)
26
+ ).to eq({"param1" => "val1", "param2" => "regexp"})
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Validations::Presence do
4
+ let(:presence_checker) { Class.new.extend(described_class) }
5
+
6
+ describe "._validates_user_repo_params" do
7
+ it 'raises an ArgumentError if user_name or repo_name is nil' do
8
+ expect{presence_checker._validate_user_repo_params('user_name', nil)}.to raise_error ArgumentError
9
+ expect{presence_checker._validate_user_repo_params(nil, 'repo_name')}.to raise_error ArgumentError
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Validations::Required do
4
+ class SpecClass
5
+ include BitBucket::Validations::Required
6
+ end
7
+
8
+ let(:spec_class) { SpecClass.new }
9
+ let(:params_with_blank) do
10
+ {
11
+ 'title' => "mock_title",
12
+ 'source' => {
13
+ 'branch' => {
14
+ 'name' => ""
15
+ }
16
+ }
17
+ }
18
+ end
19
+
20
+ describe '#parse_values' do
21
+ it 'parses a colon separated string to an array' do
22
+ result = spec_class.parse_values('hello:world')
23
+ expectation = ['hello', 'world']
24
+
25
+ expect(result).to eq(expectation)
26
+ end
27
+ end
28
+
29
+ describe '#assert_required_values_present' do
30
+ it 'raises an instance of BitBucket::Error::BlankValue if a required string is left blank' do
31
+ expect do
32
+ spec_class.assert_required_values_present(
33
+ params_with_blank,
34
+ 'title',
35
+ 'source:branch:name'
36
+ )
37
+ end.to raise_error(
38
+ BitBucket::Error::BlankValue,
39
+ "The value for: 'source:branch:name', cannot be blank :("
40
+ )
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Validations::Token do
4
+ let(:token) { Class.new.extend(described_class) }
5
+
6
+ describe ".validates_token_for" do
7
+ it 'returns false if authentication token is not required' do
8
+ expect(token.validates_token_for(:get, '/anotherpath')).to be false
9
+ end
10
+
11
+ it 'returns true if authentication token is required' do
12
+ expect(token.validates_token_for(:get, '/user')).to be true
13
+ expect(token.validates_token_for(:get, '/repos/a/b/comments')).to be true
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ describe BitBucket do
2
+ let(:api) { BitBucket }
3
+
4
+ describe "register_constant" do
5
+ it "sets a constant" do
6
+ api.register_constant({const_1: 'value1'})
7
+ end
8
+ end
9
+
10
+ describe "lookup_constant" do
11
+ it "returns the constant's value" do
12
+ expect(api.lookup_constant('CONST_1')).to eq 'value1'
13
+ expect{ api.lookup_constant('UNKNOWN_CONSTANT')}.to raise_error NameError
14
+ end
15
+ end
16
+
17
+ end