PageRenderTime 73ms CodeModel.GetById 51ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

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