tinybucket 1.3.0 → 1.4.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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -1
  3. data/Gemfile +8 -7
  4. data/README.md +28 -5
  5. data/Rakefile +1 -0
  6. data/lib/faraday_middleware/follow_oauth_redirects.rb +5 -2
  7. data/lib/tinybucket.rb +2 -0
  8. data/lib/tinybucket/api.rb +3 -0
  9. data/lib/tinybucket/api/base_api.rb +2 -0
  10. data/lib/tinybucket/api/branch_restrictions_api.rb +6 -5
  11. data/lib/tinybucket/api/branches_api.rb +48 -0
  12. data/lib/tinybucket/api/build_status_api.rb +15 -1
  13. data/lib/tinybucket/api/comments_api.rb +7 -6
  14. data/lib/tinybucket/api/commits_api.rb +25 -4
  15. data/lib/tinybucket/api/diff_api.rb +4 -3
  16. data/lib/tinybucket/api/helper.rb +3 -0
  17. data/lib/tinybucket/api/helper/api_helper.rb +2 -0
  18. data/lib/tinybucket/api/helper/branch_restrictions_helper.rb +2 -0
  19. data/lib/tinybucket/api/helper/branches_helper.rb +29 -0
  20. data/lib/tinybucket/api/helper/build_status_helper.rb +11 -0
  21. data/lib/tinybucket/api/helper/comments_helper.rb +2 -0
  22. data/lib/tinybucket/api/helper/commits_helper.rb +8 -0
  23. data/lib/tinybucket/api/helper/diff_helper.rb +2 -0
  24. data/lib/tinybucket/api/helper/pull_requests_helper.rb +2 -0
  25. data/lib/tinybucket/api/helper/repo_helper.rb +2 -0
  26. data/lib/tinybucket/api/helper/repos_helper.rb +2 -0
  27. data/lib/tinybucket/api/helper/team_helper.rb +2 -0
  28. data/lib/tinybucket/api/helper/user_helper.rb +2 -0
  29. data/lib/tinybucket/api/pull_requests_api.rb +4 -3
  30. data/lib/tinybucket/api/repo_api.rb +4 -3
  31. data/lib/tinybucket/api/repos_api.rb +3 -1
  32. data/lib/tinybucket/api/team_api.rb +4 -2
  33. data/lib/tinybucket/api/user_api.rb +3 -1
  34. data/lib/tinybucket/api_factory.rb +2 -0
  35. data/lib/tinybucket/client.rb +3 -2
  36. data/lib/tinybucket/config.rb +5 -1
  37. data/lib/tinybucket/connection.rb +21 -8
  38. data/lib/tinybucket/constants.rb +2 -0
  39. data/lib/tinybucket/enumerator.rb +2 -0
  40. data/lib/tinybucket/error.rb +2 -0
  41. data/lib/tinybucket/error/base_error.rb +2 -0
  42. data/lib/tinybucket/error/conflict.rb +2 -0
  43. data/lib/tinybucket/error/not_found.rb +2 -0
  44. data/lib/tinybucket/error/service_error.rb +2 -0
  45. data/lib/tinybucket/iterator.rb +4 -2
  46. data/lib/tinybucket/model.rb +3 -0
  47. data/lib/tinybucket/model/base.rb +2 -2
  48. data/lib/tinybucket/model/branch.rb +48 -0
  49. data/lib/tinybucket/model/branch_restriction.rb +4 -2
  50. data/lib/tinybucket/model/build_status.rb +3 -1
  51. data/lib/tinybucket/model/comment.rb +4 -2
  52. data/lib/tinybucket/model/commit.rb +6 -2
  53. data/lib/tinybucket/model/concerns.rb +2 -0
  54. data/lib/tinybucket/model/concerns/acceptable_attributes.rb +2 -0
  55. data/lib/tinybucket/model/concerns/api_callable.rb +2 -0
  56. data/lib/tinybucket/model/concerns/enumerable.rb +2 -0
  57. data/lib/tinybucket/model/concerns/reloadable.rb +2 -0
  58. data/lib/tinybucket/model/concerns/repository_keys.rb +2 -0
  59. data/lib/tinybucket/model/error_response.rb +4 -2
  60. data/lib/tinybucket/model/page.rb +4 -2
  61. data/lib/tinybucket/model/profile.rb +4 -2
  62. data/lib/tinybucket/model/pull_request.rb +4 -2
  63. data/lib/tinybucket/model/repository.rb +31 -5
  64. data/lib/tinybucket/model/team.rb +4 -2
  65. data/lib/tinybucket/null_logger.rb +2 -0
  66. data/lib/tinybucket/parser.rb +5 -0
  67. data/lib/tinybucket/parser/base_parser.rb +3 -2
  68. data/lib/tinybucket/parser/branch_parser.rb +13 -0
  69. data/lib/tinybucket/parser/branch_restriction_parser.rb +2 -0
  70. data/lib/tinybucket/parser/branch_restrictions_parser.rb +2 -0
  71. data/lib/tinybucket/parser/branches_parser.rb +11 -0
  72. data/lib/tinybucket/parser/build_status_parser.rb +2 -0
  73. data/lib/tinybucket/parser/builds_parser.rb +11 -0
  74. data/lib/tinybucket/parser/comment_parser.rb +2 -0
  75. data/lib/tinybucket/parser/comments_parser.rb +2 -0
  76. data/lib/tinybucket/parser/commit_parser.rb +2 -0
  77. data/lib/tinybucket/parser/commits_parser.rb +2 -0
  78. data/lib/tinybucket/parser/profile_parser.rb +2 -0
  79. data/lib/tinybucket/parser/profiles_parser.rb +2 -0
  80. data/lib/tinybucket/parser/pull_request_parser.rb +2 -0
  81. data/lib/tinybucket/parser/pull_requests_parser.rb +2 -0
  82. data/lib/tinybucket/parser/repo_parser.rb +2 -0
  83. data/lib/tinybucket/parser/repos_parser.rb +2 -0
  84. data/lib/tinybucket/parser/team_parser.rb +2 -0
  85. data/lib/tinybucket/parser/teams_parser.rb +2 -0
  86. data/lib/tinybucket/request.rb +2 -0
  87. data/lib/tinybucket/resource.rb +3 -0
  88. data/lib/tinybucket/resource/base.rb +6 -0
  89. data/lib/tinybucket/resource/branch_restrictions.rb +2 -0
  90. data/lib/tinybucket/resource/branches.rb +35 -0
  91. data/lib/tinybucket/resource/commit/base.rb +2 -0
  92. data/lib/tinybucket/resource/commit/build_statuses.rb +6 -3
  93. data/lib/tinybucket/resource/commit/comments.rb +2 -0
  94. data/lib/tinybucket/resource/commits.rb +13 -0
  95. data/lib/tinybucket/resource/forks.rb +2 -0
  96. data/lib/tinybucket/resource/pull_request/base.rb +2 -0
  97. data/lib/tinybucket/resource/pull_request/comments.rb +2 -0
  98. data/lib/tinybucket/resource/pull_request/commits.rb +2 -0
  99. data/lib/tinybucket/resource/pull_requests.rb +2 -0
  100. data/lib/tinybucket/resource/repos.rb +2 -0
  101. data/lib/tinybucket/resource/team/base.rb +2 -0
  102. data/lib/tinybucket/resource/team/followers.rb +2 -0
  103. data/lib/tinybucket/resource/team/following.rb +2 -0
  104. data/lib/tinybucket/resource/team/members.rb +2 -0
  105. data/lib/tinybucket/resource/team/repos.rb +2 -0
  106. data/lib/tinybucket/resource/user/base.rb +2 -0
  107. data/lib/tinybucket/resource/user/followers.rb +2 -0
  108. data/lib/tinybucket/resource/user/following.rb +2 -0
  109. data/lib/tinybucket/resource/user/repos.rb +2 -0
  110. data/lib/tinybucket/resource/watchers.rb +2 -0
  111. data/lib/tinybucket/response.rb +2 -0
  112. data/lib/tinybucket/response/handler.rb +2 -0
  113. data/lib/tinybucket/version.rb +3 -1
  114. data/tinybucket.gemspec +1 -1
  115. metadata +11 -193
  116. data/.coveralls.yml +0 -1
  117. data/.gitignore +0 -33
  118. data/.rspec +0 -1
  119. data/.travis.yml +0 -13
  120. data/Guardfile +0 -13
  121. data/spec/fixtures/branch_restriction.json +0 -17
  122. data/spec/fixtures/build_status.json +0 -16
  123. data/spec/fixtures/comment.json +0 -30
  124. data/spec/fixtures/commit.json +0 -83
  125. data/spec/fixtures/profile.json +0 -29
  126. data/spec/fixtures/pull_request.json +0 -106
  127. data/spec/fixtures/repositories/get.json +0 -78
  128. data/spec/fixtures/repositories/test_owner/get.json +0 -78
  129. data/spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/1/get.json +0 -17
  130. data/spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/get.json +0 -101
  131. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/approve/post.json +0 -16
  132. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/1/get.json +0 -38
  133. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/get.json +0 -40
  134. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/get.json +0 -83
  135. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/post.json +0 -16
  136. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/get.json +0 -16
  137. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/put.json +0 -16
  138. data/spec/fixtures/repositories/test_owner/test_repo/commits/get.json +0 -73
  139. data/spec/fixtures/repositories/test_owner/test_repo/diff/1/get.json +0 -21
  140. data/spec/fixtures/repositories/test_owner/test_repo/forks/get.json +0 -78
  141. data/spec/fixtures/repositories/test_owner/test_repo/get.json +0 -71
  142. data/spec/fixtures/repositories/test_owner/test_repo/patch/1/get.json +0 -29
  143. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/approve/delete.json +0 -3
  144. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/approve/post.json +0 -3
  145. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/1/get.json +0 -30
  146. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/get.json +0 -44
  147. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/commits/get.json +0 -66
  148. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/decline/post.json +0 -116
  149. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/diff/get.txt +0 -13
  150. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/get.json +0 -164
  151. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/merge/post.json +0 -123
  152. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get.json +0 -112
  153. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_declined.json +0 -112
  154. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_merged.json +0 -112
  155. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_open.json +0 -112
  156. data/spec/fixtures/repositories/test_owner/test_repo/watchers/get.json +0 -32
  157. data/spec/fixtures/repository.json +0 -72
  158. data/spec/fixtures/team.json +0 -32
  159. data/spec/fixtures/teams/test_team/followers/get.json +0 -36
  160. data/spec/fixtures/teams/test_team/following/get.json +0 -39
  161. data/spec/fixtures/teams/test_team/get.json +0 -32
  162. data/spec/fixtures/teams/test_team/members/get.json +0 -36
  163. data/spec/fixtures/teams/test_team/repositories/get.json +0 -125
  164. data/spec/fixtures/users/test_owner/followers/get.json +0 -65
  165. data/spec/fixtures/users/test_owner/following/get.json +0 -100
  166. data/spec/fixtures/users/test_owner/get.json +0 -29
  167. data/spec/lib/tinybucket/api/branch_restrictions_api_spec.rb +0 -77
  168. data/spec/lib/tinybucket/api/build_status_api_spec.rb +0 -65
  169. data/spec/lib/tinybucket/api/comments_api_spec.rb +0 -132
  170. data/spec/lib/tinybucket/api/commits_api_spec.rb +0 -152
  171. data/spec/lib/tinybucket/api/diff_api_spec.rb +0 -5
  172. data/spec/lib/tinybucket/api/pull_requests_api_spec.rb +0 -259
  173. data/spec/lib/tinybucket/api/repo_api_spec.rb +0 -99
  174. data/spec/lib/tinybucket/api/repos_api_spec.rb +0 -27
  175. data/spec/lib/tinybucket/api/team_api_spec.rb +0 -82
  176. data/spec/lib/tinybucket/api/user_api_spec.rb +0 -73
  177. data/spec/lib/tinybucket/api_factory_spec.rb +0 -18
  178. data/spec/lib/tinybucket/client_spec.rb +0 -100
  179. data/spec/lib/tinybucket/connection_spec.rb +0 -30
  180. data/spec/lib/tinybucket/error/service_error_spec.rb +0 -23
  181. data/spec/lib/tinybucket/model/branch_restriction_spec.rb +0 -35
  182. data/spec/lib/tinybucket/model/build_status_spec.rb +0 -66
  183. data/spec/lib/tinybucket/model/comment_spec.rb +0 -37
  184. data/spec/lib/tinybucket/model/commit_spec.rb +0 -108
  185. data/spec/lib/tinybucket/model/page_spec.rb +0 -28
  186. data/spec/lib/tinybucket/model/profile_spec.rb +0 -52
  187. data/spec/lib/tinybucket/model/pull_request_spec.rb +0 -141
  188. data/spec/lib/tinybucket/model/repository_spec.rb +0 -131
  189. data/spec/lib/tinybucket/model/team_spec.rb +0 -70
  190. data/spec/lib/tinybucket/null_logger_spec.rb +0 -53
  191. data/spec/lib/tinybucket/resource/branch_restrictions_spec.rb +0 -60
  192. data/spec/lib/tinybucket/resource/commit/build_statuses_spec.rb +0 -50
  193. data/spec/lib/tinybucket/resource/commit/comments_spec.rb +0 -49
  194. data/spec/lib/tinybucket/resource/commits_spec.rb +0 -43
  195. data/spec/lib/tinybucket/resource/forks_spec.rb +0 -36
  196. data/spec/lib/tinybucket/resource/pull_request/comments_spec.rb +0 -41
  197. data/spec/lib/tinybucket/resource/pull_request/commits_spec.rb +0 -41
  198. data/spec/lib/tinybucket/resource/pull_requests_spec.rb +0 -59
  199. data/spec/lib/tinybucket/resource/repos_spec.rb +0 -76
  200. data/spec/lib/tinybucket/resource/team/followers_spec.rb +0 -27
  201. data/spec/lib/tinybucket/resource/team/following_spec.rb +0 -27
  202. data/spec/lib/tinybucket/resource/team/members_spec.rb +0 -27
  203. data/spec/lib/tinybucket/resource/team/repos_spec.rb +0 -27
  204. data/spec/lib/tinybucket/resource/user/followers_spec.rb +0 -27
  205. data/spec/lib/tinybucket/resource/user/following_spec.rb +0 -27
  206. data/spec/lib/tinybucket/resource/user/repos_spec.rb +0 -27
  207. data/spec/lib/tinybucket/resource/watchers_spec.rb +0 -38
  208. data/spec/lib/tinybucket_spec.rb +0 -42
  209. data/spec/spec_helper.rb +0 -45
  210. data/spec/support/api_response_macros.rb +0 -74
  211. data/spec/support/fixture_macros.rb +0 -5
  212. data/spec/support/model_macros.rb +0 -103
@@ -1,132 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Tinybucket::Api::CommentsApi do
4
- include ApiResponseMacros
5
-
6
- let(:request_path) { nil }
7
- let(:owner) { 'test_owner' }
8
- let(:slug) { 'test_repo' }
9
- let(:options) { {} }
10
-
11
- let(:commit_hash) { '1' }
12
- let(:commit) do
13
- m = Tinybucket::Model::Commit.new({})
14
- m.repo_owner = owner
15
- m.repo_slug = slug
16
- m.hash = commit_hash
17
- m
18
- end
19
-
20
- let(:pullreq_id) { '1' }
21
- let(:pullreq) do
22
- m = Tinybucket::Model::PullRequest.new({})
23
- m.repo_owner = owner
24
- m.repo_slug = slug
25
- m.id = pullreq_id
26
- m
27
- end
28
-
29
- let(:commented_to) { nil }
30
- let(:api) do
31
- api = Tinybucket::Api::CommentsApi.new
32
- api.repo_owner = owner
33
- api.repo_slug = slug
34
- api.commented_to = commented_to if commented_to.present?
35
- api
36
- end
37
-
38
- it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) }
39
-
40
- before { stub_apiresponse(:get, request_path) if request_path }
41
-
42
- describe '#list' do
43
- subject { api.list(options) }
44
- let(:commented_to) { commit }
45
-
46
- context 'when without owner' do
47
- let(:owner) { nil }
48
- it { expect { subject }.to raise_error(ArgumentError) }
49
- end
50
-
51
- context 'when without slug' do
52
- let(:slug) { nil }
53
- it { expect { subject }.to raise_error(ArgumentError) }
54
- end
55
-
56
- context 'when without commented_to' do
57
- let(:commented_to) { nil }
58
- it { expect { subject }.to raise_error(ArgumentError) }
59
- end
60
-
61
- context 'when with unknown commented_to' do
62
- let(:commented_to) { {} }
63
- it { expect { subject }.to raise_error(ArgumentError) }
64
- end
65
-
66
- context 'when commented_to is commit' do
67
- let(:commented_to) { commit }
68
- let(:request_path) do
69
- "/repositories/#{owner}/#{slug}/commit/#{commit_hash}/comments"
70
- end
71
- it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
72
- end
73
-
74
- context 'when commented_to is pullreq' do
75
- let(:commented_to) { pullreq }
76
- let(:request_path) do
77
- "/repositories/#{owner}/#{slug}/pullrequests/#{pullreq_id}/comments"
78
- end
79
- it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
80
- end
81
- end
82
-
83
- describe '#find' do
84
- subject { api.find(comment_id, options) }
85
- let(:commented_to) { commit }
86
- let(:comment_id) { '1' }
87
-
88
- context 'when without owner' do
89
- let(:owner) { nil }
90
- it { expect { subject }.to raise_error(ArgumentError) }
91
- end
92
-
93
- context 'when without slug' do
94
- let(:slug) { nil }
95
- it { expect { subject }.to raise_error(ArgumentError) }
96
- end
97
-
98
- context 'when without commented_to' do
99
- let(:commented_to) { nil }
100
- it { expect { subject }.to raise_error(ArgumentError) }
101
- end
102
-
103
- context 'when with unknown commented_to' do
104
- let(:commented_to) { {} }
105
- it { expect { subject }.to raise_error(ArgumentError) }
106
- end
107
-
108
- context 'when commented_to is commit' do
109
- let(:commented_to) { commit }
110
- let(:request_path) do
111
- "/repositories/#{owner}/#{slug}/commit/#{commit_hash}" \
112
- "/comments/#{comment_id}"
113
- end
114
- it 'return Comment model' do
115
- expect(subject).to be_an_instance_of(Tinybucket::Model::Comment)
116
- expect(subject.commented_to).to eq(commit)
117
- end
118
- end
119
-
120
- context 'when commented_to is pull_request' do
121
- let(:commented_to) { pullreq }
122
- let(:request_path) do
123
- "/repositories/#{owner}/#{slug}/pullrequests/#{pullreq_id}" \
124
- "/comments/#{comment_id}"
125
- end
126
- it 'return Comment model' do
127
- expect(subject).to be_an_instance_of(Tinybucket::Model::Comment)
128
- expect(subject.commented_to).to eq(pullreq)
129
- end
130
- end
131
- end
132
- end
@@ -1,152 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Tinybucket::Api::CommitsApi do
4
- include ApiResponseMacros
5
-
6
- let(:request_path) { nil }
7
- let(:owner) { 'test_owner' }
8
- let(:slug) { 'test_repo' }
9
- let(:options) { {} }
10
-
11
- let(:api) do
12
- api = Tinybucket::Api::CommitsApi.new
13
- api.repo_owner = owner
14
- api.repo_slug = slug
15
- api
16
- end
17
-
18
- it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) }
19
-
20
- let(:request_method) { :get }
21
- let(:stub_options) { nil }
22
-
23
- before do
24
- if request_path
25
- opts = stub_options.present? ? stub_options : {}
26
- stub_apiresponse(request_method, request_path, opts)
27
- end
28
- end
29
-
30
- describe 'list' do
31
- subject { api.list(options) }
32
-
33
- context 'without owner' do
34
- let(:owner) { nil }
35
- it { expect { subject }.to raise_error(ArgumentError) }
36
- end
37
-
38
- context 'without slug' do
39
- let(:slug) { nil }
40
- it { expect { subject }.to raise_error(ArgumentError) }
41
- end
42
-
43
- context 'with owner and slug' do
44
- let(:request_path) { "/repositories/#{owner}/#{slug}/commits" }
45
- it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
46
- end
47
- end
48
-
49
- describe 'find' do
50
- let(:revision) { '1' }
51
- subject { api.find(revision, options) }
52
-
53
- context 'without owner' do
54
- let(:owner) { nil }
55
- it { expect { subject }.to raise_error(ArgumentError) }
56
- end
57
-
58
- context 'without slug' do
59
- let(:slug) { nil }
60
- it { expect { subject }.to raise_error(ArgumentError) }
61
- end
62
-
63
- context 'with owner and slug' do
64
- let(:request_path) do
65
- "/repositories/#{owner}/#{slug}/commit/#{revision}"
66
- end
67
- it { expect(subject).to be_instance_of(Tinybucket::Model::Commit) }
68
- end
69
- end
70
-
71
- describe 'approve' do
72
- let(:revision) { '1' }
73
- let(:request_method) { :post }
74
-
75
- subject { api.approve(revision, options) }
76
-
77
- context 'without owner' do
78
- let(:owner) { nil }
79
- it { expect { subject }.to raise_error(ArgumentError) }
80
- end
81
-
82
- context 'without slug' do
83
- let(:slug) { nil }
84
- it { expect { subject }.to raise_error(ArgumentError) }
85
- end
86
-
87
- context 'when pull request is not yet approved' do
88
- let(:request_path) do
89
- "/repositories/#{owner}/#{slug}/commit/#{revision}/approve"
90
- end
91
-
92
- it { expect(subject).to be_truthy }
93
- end
94
-
95
- context 'when pull request is already approved.' do
96
- let(:request_path) do
97
- "/repositories/#{owner}/#{slug}/commit/#{revision}/approve"
98
- end
99
-
100
- let(:stub_options) do
101
- {
102
- status_code: 409,
103
- message: JSON.generate(
104
- error: { message: 'You already approved this pull request.' }
105
- )
106
- }
107
- end
108
- it { expect(subject).to be_truthy }
109
- end
110
- end
111
-
112
- describe 'unapprove' do
113
- let(:revision) { '1' }
114
- let(:request_method) { :delete }
115
- subject { api.unapprove(revision) }
116
-
117
- context 'without owner' do
118
- let(:owner) { nil }
119
- it { expect { subject }.to raise_error(ArgumentError) }
120
- end
121
-
122
- context 'without slug' do
123
- let(:slug) { nil }
124
- it { expect { subject }.to raise_error(ArgumentError) }
125
- end
126
-
127
- context 'when commit is not yet approved' do
128
- let(:request_path) do
129
- "/repositories/#{owner}/#{slug}/commit/#{revision}/approve"
130
- end
131
-
132
- let(:stub_options) do
133
- {
134
- status_code: 404,
135
- message: JSON.generate(
136
- error: { message: 'You haven\'t approve this pull request.' }
137
- )
138
- }
139
- end
140
- it { expect(subject).to be_truthy }
141
- end
142
-
143
- context 'when commit is already approved' do
144
- let(:request_path) do
145
- "/repositories/#{owner}/#{slug}/commit/#{revision}/approve"
146
- end
147
- let(:stub_options) { { status_code: 204, message: '' } }
148
-
149
- it { expect(subject).to be_truthy }
150
- end
151
- end
152
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Tinybucket::Api::DiffApi do
4
- pending 'TODO: add specs'
5
- end
@@ -1,259 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Tinybucket::Api::PullRequestsApi do
4
- include ApiResponseMacros
5
-
6
- let(:api) do
7
- api = Tinybucket::Api::PullRequestsApi.new
8
- api.repo_owner = owner
9
- api.repo_slug = slug
10
- api
11
- end
12
-
13
- let(:owner) { 'test_owner' }
14
- let(:slug) { 'test_repo' }
15
- let(:request_path) { nil }
16
- let(:request_method) { :get }
17
- let(:stub_options) { nil }
18
-
19
- it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) }
20
-
21
- before do
22
- if request_path
23
- opts = stub_options.present? ? stub_options : {}
24
- stub_apiresponse(request_method, request_path, opts)
25
- end
26
- end
27
-
28
- describe 'list' do
29
- let(:options) { {} }
30
-
31
- subject { api.list(options) }
32
-
33
- context 'without repo_owner and repo_slug' do
34
- let(:owner) { nil }
35
- let(:slug) { nil }
36
- it { expect { subject }.to raise_error(ArgumentError) }
37
- end
38
-
39
- context 'without repo_owner' do
40
- let(:owner) { nil }
41
- let(:slug) { 'test_repo' }
42
- it { expect { subject }.to raise_error(ArgumentError) }
43
- end
44
-
45
- context 'without repo_slug' do
46
- let(:owner) { 'test_owner' }
47
- let(:slug) { nil }
48
- it { expect { subject }.to raise_error(ArgumentError) }
49
- end
50
-
51
- context 'with repo_owner and repo_slug' do
52
- let(:request_path) { "/repositories/#{owner}/#{slug}/pullrequests" }
53
- it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
54
- end
55
-
56
- context 'when request with state' do
57
- let(:options) { { state: state } }
58
- let(:request_path) do
59
- "/repositories/#{owner}/#{slug}/pullrequests?state=#{state}"
60
- end
61
-
62
- context 'when state is OPEN' do
63
- let(:state) { 'open' }
64
- it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
65
- end
66
-
67
- context 'when state is DECLINED' do
68
- let(:state) { 'declined' }
69
- it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
70
- end
71
-
72
- context 'when state is MERGED' do
73
- let(:state) { 'merged' }
74
- it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
75
- end
76
- end
77
- end
78
-
79
- describe 'find' do
80
- let(:pr_id) { 1 }
81
- subject { api.find(pr_id) }
82
-
83
- context 'when without repo_owner and repo_slug' do
84
- let(:owner) { nil }
85
- let(:slug) { nil }
86
- it { expect { subject }.to raise_error(ArgumentError) }
87
- end
88
-
89
- context 'when without repo_owner' do
90
- let(:owner) { nil }
91
- it { expect { subject }.to raise_error(ArgumentError) }
92
- end
93
-
94
- context 'when without repo_slug' do
95
- let(:slug) { nil }
96
- it { expect { subject }.to raise_error(ArgumentError) }
97
- end
98
-
99
- context 'when with repo_owner and repo_slug' do
100
- let(:request_path) do
101
- "/repositories/#{owner}/#{slug}/pullrequests/#{pr_id}"
102
- end
103
-
104
- it 'return pull request model' do
105
- expect(subject).to be_an_instance_of(Tinybucket::Model::PullRequest)
106
- end
107
- end
108
- end
109
-
110
- describe 'commits' do
111
- let(:pr_id) { 1 }
112
- subject { api.commits(pr_id) }
113
-
114
- context 'when without repo_owner and repo_slug' do
115
- let(:owner) { nil }
116
- let(:slug) { nil }
117
- it { expect { subject }.to raise_error(ArgumentError) }
118
- end
119
-
120
- context 'when without repo_owner' do
121
- let(:owner) { nil }
122
- it { expect { subject }.to raise_error(ArgumentError) }
123
- end
124
-
125
- context 'when without repo_slug' do
126
- let(:slug) { nil }
127
- it { expect { subject }.to raise_error(ArgumentError) }
128
- end
129
-
130
- context 'when with repo_owner and repo_slug' do
131
- let(:request_path) do
132
- "/repositories/#{owner}/#{slug}/pullrequests/1/commits"
133
- end
134
- it 'return page model which contains commit models' do
135
- expect(subject).to be_an_instance_of(Tinybucket::Model::Page)
136
- end
137
- end
138
- end
139
-
140
- describe 'approve' do
141
- let(:pr_id) { 1 }
142
- let(:request_method) { :post }
143
- subject { api.approve(pr_id) }
144
-
145
- context 'when without repo_owner and repo_slug' do
146
- let(:owner) { nil }
147
- let(:slug) { nil }
148
- it { expect { subject }.to raise_error(ArgumentError) }
149
- end
150
-
151
- context 'when without repo_owner' do
152
- let(:owner) { nil }
153
- it { expect { subject }.to raise_error(ArgumentError) }
154
- end
155
-
156
- context 'when without repo_slug' do
157
- let(:slug) { nil }
158
- it { expect { subject }.to raise_error(ArgumentError) }
159
- end
160
-
161
- context 'when with repo_owner and repo_slug' do
162
- let(:request_path) do
163
- "/repositories/#{owner}/#{slug}/pullrequests/1/approve"
164
- end
165
- context 'when pull request is not yet approved.' do
166
- it { expect(subject).to be_truthy }
167
- end
168
- context 'when pull request is already approved.' do
169
- let(:stub_options) do
170
- {
171
- status_code: 409,
172
- message: JSON.generate(
173
- error: { message: 'You already approved this pull request.' }
174
- )
175
- }
176
- end
177
- it { expect(subject).to be_truthy }
178
- end
179
- end
180
- end
181
-
182
- describe 'unapprove' do
183
- let(:pr_id) { 1 }
184
- let(:request_method) { :delete }
185
- subject { api.unapprove(pr_id) }
186
-
187
- context 'when without repo_owner and repo_slug' do
188
- let(:owner) { nil }
189
- let(:slug) { nil }
190
- it { expect { subject }.to raise_error(ArgumentError) }
191
- end
192
-
193
- context 'when without repo_owner' do
194
- let(:owner) { nil }
195
- it { expect { subject }.to raise_error(ArgumentError) }
196
- end
197
-
198
- context 'when without repo_slug' do
199
- let(:slug) { nil }
200
- it { expect { subject }.to raise_error(ArgumentError) }
201
- end
202
-
203
- context 'when with repo_owner and repo_slug' do
204
- let(:request_path) do
205
- "/repositories/#{owner}/#{slug}/pullrequests/1/approve"
206
- end
207
-
208
- context 'when pull request is approved' do
209
- # In this case, bitbucket api respond '204 No content'.
210
- let(:stub_options) { { status_code: 204, message: '' } }
211
- it { expect(subject).to be_truthy }
212
- end
213
-
214
- context 'when pull request is not approved yet.' do
215
- # In this case, bitbucket api respond '404 NotFound'.
216
- let(:stub_options) do
217
- {
218
- status_code: 404,
219
- message: JSON.generate(
220
- error: { message: 'You haven\'t approve this pull request.' }
221
- )
222
- }
223
- end
224
- it { expect(subject).to be_truthy }
225
- end
226
- end
227
- end
228
-
229
- describe 'diff' do
230
- let(:pr_id) { 1 }
231
- subject { api.diff(pr_id) }
232
-
233
- context 'when without repo_owner and repo_slug' do
234
- let(:owner) { nil }
235
- let(:slug) { nil }
236
- it { expect { subject }.to raise_error(ArgumentError) }
237
- end
238
-
239
- context 'when without repo_owner' do
240
- let(:owner) { nil }
241
- it { expect { subject }.to raise_error(ArgumentError) }
242
- end
243
-
244
- context 'when without repo_slug' do
245
- let(:slug) { nil }
246
- it { expect { subject }.to raise_error(ArgumentError) }
247
- end
248
-
249
- context 'when with repo_owner and repo_slug' do
250
- let(:stub_options) do
251
- { content_type: 'plain/text' }
252
- end
253
- let(:request_path) do
254
- "/repositories/#{owner}/#{slug}/pullrequests/1/diff"
255
- end
256
- it { expect(subject).to be_instance_of(String) }
257
- end
258
- end
259
- end