github_api 0.8.11 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/README.md +21 -14
  2. data/features/activity/notifications.feature +15 -0
  3. data/features/cassettes/activity/notifications/list_user.yml +54 -0
  4. data/features/step_definitions/common_steps.rb +8 -9
  5. data/lib/github_api.rb +3 -4
  6. data/lib/github_api/activity.rb +8 -13
  7. data/lib/github_api/activity/events.rb +0 -5
  8. data/lib/github_api/activity/notifications.rb +0 -5
  9. data/lib/github_api/api.rb +27 -22
  10. data/lib/github_api/api_factory.rb +13 -12
  11. data/lib/github_api/authorizations.rb +0 -5
  12. data/lib/github_api/client.rb +33 -33
  13. data/lib/github_api/configuration.rb +10 -2
  14. data/lib/github_api/connection.rb +2 -3
  15. data/lib/github_api/constants.rb +0 -3
  16. data/lib/github_api/gists.rb +2 -7
  17. data/lib/github_api/git_data.rb +10 -15
  18. data/lib/github_api/git_data/blobs.rb +0 -5
  19. data/lib/github_api/git_data/commits.rb +0 -5
  20. data/lib/github_api/git_data/references.rb +3 -7
  21. data/lib/github_api/git_data/tags.rb +0 -5
  22. data/lib/github_api/git_data/trees.rb +0 -5
  23. data/lib/github_api/gitignore.rb +0 -5
  24. data/lib/github_api/issues.rb +10 -15
  25. data/lib/github_api/issues/comments.rb +0 -5
  26. data/lib/github_api/issues/events.rb +0 -5
  27. data/lib/github_api/issues/labels.rb +0 -5
  28. data/lib/github_api/issues/milestones.rb +0 -5
  29. data/lib/github_api/markdown.rb +0 -5
  30. data/lib/github_api/meta.rb +0 -5
  31. data/lib/github_api/orgs.rb +4 -9
  32. data/lib/github_api/page_iterator.rb +44 -29
  33. data/lib/github_api/paged_request.rb +12 -12
  34. data/lib/github_api/{result.rb → pagination.rb} +19 -86
  35. data/lib/github_api/params_hash.rb +1 -1
  36. data/lib/github_api/pull_requests.rb +2 -7
  37. data/lib/github_api/repos.rb +22 -27
  38. data/lib/github_api/request.rb +7 -4
  39. data/lib/github_api/response/header.rb +76 -0
  40. data/lib/github_api/response_wrapper.rb +126 -0
  41. data/lib/github_api/scopes.rb +1 -1
  42. data/lib/github_api/search.rb +0 -5
  43. data/lib/github_api/users.rb +6 -11
  44. data/lib/github_api/version.rb +2 -2
  45. data/spec/github/activity/notifications/get_spec.rb +1 -1
  46. data/spec/github/activity/starring/starred_spec.rb +1 -1
  47. data/spec/github/activity/watching/watched_spec.rb +1 -1
  48. data/spec/github/api_factory_spec.rb +7 -8
  49. data/spec/github/api_spec.rb +0 -7
  50. data/spec/github/authorization_spec.rb +22 -32
  51. data/spec/github/authorizations/create_spec.rb +49 -0
  52. data/spec/github/authorizations/delete_spec.rb +39 -0
  53. data/spec/github/authorizations/get_spec.rb +49 -0
  54. data/spec/github/authorizations/list_spec.rb +55 -0
  55. data/spec/github/authorizations/update_spec.rb +50 -0
  56. data/spec/github/authorizations_spec.rb +2 -236
  57. data/spec/github/gists/comments/create_spec.rb +1 -1
  58. data/spec/github/gists/comments/edit_spec.rb +1 -1
  59. data/spec/github/gists/comments/get_spec.rb +1 -1
  60. data/spec/github/gists/create_spec.rb +1 -1
  61. data/spec/github/gists/edit_spec.rb +1 -1
  62. data/spec/github/gists/fork_spec.rb +1 -1
  63. data/spec/github/gists/get_spec.rb +1 -1
  64. data/spec/github/git_data/blobs/create_spec.rb +1 -1
  65. data/spec/github/git_data/blobs/get_spec.rb +1 -1
  66. data/spec/github/git_data/commits/create_spec.rb +1 -1
  67. data/spec/github/git_data/commits/get_spec.rb +1 -1
  68. data/spec/github/git_data/references/create_spec.rb +2 -2
  69. data/spec/github/git_data/references/get_spec.rb +1 -1
  70. data/spec/github/git_data/references/list_spec.rb +16 -6
  71. data/spec/github/git_data/tags/create_spec.rb +1 -1
  72. data/spec/github/git_data/tags/get_spec.rb +1 -1
  73. data/spec/github/git_data/trees/create_spec.rb +1 -1
  74. data/spec/github/git_data/trees/get_spec.rb +4 -4
  75. data/spec/github/issues/comments/create_spec.rb +1 -1
  76. data/spec/github/issues/comments/edit_spec.rb +1 -1
  77. data/spec/github/issues/comments/get_spec.rb +1 -1
  78. data/spec/github/issues/create_spec.rb +1 -1
  79. data/spec/github/issues/edit_spec.rb +1 -1
  80. data/spec/github/issues/events/get_spec.rb +1 -1
  81. data/spec/github/issues/get_spec.rb +1 -1
  82. data/spec/github/issues/labels/create_spec.rb +1 -1
  83. data/spec/github/issues/labels/get_spec.rb +1 -1
  84. data/spec/github/issues/labels/update_spec.rb +1 -1
  85. data/spec/github/issues/milestones/create_spec.rb +1 -1
  86. data/spec/github/issues/milestones/delete_spec.rb +1 -1
  87. data/spec/github/issues/milestones/get_spec.rb +1 -1
  88. data/spec/github/issues/milestones/update_spec.rb +1 -1
  89. data/spec/github/orgs/edit_spec.rb +1 -1
  90. data/spec/github/orgs/get_spec.rb +1 -1
  91. data/spec/github/orgs/teams/create_spec.rb +1 -1
  92. data/spec/github/orgs/teams/edit_spec.rb +1 -1
  93. data/spec/github/orgs/teams/get_spec.rb +1 -1
  94. data/spec/github/paged_request_spec.rb +34 -29
  95. data/spec/github/pagination/iterator/number_spec.rb +118 -0
  96. data/spec/github/pagination/iterator/sha_spec.rb +67 -0
  97. data/spec/github/pull_requests/comments/create_spec.rb +1 -1
  98. data/spec/github/pull_requests/comments/edit_spec.rb +1 -1
  99. data/spec/github/pull_requests/comments/get_spec.rb +1 -1
  100. data/spec/github/pull_requests/create_spec.rb +1 -1
  101. data/spec/github/pull_requests/get_spec.rb +1 -1
  102. data/spec/github/pull_requests/update_spec.rb +1 -1
  103. data/spec/github/repos/branch_spec.rb +1 -1
  104. data/spec/github/repos/comments/create_spec.rb +1 -1
  105. data/spec/github/repos/comments/get_spec.rb +1 -1
  106. data/spec/github/repos/comments/update_spec.rb +1 -1
  107. data/spec/github/repos/commits/get_spec.rb +1 -1
  108. data/spec/github/repos/create_spec.rb +1 -1
  109. data/spec/github/repos/downloads/create_spec.rb +1 -1
  110. data/spec/github/repos/downloads/get_spec.rb +1 -1
  111. data/spec/github/repos/edit_spec.rb +1 -1
  112. data/spec/github/repos/forks/create_spec.rb +1 -1
  113. data/spec/github/repos/get_spec.rb +1 -1
  114. data/spec/github/repos/hooks/create_spec.rb +1 -1
  115. data/spec/github/repos/hooks/edit_spec.rb +1 -1
  116. data/spec/github/repos/hooks/get_spec.rb +1 -1
  117. data/spec/github/repos/languages_spec.rb +1 -1
  118. data/spec/github/repos/merging/merge_spec.rb +1 -1
  119. data/spec/github/repos/statuses/create_spec.rb +1 -1
  120. data/spec/github/repos/tags_spec.rb +1 -1
  121. data/spec/github/repos/teams_spec.rb +1 -1
  122. data/spec/github/request/endpoint_spec.rb +24 -0
  123. data/spec/github/request/request_spec.rb +38 -0
  124. data/spec/github/{result_spec.rb → response_wrapper_spec.rb} +14 -13
  125. data/spec/github/users/emails/list_spec.rb +1 -1
  126. data/spec/github/users/get_spec.rb +2 -7
  127. data/spec/github/users/keys/create_spec.rb +1 -1
  128. data/spec/github/users/keys/get_spec.rb +1 -1
  129. data/spec/github/users/keys/update_spec.rb +1 -1
  130. data/spec/github/users/update_spec.rb +1 -1
  131. data/spec/github_spec.rb +1 -6
  132. data/spec/{github/activity → integration}/activity_spec.rb +0 -0
  133. data/spec/{github/gists → integration}/gists_spec.rb +2 -0
  134. data/spec/{github/git_data → integration}/git_data_spec.rb +0 -0
  135. data/spec/{github/issues → integration}/issues_spec.rb +2 -0
  136. data/spec/integration/options_spec.rb +103 -23
  137. data/spec/{github/orgs → integration}/orgs_spec.rb +0 -0
  138. data/spec/{github/pull_requests → integration}/pull_requests_spec.rb +0 -0
  139. data/spec/{github → integration}/repos_spec.rb +2 -0
  140. data/spec/{github/users → integration}/users_spec.rb +0 -0
  141. data/spec/shared/array_of_resources_behaviour.rb +1 -1
  142. metadata +55 -46
  143. data/lib/github_api/page_uri_processor.rb +0 -25
  144. data/lib/github_api/response/helpers.rb +0 -21
  145. data/spec/github/page_iterator_spec.rb +0 -260
  146. data/spec/github/response/helpers_spec.rb +0 -16
@@ -45,7 +45,7 @@ describe Github::GitData::Tags, '#create' do
45
45
 
46
46
  it "should return the resource" do
47
47
  tag = subject.create user, repo, inputs
48
- tag.should be_a Hashie::Mash
48
+ tag.should be_a Github::ResponseWrapper
49
49
  end
50
50
 
51
51
  it "should get the tag information" do
@@ -37,7 +37,7 @@ describe Github::GitData::Tags, '#get' do
37
37
 
38
38
  it "should return mash" do
39
39
  tag = subject.get user, repo, sha
40
- tag.should be_a Hashie::Mash
40
+ tag.should be_a Github::ResponseWrapper
41
41
  end
42
42
  end
43
43
 
@@ -46,7 +46,7 @@ describe Github::GitData::Trees, '#create' do
46
46
 
47
47
  it "should return the resource" do
48
48
  tree_sha = subject.create user, repo, inputs
49
- tree_sha.should be_a Hashie::Mash
49
+ tree_sha.should be_a Github::ResponseWrapper
50
50
  end
51
51
 
52
52
  it "should get the tree information" do
@@ -35,9 +35,9 @@ describe Github::GitData::Trees, '#get' do
35
35
  tree.sha.should eql sha
36
36
  end
37
37
 
38
- it "should return mash" do
38
+ it "should return response wrapper" do
39
39
  tree = subject.get user, repo, sha
40
- tree.should be_a Hashie::Mash
40
+ tree.should be_a Github::ResponseWrapper
41
41
  end
42
42
  end
43
43
 
@@ -56,9 +56,9 @@ describe Github::GitData::Trees, '#get' do
56
56
  tree.sha.should eql sha
57
57
  end
58
58
 
59
- it "should return mash" do
59
+ it "should return response wrapper" do
60
60
  tree = subject.get user, repo, sha, 'recursive' => true
61
- tree.should be_a Hashie::Mash
61
+ tree.should be_a Github::ResponseWrapper
62
62
  end
63
63
  end
64
64
 
@@ -34,7 +34,7 @@ describe Github::Issues::Comments, '#create' do
34
34
 
35
35
  it "should return the resource" do
36
36
  comment = subject.create user, repo, issue_id, inputs
37
- comment.should be_a Hashie::Mash
37
+ comment.should be_a Github::ResponseWrapper
38
38
  end
39
39
 
40
40
  it "should get the comment information" do
@@ -34,7 +34,7 @@ describe Github::Issues::Comments, '#edit' do
34
34
 
35
35
  it "should return the resource" do
36
36
  comment = subject.edit user, repo, comment_id, inputs
37
- comment.should be_a Hashie::Mash
37
+ comment.should be_a Github::ResponseWrapper
38
38
  end
39
39
 
40
40
  it "should get the comment information" do
@@ -38,7 +38,7 @@ describe Github::Issues::Comments, '#get' do
38
38
 
39
39
  it "should return mash" do
40
40
  comment = subject.get user, repo, comment_id
41
- comment.should be_a Hashie::Mash
41
+ comment.should be_a Github::ResponseWrapper
42
42
  end
43
43
  end
44
44
 
@@ -44,7 +44,7 @@ describe Github::Issues, '#create' do
44
44
 
45
45
  it "should return the resource" do
46
46
  issue = subject.create user, repo, inputs
47
- issue.should be_a Hashie::Mash
47
+ issue.should be_a Github::ResponseWrapper
48
48
  end
49
49
 
50
50
  it "should get the issue information" do
@@ -45,7 +45,7 @@ describe Github::Issues, '#edit' do
45
45
 
46
46
  it "should return resource" do
47
47
  issue = subject.edit user, repo, issue_id, inputs
48
- issue.should be_a Hashie::Mash
48
+ issue.should be_a Github::ResponseWrapper
49
49
  end
50
50
 
51
51
  it "should be able to retrieve information" do
@@ -38,7 +38,7 @@ describe Github::Issues::Events, '#list' do
38
38
 
39
39
  it "should return mash" do
40
40
  event = subject.get user, repo, event_id
41
- event.should be_a Hashie::Mash
41
+ event.should be_a Github::ResponseWrapper
42
42
  end
43
43
  end
44
44
 
@@ -38,7 +38,7 @@ describe Github::Issues, '#get' do
38
38
 
39
39
  it "should return mash" do
40
40
  issue = subject.get user, repo, issue_id
41
- issue.should be_a Hashie::Mash
41
+ issue.should be_a Github::ResponseWrapper
42
42
  end
43
43
  end
44
44
 
@@ -44,7 +44,7 @@ describe Github::Issues::Labels, '#create' do
44
44
 
45
45
  it "should return the resource" do
46
46
  label = subject.create user, repo, inputs
47
- label.should be_a Hashie::Mash
47
+ label.should be_a Github::ResponseWrapper
48
48
  end
49
49
 
50
50
  it "should get the label information" do
@@ -37,7 +37,7 @@ describe Github::Issues::Labels, '#get' do
37
37
 
38
38
  it "should return mash" do
39
39
  label = subject.get user, repo, label_id
40
- label.should be_a Hashie::Mash
40
+ label.should be_a Github::ResponseWrapper
41
41
  end
42
42
  end
43
43
 
@@ -45,7 +45,7 @@ describe Github::Issues::Labels, '#update' do
45
45
 
46
46
  it "should return the resource" do
47
47
  label = subject.update user, repo, label_id, inputs
48
- label.should be_a Hashie::Mash
48
+ label.should be_a Github::ResponseWrapper
49
49
  end
50
50
 
51
51
  it "should get the label information" do
@@ -40,7 +40,7 @@ describe Github::Issues::Milestones, '#create' do
40
40
 
41
41
  it "should return the resource" do
42
42
  milestone = subject.create user, repo, inputs
43
- milestone.should be_a Hashie::Mash
43
+ milestone.should be_a Github::ResponseWrapper
44
44
  end
45
45
 
46
46
  it "should get the milestone information" do
@@ -26,7 +26,7 @@ describe Github::Issues::Milestones, '#create' do
26
26
 
27
27
  it "should return the resource" do
28
28
  milestone = subject.delete user, repo, milestone_id
29
- milestone.should be_a Hashie::Mash
29
+ milestone.should be_a Github::ResponseWrapper
30
30
  end
31
31
 
32
32
  it "should get the milestone information" do
@@ -38,7 +38,7 @@ describe Github::Issues::Milestones, '#get' do
38
38
 
39
39
  it "should return mash" do
40
40
  milestone = subject.get user, repo, milestone_id
41
- milestone.should be_a Hashie::Mash
41
+ milestone.should be_a Github::ResponseWrapper
42
42
  end
43
43
  end
44
44
 
@@ -41,7 +41,7 @@ describe Github::Issues::Milestones, '#update' do
41
41
 
42
42
  it "should return the resource" do
43
43
  milestone = subject.update user, repo, milestone_id, inputs
44
- milestone.should be_a Hashie::Mash
44
+ milestone.should be_a Github::ResponseWrapper
45
45
  end
46
46
 
47
47
  it "should get the milestone information" do
@@ -38,7 +38,7 @@ describe Github::Orgs, '#edit' do
38
38
 
39
39
  it "should return resource" do
40
40
  organisation = subject.edit org
41
- organisation.should be_a Hashie::Mash
41
+ organisation.should be_a Github::ResponseWrapper
42
42
  end
43
43
 
44
44
  it "should be able to retrieve information" do
@@ -33,7 +33,7 @@ describe Github::Orgs, '#get' do
33
33
 
34
34
  it "should return mash" do
35
35
  organisation = subject.get org
36
- organisation.should be_a Hashie::Mash
36
+ organisation.should be_a Github::ResponseWrapper
37
37
  end
38
38
  end
39
39
 
@@ -42,7 +42,7 @@ describe Github::Orgs::Teams, '#create' do
42
42
 
43
43
  it "should return the resource" do
44
44
  team = subject.create org, inputs
45
- team.should be_a Hashie::Mash
45
+ team.should be_a Github::ResponseWrapper
46
46
  end
47
47
 
48
48
  it "should get the team information" do
@@ -41,7 +41,7 @@ describe Github::Orgs::Teams, '#edit' do
41
41
 
42
42
  it "should return the resource" do
43
43
  edited_team = subject.edit team, inputs
44
- edited_team.should be_a Hashie::Mash
44
+ edited_team.should be_a Github::ResponseWrapper
45
45
  end
46
46
 
47
47
  it "should get the team information" do
@@ -34,7 +34,7 @@ describe Github::Orgs::Teams, '#get' do
34
34
 
35
35
  it "should return mash" do
36
36
  team_res = subject.get team
37
- team_res.should be_a Hashie::Mash
37
+ team_res.should be_a Github::ResponseWrapper
38
38
  end
39
39
  end
40
40
 
@@ -2,39 +2,44 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Github::PagedRequest do
6
- it { described_class.constants.should include :FIRST_PAGE }
7
- it { described_class.constants.should include :PER_PAGE }
8
- it { described_class.constants.should include :NOT_FOUND }
9
-
10
- context 'page_request' do
11
- let(:path) { '/repos' }
12
- let(:client) { Github::Client }
13
-
14
- before do
15
- Github.stub(:api_client).and_return client
16
- client.stub(:get_request)
5
+ describe Github::PagedRequest, '#page_request' do
6
+ let(:current_api) { Github::Repos.new }
7
+ let(:path) { "/repositories/"}
8
+ let(:klass) {
9
+ klass = Class.new do
10
+ include Github::PagedRequest
17
11
  end
12
+ }
18
13
 
19
- it 'sets default per_page when only custom page passed' do
20
- Github.stub_chain(:api_client, :per_page).and_return nil
21
- Github::PagedRequest.page_request path, {'page' => 3, 'per_page' => -1}
22
- Github::PagedRequest.page.should eq 3
23
- Github::PagedRequest.per_page.should eq 30
24
- end
14
+ subject(:instance) { klass.new }
25
15
 
26
- it 'sets default page when only custom per_page passed' do
27
- Github.stub_chain(:api_client, :page).and_return nil
28
- Github::PagedRequest.page_request path, {'per_page' => 33, 'page' => -1}
29
- Github::PagedRequest.page.should eq 1
30
- Github::PagedRequest.per_page.should eq 33
31
- end
16
+ before {
17
+ instance.stub(:current_api).and_return current_api
18
+ }
32
19
 
33
- it 'sends get request with passed parameters' do
34
- Github::Client.should_receive(:get_request).
35
- with(path, 'page' => 2, 'per_page' => 33)
36
- Github::PagedRequest.page_request path, {'page' => 2, 'per_page' => 33}
37
- end
20
+ it { klass.constants.should include :FIRST_PAGE }
21
+
22
+ it { klass.constants.should include :PER_PAGE }
23
+
24
+ it { klass.constants.should include :NOT_FOUND }
25
+
26
+ it { should respond_to(:page_request) }
27
+
28
+ it 'calls get_request on api current instance' do
29
+ current_api.should_receive(:get_request).with(path, {})
30
+ instance.page_request(path)
31
+ end
32
+
33
+ it 'sets default per_page when only custom page passed' do
34
+ current_api.should_receive(:get_request).
35
+ with(path, {'page' => 3, 'per_page' => 30})
36
+ instance.page_request(path, {'page' => 3, 'per_page' => -1})
37
+ end
38
+
39
+ it 'sets default page when only custom per_page passed' do
40
+ current_api.should_receive(:get_request).
41
+ with(path, {'page' => 1, 'per_page' => 33})
42
+ instance.page_request(path, {'page' => -1, 'per_page' => 33})
38
43
  end
39
44
 
40
45
  end # Github::PagedRequest
@@ -0,0 +1,118 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::PageIterator, 'when number' do
6
+ let(:header) { {"Link" => "<https://api.github.com/users/wycats/repos?page=4&per_page=20>; rel=\"next\", <https://api.github.com/users/wycats/repos?page=6&per_page=20>; rel=\"last\", <https://api.github.com/users/wycats/repos?page=1&per_page=20>; rel=\"first\", <https://api.github.com/users/wycats/repos?page=2&per_page=20>; rel=\"prev\""}
7
+ }
8
+ let(:links) { Github::PageLinks.new(header) }
9
+
10
+ let(:first_link) { "https://api.github.com/users/wycats/repos?page=1&per_page=20" }
11
+ let(:next_link) { "https://api.github.com/users/wycats/repos?page=4&per_page=20" }
12
+ let(:prev_link) { "https://api.github.com/users/wycats/repos?page=2&per_page=20" }
13
+ let(:last_link) { "https://api.github.com/users/wycats/repos?page=6&per_page=20" }
14
+
15
+ let(:current_api) { Github::Repos.new }
16
+ let(:user) { 'wycats' }
17
+ let(:response) { stub(:response).as_null_object }
18
+
19
+ subject(:instance) { described_class.new(links, current_api) }
20
+
21
+ before {
22
+ instance.stub(:has_next?).and_return true
23
+ stub_get("/users/#{user}/repos").
24
+ with(:query => { 'page' => '4', 'per_page' => '20'}).
25
+ to_return(:body => '', :status => 200, :headers => header)
26
+ }
27
+
28
+ it { described_class::ATTRIBUTES.should_not be_nil }
29
+
30
+ its(:first_page) { should eq 1 }
31
+
32
+ its(:first_page_uri) { should eq first_link }
33
+
34
+ its(:next_page) { should eq 4 }
35
+
36
+ its(:next_page_uri) { should eq next_link}
37
+
38
+ its(:prev_page) { should eq 2 }
39
+
40
+ its(:prev_page_uri) { should eq prev_link }
41
+
42
+ its(:last_page) { should eq 6 }
43
+
44
+ its(:last_page_uri) { should eq last_link }
45
+
46
+ context 'has_next?' do
47
+ it "return true when next_page_uri is present" do
48
+ expect(instance.has_next?).to be_true
49
+ end
50
+ end
51
+
52
+ context 'first page request' do
53
+ it 'returns nil if there are no more pages' do
54
+ instance.stub(:first_page_uri).and_return false
55
+ expect(instance.first).to be_nil
56
+ end
57
+
58
+ it 'performs request' do
59
+ instance.should_receive(:page_request).
60
+ with("/users/#{user}/repos", 'per_page' => 20, 'page' => 1).
61
+ and_return response
62
+ instance.first
63
+ end
64
+ end
65
+
66
+ context 'next page request' do
67
+ it 'returns nil if there are no more pages' do
68
+ instance.stub(:has_next?).and_return false
69
+ expect(instance.next).to be_nil
70
+ end
71
+
72
+ it 'performs request' do
73
+ instance.should_receive(:page_request).with("/users/#{user}/repos",
74
+ 'page' => 4,'per_page' => 20).and_return response
75
+ instance.next
76
+ end
77
+ end
78
+
79
+ context 'prev page request' do
80
+ it 'returns nil if there are no more pages' do
81
+ instance.stub(:prev_page_uri).and_return false
82
+ expect(instance.prev).to be_nil
83
+ end
84
+
85
+ it 'performs request' do
86
+ instance.should_receive(:page_request).with("/users/#{user}/repos",
87
+ 'page' => 2,'per_page' => 20).and_return response
88
+ instance.prev
89
+ end
90
+ end
91
+
92
+ context 'last page request' do
93
+ it 'returns nil if there are no more pages' do
94
+ instance.stub(:last_page_uri).and_return false
95
+ expect(instance.last).to be_nil
96
+ end
97
+
98
+ it 'performs request' do
99
+ instance.should_receive(:page_request).with("/users/#{user}/repos",
100
+ 'page' => 6,'per_page' => 20).and_return response
101
+ instance.last
102
+ end
103
+ end
104
+
105
+ context 'get_page request' do
106
+ it 'returns nil if there are no more pages' do
107
+ instance.stub(:first_page_uri).and_return nil
108
+ instance.stub(:last_page_uri).and_return nil
109
+ expect(instance.get_page(5)).to be_nil
110
+ end
111
+
112
+ it 'performs request' do
113
+ instance.should_receive(:page_request).with("/users/#{user}/repos",
114
+ 'page' => 2,'per_page' => 20).and_return response
115
+ instance.get_page(2)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::PageIterator, 'when sha' do
6
+ let(:header) { {"Link" => "<https://api.github.com/repos/peter-murach/github/commits?last_sha=d1e503c02fa770859895dd0d12aedefa28b95723&per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd&top=801d80dfd59bf1d2cb30a243799953ab683a3abd>; rel=\"next\", <https://api.github.com/repos/peter-murach/github/commits?per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd>; rel=\"first\"" }
7
+ }
8
+ let(:links) { Github::PageLinks.new(header) }
9
+
10
+ let(:first_link) { "https://api.github.com/repos/peter-murach/github/commits?per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd" }
11
+ let(:next_link) { "https://api.github.com/repos/peter-murach/github/commits?last_sha=d1e503c02fa770859895dd0d12aedefa28b95723&per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd&top=801d80dfd59bf1d2cb30a243799953ab683a3abd" }
12
+
13
+ let(:top_sha) { '801d80dfd59bf1d2cb30a243799953ab683a3abd' }
14
+ let(:sha) { '801d80dfd59bf1d2cb30a243799953ab683a3abd' }
15
+ let(:last_sha) { "d1e503c02fa770859895dd0d12aedefa28b95723"}
16
+
17
+ let(:current_api) { Github::Repos.new }
18
+ let(:user) { 'wycats' }
19
+ let(:response) { stub(:response).as_null_object }
20
+
21
+ subject(:instance) { described_class.new(links, current_api) }
22
+
23
+ before {
24
+ instance.stub(:has_next?).and_return true
25
+ instance.stub(:next_page).and_return -1
26
+ stub_get("/repos/peter-murach/github/commits").
27
+ to_return(:body => '', :status => 200, :headers => header)
28
+ }
29
+
30
+ it { described_class::ATTRIBUTES.should_not be_nil }
31
+
32
+ its(:first_page) { should eq -1 }
33
+
34
+ its(:first_page_uri) { should eq first_link }
35
+
36
+ its(:next_page) { should eq -1 }
37
+
38
+ its(:next_page_uri) { should eq next_link}
39
+
40
+ its(:prev_page) { should eq -1 }
41
+
42
+ its(:prev_page_uri) { should be_nil }
43
+
44
+ its(:last_page) { should eq -1 }
45
+
46
+ its(:last_page_uri) { should be_nil }
47
+
48
+ context 'first page request' do
49
+ it 'performs request' do
50
+ instance.should_receive(:page_request).
51
+ with("/repos/peter-murach/github/commits",
52
+ 'sha' => 'master', 'per_page' => 30).and_return response
53
+ instance.first
54
+ end
55
+ end
56
+
57
+ context 'next page request' do
58
+ it 'performs request' do
59
+ instance.should_receive(:page_request).
60
+ with("/repos/peter-murach/github/commits", 'last_sha' => last_sha,
61
+ 'sha' => last_sha, 'per_page' => 30, 'top' => top_sha).
62
+ and_return response
63
+ instance.next
64
+ end
65
+ end
66
+
67
+ end