/spec/octokit/client/issues_spec.rb

http://github.com/pengwynn/octokit · Ruby · 265 lines · 231 code · 34 blank · 0 comment · 10 complexity · 67ecf62bc536f58da5460b5eb59ee6a2 MD5 · raw file

  1. require 'helper'
  2. describe Octokit::Client::Issues do
  3. before do
  4. Octokit.reset!
  5. @client = oauth_client
  6. end
  7. after do
  8. Octokit.reset!
  9. end
  10. describe ".list_issues", :vcr do
  11. it "returns issues for a repository" do
  12. issues = @client.issues("sferik/rails_admin")
  13. expect(issues).to be_kind_of Array
  14. assert_requested :get, github_url("/repos/sferik/rails_admin/issues")
  15. end
  16. it "returns dashboard issues for the authenticated user" do
  17. issues = @client.issues
  18. expect(issues).to be_kind_of Array
  19. assert_requested :get, github_url("/issues")
  20. end
  21. end # .list_issues
  22. describe ".user_issues", :vcr do
  23. it "returns issues for the authenticated user for owned and member repos" do
  24. issues = @client.user_issues
  25. expect(issues).to be_kind_of Array
  26. assert_requested :get, github_url("/user/issues")
  27. end
  28. end # .user_issues
  29. describe ".org_issues", :vcr do
  30. it "returns issues for the organization for the authenticated user" do
  31. issues = @client.org_issues(test_github_org)
  32. expect(issues).to be_kind_of Array
  33. assert_requested :get, github_url("/orgs/#{test_github_org}/issues")
  34. end
  35. end # .org_issues
  36. describe ".list_assignees", :vcr do
  37. it "returns available assignees for a repository" do
  38. users = @client.list_assignees("octokit/octokit.rb")
  39. expect(users).to be_kind_of Array
  40. assert_requested :get, github_url("/repos/octokit/octokit.rb/assignees")
  41. end
  42. end
  43. context "with repository" do
  44. before(:each) do
  45. @repo = @client.create_repository("#{test_github_repository}_#{Time.now.to_f}")
  46. end
  47. after(:each) do
  48. begin
  49. @client.delete_repository(@repo.full_name)
  50. rescue Octokit::NotFound
  51. end
  52. end
  53. describe ".create_issue", :vcr do
  54. it "creates an issue" do
  55. issue = @client.create_issue \
  56. @repo.full_name,
  57. "Migrate issues to v3",
  58. "Move all Issues calls to v3 of the API"
  59. expect(issue.title).to match(/Migrate/)
  60. assert_requested :post, github_url("/repos/#{@repo.full_name}/issues")
  61. end
  62. it "creates an issue with delimited labels" do
  63. issue = @client.create_issue \
  64. @repo.full_name,
  65. "New issue with delimited labels",
  66. "Testing",
  67. :labels => "bug, feature"
  68. expect(issue.title).to match(/delimited/)
  69. expect(issue.labels.map(&:name)).to include("feature")
  70. assert_requested :post, github_url("/repos/#{@repo.full_name}/issues")
  71. end
  72. it "creates an issue with labels array" do
  73. issue = @client.create_issue \
  74. @repo.full_name,
  75. "New issue with labels array",
  76. "Testing",
  77. :labels => %w(bug feature)
  78. expect(issue.title).to match(/array/)
  79. expect(issue.labels.map(&:name)).to include("feature")
  80. assert_requested :post, github_url("/repos/#{@repo.full_name}/issues")
  81. end
  82. it "creates an issue without body argument" do
  83. issue = @client.create_issue(@repo.full_name, "New issue without body argument")
  84. expect(issue.body).to be_nil
  85. assert_requested :post, github_url("/repos/#{@repo.full_name}/issues")
  86. end
  87. end # .create_issue
  88. context "with issue" do
  89. before(:each) do
  90. @issue = @client.create_issue(@repo.full_name, "Migrate issues to v3", "Move all Issues calls to v3 of the API")
  91. end
  92. describe ".issue", :vcr do
  93. it "returns an issue" do
  94. issue = @client.issue(@repo.full_name, @issue.number)
  95. assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}")
  96. expect(issue.number).to eq(@issue.number)
  97. end
  98. it "returns a full issue" do
  99. issue = @client.issue(@repo.full_name, @issue.number, :accept => 'application/vnd.github.full+json')
  100. assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}")
  101. expect(issue.body_html).to include('<p>Move all')
  102. expect(issue.body_text).to include('Move all')
  103. end
  104. end # .issue
  105. describe ".close_issue", :vcr do
  106. it "closes an issue" do
  107. issue = @client.close_issue(@repo.full_name, @issue.number)
  108. expect(issue.state).to eq "closed"
  109. expect(issue.number).to eq(@issue.number)
  110. assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}")
  111. end
  112. end # .close_issue
  113. context "with closed issue" do
  114. before(:each) do
  115. @client.close_issue(@repo.full_name, @issue.number)
  116. end
  117. describe ".reopen_issue", :vcr do
  118. it "reopens an issue" do
  119. issue = @client.reopen_issue(@repo.full_name, @issue.number)
  120. expect(issue.state).to eq "open"
  121. expect(issue.number).to eq(@issue.number)
  122. assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}"), :times => 2
  123. end
  124. end # .reopen_issue
  125. end # with closed issue
  126. describe ".lock_issue", :vcr do
  127. it "locks an issue" do
  128. @client.lock_issue(@repo.full_name, @issue.number)
  129. assert_requested :put, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/lock")
  130. end
  131. end # .lock_issue
  132. context "with locked issue" do
  133. before(:each) do
  134. @client.lock_issue(@repo.full_name, @issue.number)
  135. end
  136. describe ".unlock_issue", :vcr do
  137. it "unlocks an issue" do
  138. @client.unlock_issue(@repo.full_name, @issue.number)
  139. assert_requested :delete, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/lock")
  140. end
  141. end # .unlock_issue
  142. end # with locked issue
  143. describe ".update_issue", :vcr do
  144. it "updates an issue" do
  145. issue = @client.update_issue(@repo.full_name, @issue.number, "Use all the v3 api!", "")
  146. expect(issue.number).to eq(@issue.number)
  147. assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}")
  148. end
  149. it "updates an issue without positional args" do
  150. issue = @client.update_issue(@repo.full_name, @issue.number, :title => "Use all the v3 api!", :body => "")
  151. expect(issue.number).to eq(@issue.number)
  152. assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}")
  153. end
  154. end # .update_issue
  155. describe ".add_comment", :vcr do
  156. it "adds a comment" do
  157. comment = @client.add_comment(@repo.full_name, @issue.number, "A test comment")
  158. expect(comment.user.login).to eq(test_github_login)
  159. assert_requested :post, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/comments")
  160. end
  161. end # .add_comment
  162. context "with issue comment" do
  163. before(:each) do
  164. @issue_comment = @client.add_comment(@repo.full_name, @issue.number, "Another test comment")
  165. end
  166. describe ".update_comment", :vcr do
  167. it "updates an existing comment" do
  168. @client.update_comment(@repo.full_name, @issue_comment.id, "A test comment update")
  169. assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/comments/#{@issue_comment.id}")
  170. end
  171. end # .update_comment
  172. describe ".delete_comment", :vcr do
  173. it "deletes an existing comment" do
  174. @client.delete_comment(@repo.full_name, @issue_comment.id)
  175. assert_requested :delete, github_url("/repos/#{@repo.full_name}/issues/comments/#{@issue_comment.id}")
  176. end
  177. end # .delete_comment
  178. end # with issue comment
  179. describe ".issue_timeline", :vcr do
  180. it "returns an issue timeline" do
  181. timeline = @client.issue_timeline(@repo.full_name, @issue.number, accept: Octokit::Preview::PREVIEW_TYPES[:issue_timelines])
  182. expect(timeline).to be_kind_of Array
  183. assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/timeline")
  184. end
  185. end # .issue_timeline
  186. context "with assignees" do
  187. before(:each) do
  188. issue = @client.add_assignees(@repo.full_name, @issue.number, ["api-padawan"])
  189. expect(issue.assignees.count).not_to be_zero
  190. end
  191. describe ".remove_assignees", :vcr do
  192. it "removes assignees" do
  193. issue = @client.remove_assignees(
  194. @repo.full_name, @issue.number, ["api-padawan"]
  195. )
  196. expect(issue.assignees.count).to be_zero
  197. assert_requested :post, github_url("repos/#{@repo.full_name}/issues/#{@issue.number}/assignees")
  198. end
  199. end # .remove_assignees
  200. end # with assignees
  201. end # with issue
  202. end # with repo
  203. describe ".repository_issues_comments", :vcr do
  204. it "returns comments for all issues in a repository" do
  205. comments = @client.issues_comments("octokit/octokit.rb")
  206. expect(comments).to be_kind_of Array
  207. assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/comments')
  208. end
  209. end # .repository_issues_comments
  210. describe ".issue_comments", :vcr do
  211. it "returns comments for an issue" do
  212. comments = @client.issue_comments("octokit/octokit.rb", 25)
  213. expect(comments).to be_kind_of Array
  214. assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/25/comments')
  215. end
  216. end # .issue_comments
  217. describe ".issue_comment", :vcr do
  218. it "returns a single comment for an issue" do
  219. comment = @client.issue_comment("octokit/octokit.rb", 1194690)
  220. expect(comment.rels[:self].href).to eq("https://api.github.com/repos/octokit/octokit.rb/issues/comments/1194690")
  221. assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/comments/1194690')
  222. end
  223. end # .issue_comment
  224. describe ".add_assignees", :vcr do
  225. it "adds assignees" do
  226. issue = @client.add_assignees('tomb0y/wheelbarrow', 10, ["tomb0y"])
  227. expect(issue.assignees.count).not_to be_zero
  228. assert_requested :post, github_url("repos/tomb0y/wheelbarrow/issues/10/assignees")
  229. end
  230. end # .add_assignees
  231. end