github_api 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.rdoc +228 -0
  3. data/Rakefile +52 -0
  4. data/features/github_api.feature +50 -0
  5. data/features/options.feature +4 -0
  6. data/features/pagination.feature +4 -0
  7. data/features/step_definitions/github_api_steps.rb +11 -0
  8. data/features/support/env.rb +13 -0
  9. data/lib/github_api.rb +73 -0
  10. data/lib/github_api/api.rb +175 -0
  11. data/lib/github_api/api/utils.rb +9 -0
  12. data/lib/github_api/authorization.rb +73 -0
  13. data/lib/github_api/authorizations.rb +119 -0
  14. data/lib/github_api/cache_control.rb +19 -0
  15. data/lib/github_api/client.rb +55 -0
  16. data/lib/github_api/compatibility.rb +23 -0
  17. data/lib/github_api/configuration.rb +96 -0
  18. data/lib/github_api/connection.rb +75 -0
  19. data/lib/github_api/core_ext/array.rb +14 -0
  20. data/lib/github_api/core_ext/hash.rb +42 -0
  21. data/lib/github_api/error.rb +35 -0
  22. data/lib/github_api/events.rb +202 -0
  23. data/lib/github_api/gists.rb +200 -0
  24. data/lib/github_api/gists/comments.rb +86 -0
  25. data/lib/github_api/git_data.rb +26 -0
  26. data/lib/github_api/git_data/blobs.rb +51 -0
  27. data/lib/github_api/git_data/commits.rb +78 -0
  28. data/lib/github_api/git_data/references.rb +113 -0
  29. data/lib/github_api/git_data/tags.rb +78 -0
  30. data/lib/github_api/git_data/trees.rb +89 -0
  31. data/lib/github_api/issues.rb +215 -0
  32. data/lib/github_api/issues/comments.rb +123 -0
  33. data/lib/github_api/issues/events.rb +54 -0
  34. data/lib/github_api/issues/labels.rb +191 -0
  35. data/lib/github_api/issues/milestones.rb +140 -0
  36. data/lib/github_api/mime_type.rb +55 -0
  37. data/lib/github_api/orgs.rb +95 -0
  38. data/lib/github_api/orgs/members.rb +120 -0
  39. data/lib/github_api/orgs/teams.rb +245 -0
  40. data/lib/github_api/pull_requests.rb +224 -0
  41. data/lib/github_api/pull_requests/comments.rb +144 -0
  42. data/lib/github_api/repos.rb +286 -0
  43. data/lib/github_api/repos/collaborators.rb +81 -0
  44. data/lib/github_api/repos/commits.rb +180 -0
  45. data/lib/github_api/repos/downloads.rb +155 -0
  46. data/lib/github_api/repos/forks.rb +48 -0
  47. data/lib/github_api/repos/hooks.rb +174 -0
  48. data/lib/github_api/repos/keys.rb +104 -0
  49. data/lib/github_api/repos/pub_sub_hubbub.rb +102 -0
  50. data/lib/github_api/repos/watching.rb +94 -0
  51. data/lib/github_api/request.rb +84 -0
  52. data/lib/github_api/request/basic_auth.rb +31 -0
  53. data/lib/github_api/request/caching.rb +33 -0
  54. data/lib/github_api/request/oauth2.rb +33 -0
  55. data/lib/github_api/response.rb +28 -0
  56. data/lib/github_api/response/helpers.rb +14 -0
  57. data/lib/github_api/response/jsonize.rb +26 -0
  58. data/lib/github_api/response/mashify.rb +24 -0
  59. data/lib/github_api/response/raise_error.rb +33 -0
  60. data/lib/github_api/result.rb +42 -0
  61. data/lib/github_api/users.rb +84 -0
  62. data/lib/github_api/users/emails.rb +49 -0
  63. data/lib/github_api/users/followers.rb +98 -0
  64. data/lib/github_api/users/keys.rb +84 -0
  65. data/lib/github_api/version.rb +12 -0
  66. data/spec/README.rdoc +22 -0
  67. data/spec/coverage_adapter.rb +15 -0
  68. data/spec/fixtures/auths/authorization.json +14 -0
  69. data/spec/fixtures/auths/authorizations.json +16 -0
  70. data/spec/fixtures/events/events.json +29 -0
  71. data/spec/fixtures/issues/comment.json +13 -0
  72. data/spec/fixtures/issues/comments.json +15 -0
  73. data/spec/fixtures/issues/event.json +13 -0
  74. data/spec/fixtures/issues/events.json +15 -0
  75. data/spec/fixtures/issues/issue.json +56 -0
  76. data/spec/fixtures/issues/issues.json +58 -0
  77. data/spec/fixtures/issues/milestone.json +18 -0
  78. data/spec/fixtures/issues/milestones.json +20 -0
  79. data/spec/fixtures/orgs/members.json +9 -0
  80. data/spec/fixtures/orgs/org.json +18 -0
  81. data/spec/fixtures/orgs/orgs.json +8 -0
  82. data/spec/fixtures/orgs/team.json +8 -0
  83. data/spec/fixtures/orgs/team_repos.json +29 -0
  84. data/spec/fixtures/orgs/teams.json +7 -0
  85. data/spec/fixtures/repos/branches.json +9 -0
  86. data/spec/fixtures/repos/collaborators.json +8 -0
  87. data/spec/fixtures/repos/commit.json +53 -0
  88. data/spec/fixtures/repos/commit_comment.json +16 -0
  89. data/spec/fixtures/repos/commit_comments.json +18 -0
  90. data/spec/fixtures/repos/commits.json +27 -0
  91. data/spec/fixtures/repos/contributors.json +8 -0
  92. data/spec/fixtures/repos/download.json +10 -0
  93. data/spec/fixtures/repos/download_s3.json +21 -0
  94. data/spec/fixtures/repos/downloads.json +12 -0
  95. data/spec/fixtures/repos/fork.json +27 -0
  96. data/spec/fixtures/repos/forks.json +29 -0
  97. data/spec/fixtures/repos/hook.json +15 -0
  98. data/spec/fixtures/repos/hooks.json +10 -0
  99. data/spec/fixtures/repos/key.json +6 -0
  100. data/spec/fixtures/repos/keys.json +8 -0
  101. data/spec/fixtures/repos/languages.json +4 -0
  102. data/spec/fixtures/repos/repo.json +90 -0
  103. data/spec/fixtures/repos/repo_comments.json +18 -0
  104. data/spec/fixtures/repos/repos.json +29 -0
  105. data/spec/fixtures/repos/tags.json +11 -0
  106. data/spec/fixtures/repos/teams.json +7 -0
  107. data/spec/fixtures/repos/watched.json +29 -0
  108. data/spec/fixtures/repos/watchers.json +8 -0
  109. data/spec/fixtures/users/user.json +32 -0
  110. data/spec/github/api_spec.rb +25 -0
  111. data/spec/github/authorization_spec.rb +176 -0
  112. data/spec/github/authorizations_spec.rb +242 -0
  113. data/spec/github/client_spec.rb +50 -0
  114. data/spec/github/core_ext/hash_spec.rb +44 -0
  115. data/spec/github/events_spec.rb +491 -0
  116. data/spec/github/gists/comments_spec.rb +5 -0
  117. data/spec/github/gists_spec.rb +5 -0
  118. data/spec/github/git_data/blobs_spec.rb +5 -0
  119. data/spec/github/git_data/commits_spec.rb +5 -0
  120. data/spec/github/git_data/references_spec.rb +5 -0
  121. data/spec/github/git_data/tags_spec.rb +5 -0
  122. data/spec/github/git_data/trees_spec.rb +5 -0
  123. data/spec/github/git_data_spec.rb +5 -0
  124. data/spec/github/issues/comments_spec.rb +254 -0
  125. data/spec/github/issues/events_spec.rb +153 -0
  126. data/spec/github/issues/labels_spec.rb +5 -0
  127. data/spec/github/issues/milestones_spec.rb +260 -0
  128. data/spec/github/issues_spec.rb +287 -0
  129. data/spec/github/mime_type_spec.rb +70 -0
  130. data/spec/github/orgs/members_spec.rb +275 -0
  131. data/spec/github/orgs/teams_spec.rb +563 -0
  132. data/spec/github/orgs_spec.rb +160 -0
  133. data/spec/github/repos/collaborators_spec.rb +169 -0
  134. data/spec/github/repos/commits_spec.rb +424 -0
  135. data/spec/github/repos/downloads_spec.rb +247 -0
  136. data/spec/github/repos/forks_spec.rb +108 -0
  137. data/spec/github/repos/hooks_spec.rb +333 -0
  138. data/spec/github/repos/keys_spec.rb +217 -0
  139. data/spec/github/repos/pub_sub_hubbub_spec.rb +83 -0
  140. data/spec/github/repos/watching_spec.rb +222 -0
  141. data/spec/github/repos_spec.rb +571 -0
  142. data/spec/github/result_spec.rb +43 -0
  143. data/spec/github/users_spec.rb +140 -0
  144. data/spec/github_spec.rb +109 -0
  145. data/spec/spec_helper.rb +86 -0
  146. data/spec/support/base.rb +13 -0
  147. metadata +149 -4
@@ -0,0 +1,160 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Orgs do
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:org) { 'github' }
8
+
9
+ describe "orgs" do
10
+ context "resource found for a user" do
11
+ before do
12
+ stub_get("/users/#{user}/orgs").
13
+ to_return(:body => fixture('orgs/orgs.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "should get the resources" do
17
+ github.orgs.orgs user
18
+ a_get("/users/#{user}/orgs").should have_been_made
19
+ end
20
+
21
+ it "should return array of resources" do
22
+ orgs = github.orgs.orgs user
23
+ orgs.should be_an Array
24
+ orgs.should have(1).items
25
+ end
26
+
27
+ it "should be a mash type" do
28
+ orgs = github.orgs.orgs user
29
+ orgs.first.should be_a Hashie::Mash
30
+ end
31
+
32
+ it "should get org information" do
33
+ orgs = github.orgs.orgs user
34
+ orgs.first.login.should == 'github'
35
+ end
36
+
37
+ it "should yield to a block" do
38
+ github.orgs.should_receive(:orgs).with(user).and_yield('web')
39
+ github.orgs.orgs(user) { |param| 'web' }
40
+ end
41
+ end
42
+
43
+ context "resource found for an au user" do
44
+ before do
45
+ github.user = nil
46
+ github.oauth_token = OAUTH_TOKEN
47
+ stub_get("/user/orgs?access_token=#{OAUTH_TOKEN}").
48
+ to_return(:body => fixture('orgs/orgs.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
49
+ end
50
+
51
+ after do
52
+ github.user, github.oauth_token = nil, nil
53
+ end
54
+
55
+ it "should get the resources" do
56
+ github.orgs.orgs
57
+ a_get("/user/orgs?access_token=#{OAUTH_TOKEN}").should have_been_made
58
+ end
59
+ end
60
+
61
+ context "resource not found for a user" do
62
+ before do
63
+ stub_get("/users/#{user}/orgs").
64
+ to_return(:body => "", :status => [404, "Not Found"])
65
+ end
66
+
67
+ it "should return 404 with a message 'Not Found'" do
68
+ expect {
69
+ github.orgs.orgs user
70
+ }.to raise_error(Github::ResourceNotFound)
71
+ end
72
+ end
73
+ end # orgs
74
+
75
+ describe "org" do
76
+ context "resource found" do
77
+ before do
78
+ stub_get("/orgs/#{org}").
79
+ to_return(:body => fixture('orgs/org.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
80
+ end
81
+
82
+ it "should fail to get resource without org name" do
83
+ expect { github.orgs.org }.to raise_error(ArgumentError)
84
+ end
85
+
86
+ it "should get the resource" do
87
+ github.orgs.org org
88
+ a_get("/orgs/#{org}").should have_been_made
89
+ end
90
+
91
+ it "should get org information" do
92
+ organisation = github.orgs.org org
93
+ organisation.id.should == 1
94
+ organisation.login.should == 'github'
95
+ end
96
+
97
+ it "should return mash" do
98
+ organisation = github.orgs.org org
99
+ organisation.should be_a Hashie::Mash
100
+ end
101
+ end
102
+
103
+ context "resource not found" do
104
+ before do
105
+ stub_get("/orgs/#{org}").
106
+ to_return(:body => fixture('orgs/org.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
107
+ end
108
+
109
+ it "should fail to retrive resource" do
110
+ expect {
111
+ github.orgs.org org
112
+ }.to raise_error(Github::ResourceNotFound)
113
+ end
114
+ end
115
+ end # org
116
+
117
+ describe "edit_org" do
118
+ let(:inputs) { { :billing_email => 'support@github.com', :blog => "https://github.com/blog", :company => "GitHub", :email => "support@github.com", :location => "San Francisco", :name => "github" } }
119
+
120
+ context "resource edited successfully" do
121
+ before do
122
+ stub_patch("/orgs/#{org}").with(inputs).
123
+ to_return(:body => fixture("orgs/org.json"), :status => 200, :headers => { :content_type => "application/json; charset=utf-8"})
124
+ end
125
+
126
+ it "should fail to edit without 'user/repo' parameters" do
127
+ expect { github.orgs.edit_org }.to raise_error(ArgumentError)
128
+ end
129
+
130
+ it "should edit the resource" do
131
+ github.orgs.edit_org org
132
+ a_patch("/orgs/#{org}").with(inputs).should have_been_made
133
+ end
134
+
135
+ it "should return resource" do
136
+ organisation = github.orgs.edit_org org
137
+ organisation.should be_a Hashie::Mash
138
+ end
139
+
140
+ it "should be able to retrieve information" do
141
+ organisation = github.orgs.edit_org org
142
+ organisation.name.should == 'github'
143
+ end
144
+ end
145
+
146
+ context "failed to edit resource" do
147
+ before do
148
+ stub_patch("/orgs/#{org}").with(inputs).
149
+ to_return(:body => fixture("orgs/org.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
150
+ end
151
+
152
+ it "should fail to find resource" do
153
+ expect {
154
+ github.orgs.edit_org org
155
+ }.to raise_error(Github::ResourceNotFound)
156
+ end
157
+ end
158
+ end # edit_org
159
+
160
+ end # Github::Orgs
@@ -0,0 +1,169 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::Collaborators do
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:collaborator) { 'octocat' }
9
+
10
+ describe "collaborators" do
11
+ context "resource found" do
12
+ before do
13
+ stub_get("/repos/#{user}/#{repo}/collaborators").
14
+ to_return(:body => fixture('repos/collaborators.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
15
+ end
16
+
17
+ it "should fail to get resource without username" do
18
+ github.user, github.repo = nil, nil
19
+ expect { github.repos.collaborators }.to raise_error(ArgumentError)
20
+ end
21
+
22
+ it "should get the resources" do
23
+ github.repos.collaborators user, repo
24
+ a_get("/repos/#{user}/#{repo}/collaborators").should have_been_made
25
+ end
26
+
27
+ it "should return array of resources" do
28
+ collaborators = github.repos.collaborators user, repo
29
+ collaborators.should be_an Array
30
+ collaborators.should have(1).items
31
+ end
32
+
33
+ it "should be a mash type" do
34
+ collaborators = github.repos.collaborators user, repo
35
+ collaborators.first.should be_a Hashie::Mash
36
+ end
37
+
38
+ it "should get collaborator information" do
39
+ collaborators = github.repos.collaborators user, repo
40
+ collaborators.first.login.should == 'octocat'
41
+ end
42
+
43
+ it "should yield to a block" do
44
+ github.repos.should_receive(:collaborators).with(user, repo).and_yield('web')
45
+ github.repos.collaborators(user, repo) { |param| 'web' }
46
+ end
47
+ end
48
+
49
+ context "resource not found" do
50
+ before do
51
+ stub_get("/repos/#{user}/#{repo}/collaborators").
52
+ to_return(:body => "", :status => [404, "Not Found"], :headers => {:content_type => "application/json; charset=utf-8"})
53
+ end
54
+
55
+ it "should return 404 with a message 'Not Found'" do
56
+ expect {
57
+ github.repos.collaborators user, repo
58
+ }.to raise_error(Github::ResourceNotFound)
59
+ end
60
+ end
61
+ end # collaborators
62
+
63
+
64
+ describe "collaborator?" do
65
+ context "resource found " do
66
+ before do
67
+ stub_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
68
+ to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
69
+ end
70
+
71
+ it "should fail to get resource without collaborator name" do
72
+ expect {
73
+ github.repos.collaborator?(user, repo, nil)
74
+ }.to raise_error(ArgumentError)
75
+ end
76
+
77
+ it "should get the resource" do
78
+ github.repos.collaborator? user, repo, collaborator
79
+ a_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").should have_been_made
80
+ end
81
+
82
+ it "should find collaborator" do
83
+ github.repos.should_receive(:collaborator?).with(user, repo, collaborator).and_return true
84
+ github.repos.collaborator? user, repo, collaborator
85
+ end
86
+ end
87
+
88
+ context "resource not found" do
89
+ before do
90
+ stub_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
91
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
92
+ end
93
+
94
+ it "should fail to retrieve resource" do
95
+ github.repos.should_receive(:collaborator?).with(user, repo, collaborator).and_return false
96
+ github.repos.collaborator? user, repo, collaborator
97
+ end
98
+ end
99
+ end # collaborator?
100
+
101
+ describe "add_collaborator" do
102
+
103
+ context "resouce added" do
104
+ before do
105
+ stub_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
106
+ to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
107
+ end
108
+
109
+ it "should fail to add resource if 'collaborator' input is missing" do
110
+ expect {
111
+ github.repos.add_collaborator user, repo, nil
112
+ }.to raise_error(ArgumentError)
113
+ end
114
+
115
+ it "should add resource successfully" do
116
+ github.repos.add_collaborator user, repo, collaborator
117
+ a_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").should have_been_made
118
+ end
119
+ end
120
+
121
+ context "failed to add resource" do
122
+ before do
123
+ stub_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
124
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
125
+ end
126
+
127
+ it "should fail to add resource" do
128
+ expect {
129
+ github.repos.add_collaborator user, repo, collaborator
130
+ }.to raise_error(Github::ResourceNotFound)
131
+ end
132
+ end
133
+ end # add_collaborator
134
+
135
+ describe "remove_collaborator" do
136
+
137
+ context "resouce added" do
138
+ before do
139
+ stub_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
140
+ to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
141
+ end
142
+
143
+ it "should fail to add resource if 'collaborator' input is missing" do
144
+ expect {
145
+ github.repos.remove_collaborator user, repo, nil
146
+ }.to raise_error(ArgumentError)
147
+ end
148
+
149
+ it "should add resource successfully" do
150
+ github.repos.remove_collaborator user, repo, collaborator
151
+ a_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").should have_been_made
152
+ end
153
+ end
154
+
155
+ context "failed to remove resource" do
156
+ before do
157
+ stub_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
158
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
159
+ end
160
+
161
+ it "should fail to remove resource" do
162
+ expect {
163
+ github.repos.remove_collaborator user, repo, collaborator
164
+ }.to raise_error(Github::ResourceNotFound)
165
+ end
166
+ end
167
+ end # remove_collaborator
168
+
169
+ end # Github::Repos::Collaborators
@@ -0,0 +1,424 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::Commits do
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ describe "commits" do
10
+ context "resource found" do
11
+ before do
12
+ stub_get("/repos/#{user}/#{repo}/commits").
13
+ to_return(:body => fixture('repos/commits.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "should fail to get resource without username" do
17
+ github.user, github.repo = nil, nil
18
+ expect { github.repos.commits }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ it "should get the resources" do
22
+ github.repos.commits user, repo
23
+ a_get("/repos/#{user}/#{repo}/commits").should have_been_made
24
+ end
25
+
26
+ it "should return array of resources" do
27
+ commits = github.repos.commits user, repo
28
+ commits.should be_an Array
29
+ commits.should have(1).items
30
+ end
31
+
32
+ it "should be a mash type" do
33
+ commits = github.repos.commits user, repo
34
+ commits.first.should be_a Hashie::Mash
35
+ end
36
+
37
+ it "should get commit information" do
38
+ commits = github.repos.commits user, repo
39
+ commits.first.author.name.should == 'Scott Chacon'
40
+ end
41
+
42
+ it "should yield to a block" do
43
+ github.repos.should_receive(:commits).with(user, repo).and_yield('web')
44
+ github.repos.commits(user, repo) { |param| 'web' }
45
+ end
46
+ end
47
+
48
+ context "resource not found" do
49
+ before do
50
+ stub_get("/repos/#{user}/#{repo}/commits").
51
+ to_return(:body => "", :status => [404, "Not Found"])
52
+ end
53
+
54
+ it "should return 404 with a message 'Not Found'" do
55
+ expect {
56
+ github.repos.commits user, repo
57
+ }.to raise_error(Github::ResourceNotFound)
58
+ end
59
+ end
60
+ end # commits
61
+
62
+ describe "commit" do
63
+ let(:sha) { '23432dfosfsufd' }
64
+
65
+ context "resource found" do
66
+ before do
67
+ stub_get("/repos/#{user}/#{repo}/commits/#{sha}").
68
+ to_return(:body => fixture('repos/commit.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
69
+ end
70
+
71
+ it "should fail to get resource without sha key" do
72
+ expect {
73
+ github.repos.commit(user, repo, nil)
74
+ }.to raise_error(ArgumentError)
75
+ end
76
+
77
+ it "should get the resource" do
78
+ github.repos.commit user, repo, sha
79
+ a_get("/repos/#{user}/#{repo}/commits/#{sha}").should have_been_made
80
+ end
81
+
82
+ it "should get commit information" do
83
+ commit = github.repos.commit user, repo, sha
84
+ commit.commit.author.name.should == 'Monalisa Octocat'
85
+ end
86
+
87
+ it "should return mash" do
88
+ commit = github.repos.commit user, repo, sha
89
+ commit.should be_a Hashie::Mash
90
+ end
91
+
92
+ end
93
+
94
+ context "resource not found" do
95
+ before do
96
+ stub_get("/repos/#{user}/#{repo}/commits/#{sha}").
97
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
98
+ end
99
+
100
+ it "should fail to retrive resource" do
101
+ expect {
102
+ github.repos.commit user, repo, sha
103
+ }.to raise_error(Github::ResourceNotFound)
104
+ end
105
+ end
106
+ end # commit
107
+
108
+ describe "commit comments" do
109
+ context "resource found" do
110
+ before do
111
+ stub_get("/repos/#{user}/#{repo}/comments").
112
+ to_return(:body => fixture('repos/repo_comments.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
113
+ end
114
+
115
+ it "should fail to get resource without username" do
116
+ github.user, github.repo = nil, nil
117
+ expect { github.repos.repo_comments }.to raise_error(ArgumentError)
118
+ end
119
+
120
+ it "should get the resources" do
121
+ github.repos.repo_comments user, repo
122
+ a_get("/repos/#{user}/#{repo}/comments").should have_been_made
123
+ end
124
+
125
+ it "should return array of resources" do
126
+ repo_comments = github.repos.repo_comments user, repo
127
+ repo_comments.should be_an Array
128
+ repo_comments.should have(1).items
129
+ end
130
+
131
+ it "should be a mash type" do
132
+ repo_comments = github.repos.repo_comments user, repo
133
+ repo_comments.first.should be_a Hashie::Mash
134
+ end
135
+
136
+ it "should get commit comment information" do
137
+ repo_comments = github.repos.repo_comments user, repo
138
+ repo_comments.first.user.login.should == 'octocat'
139
+ end
140
+
141
+ it "should yield to a block" do
142
+ github.repos.should_receive(:repo_comments).with(user, repo).and_yield('web')
143
+ github.repos.repo_comments(user, repo) { |param| 'web' }
144
+ end
145
+ end
146
+
147
+ context "resource not found" do
148
+ before do
149
+ stub_get("/repos/#{user}/#{repo}/comments").
150
+ to_return(:body => "", :status => [404, "Not Found"])
151
+ end
152
+
153
+ it "should return 404 with a message 'Not Found'" do
154
+ expect {
155
+ github.repos.repo_comments user, repo
156
+ }.to raise_error(Github::ResourceNotFound)
157
+ end
158
+ end
159
+ end # repo comments
160
+
161
+ describe "commit_comments" do
162
+ let(:sha) { '23432dfosfsufd' }
163
+
164
+ context "resource found" do
165
+ before do
166
+ stub_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").
167
+ to_return(:body => fixture('repos/commit_comments.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
168
+ end
169
+
170
+ it "should fail to get resource without sha key" do
171
+ expect {
172
+ github.repos.commit_comments(user, repo, nil)
173
+ }.to raise_error(ArgumentError)
174
+ end
175
+
176
+ it "should get the resource" do
177
+ github.repos.commit_comments user, repo, sha
178
+ a_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").should have_been_made
179
+ end
180
+
181
+ it "should return array of resources" do
182
+ commit_comments = github.repos.commit_comments user, repo, sha
183
+ commit_comments.should be_an Array
184
+ commit_comments.should have(1).items
185
+ end
186
+
187
+ it "should be a mash type" do
188
+ commit_comments = github.repos.commit_comments user, repo, sha
189
+ commit_comments.first.should be_a Hashie::Mash
190
+ end
191
+
192
+ it "should get commit comment information" do
193
+ commit_comments = github.repos.commit_comments user, repo, sha
194
+ commit_comments.first.user.login.should == 'octocat'
195
+ end
196
+
197
+ it "should yield to a block" do
198
+ github.repos.should_receive(:commit_comments).with(user, repo, sha).and_yield('web')
199
+ github.repos.commit_comments(user, repo, sha) { |param| 'web' }
200
+ end
201
+ end
202
+
203
+ context "resource not found" do
204
+ before do
205
+ stub_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").
206
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
207
+ end
208
+
209
+ it "should fail to retrive resource" do
210
+ expect {
211
+ github.repos.commit_comments user, repo, sha
212
+ }.to raise_error(Github::ResourceNotFound)
213
+ end
214
+ end
215
+ end # commit_comments
216
+
217
+ describe "commit_comment" do
218
+ let(:comment_id) { 1 }
219
+
220
+ context "resource found" do
221
+ before do
222
+ stub_get("/repos/#{user}/#{repo}/comments/#{comment_id}").
223
+ to_return(:body => fixture('repos/commit_comment.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
224
+ end
225
+
226
+ it "should fail to get resource without comment id" do
227
+ expect {
228
+ github.repos.commit_comment user, repo, nil
229
+ }.to raise_error(ArgumentError)
230
+ end
231
+
232
+ it "should get the resource" do
233
+ github.repos.commit_comment user, repo, comment_id
234
+ a_get("/repos/#{user}/#{repo}/comments/#{comment_id}").should have_been_made
235
+ end
236
+
237
+ it "should get commit comment information" do
238
+ commit_comment = github.repos.commit_comment user, repo, comment_id
239
+ commit_comment.user.login.should == 'octocat'
240
+ end
241
+
242
+ it "should return mash" do
243
+ commit_comment = github.repos.commit_comment user, repo, comment_id
244
+ commit_comment.should be_a Hashie::Mash
245
+ end
246
+
247
+ end
248
+
249
+ context "resource not found" do
250
+ before do
251
+ stub_get("/repos/#{user}/#{repo}/comments/#{comment_id}").
252
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
253
+ end
254
+
255
+ it "should fail to retrive resource" do
256
+ expect {
257
+ github.repos.commit_comment user, repo, comment_id
258
+ }.to raise_error(Github::ResourceNotFound)
259
+ end
260
+ end
261
+ end # commit_comment
262
+
263
+ describe "create_comment" do
264
+ let(:sha) { '23432dfosfsufd' }
265
+ let(:inputs) { {'body'=> 'web', :commit_id => 1, :line => 1, :path => 'file1.txt', :position => 4 } }
266
+
267
+ context "resouce created" do
268
+ before do
269
+ stub_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).
270
+ to_return(:body => fixture('repos/commit_comment.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
271
+
272
+ end
273
+
274
+ it "should fail to create resource if 'body' input is missing" do
275
+ expect {
276
+ github.repos.create_comment user, repo, sha, inputs.except('body')
277
+ }.to raise_error(ArgumentError)
278
+ end
279
+
280
+ it "should fail to create resource if 'commit_id' input is missing" do
281
+ expect {
282
+ github.repos.create_comment user, repo, sha, inputs.except(:commit_id)
283
+ }.to raise_error(ArgumentError)
284
+ end
285
+
286
+ it "should fail to create resource if 'line' input is missing" do
287
+ expect {
288
+ github.repos.create_comment user, repo, sha, inputs.except(:line)
289
+ }.to raise_error(ArgumentError)
290
+ end
291
+
292
+ it "should fail to create resource if 'path' input is missing" do
293
+ expect {
294
+ github.repos.create_comment user, repo, sha, inputs.except(:path)
295
+ }.to raise_error(ArgumentError)
296
+ end
297
+
298
+ it "should fail to create resource if 'position' input is missing" do
299
+ expect {
300
+ github.repos.create_comment user, repo, sha, inputs.except(:position)
301
+ }.to raise_error(ArgumentError)
302
+ end
303
+
304
+ it "should create resource successfully" do
305
+ github.repos.create_comment user, repo, sha, inputs
306
+ a_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).should have_been_made
307
+ end
308
+
309
+ it "should return the resource" do
310
+ comment = github.repos.create_comment user, repo, sha, inputs
311
+ comment.should be_a Hashie::Mash
312
+ end
313
+
314
+ it "should get the commit comment information" do
315
+ comment = github.repos.create_comment user, repo, sha, inputs
316
+ comment.user.login.should == 'octocat'
317
+ end
318
+ end
319
+
320
+ context "failed to create resource" do
321
+ before do
322
+ stub_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).
323
+ to_return(:body => fixture('repos/commit_comment.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
324
+
325
+ end
326
+
327
+ it "should fail to retrieve resource" do
328
+ expect {
329
+ github.repos.create_comment user, repo, sha, inputs
330
+ }.to raise_error(Github::ResourceNotFound)
331
+ end
332
+ end
333
+ end # create_comment
334
+
335
+ describe "delete_comment" do
336
+ let(:comment_id) { 1 }
337
+
338
+ context "resource deleted successfully" do
339
+ before do
340
+ stub_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").
341
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
342
+ end
343
+
344
+ it "should fail to delete without 'user/repo' parameters" do
345
+ github.user, github.repo = nil, nil
346
+ expect { github.repos.delete_comment }.to raise_error(ArgumentError)
347
+ end
348
+
349
+ it "should fail to delete resource without 'comment_id'" do
350
+ expect {
351
+ github.repos.delete_comment user, repo, nil
352
+ }.to raise_error(ArgumentError)
353
+ end
354
+
355
+ it "should delete the resource" do
356
+ github.repos.delete_comment user, repo, comment_id
357
+ a_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").should have_been_made
358
+ end
359
+ end
360
+
361
+ context "failed to delete resource" do
362
+ before do
363
+ stub_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").
364
+ to_return(:body => '', :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
365
+
366
+ end
367
+
368
+ it "should fail to find resource" do
369
+ expect {
370
+ github.repos.delete_comment user, repo, comment_id
371
+ }.to raise_error(Github::ResourceNotFound)
372
+ end
373
+ end
374
+ end # delete_comment
375
+
376
+ describe "update_comment" do
377
+ let(:comment_id) { 1 }
378
+ let(:inputs) { {'body'=> 'web'} }
379
+
380
+ context "resouce created" do
381
+ before do
382
+ stub_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).
383
+ to_return(:body => fixture('repos/commit_comment.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
384
+
385
+ end
386
+
387
+ it "should fail to create resource if 'body' input is missing" do
388
+ expect {
389
+ github.repos.update_comment user, repo, comment_id, inputs.except('body')
390
+ }.to raise_error(ArgumentError)
391
+ end
392
+
393
+ it "should create resource successfully" do
394
+ github.repos.update_comment user, repo, comment_id, inputs
395
+ a_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).should have_been_made
396
+ end
397
+
398
+ it "should return the resource" do
399
+ comment = github.repos.update_comment user, repo, comment_id, inputs
400
+ comment.should be_a Hashie::Mash
401
+ end
402
+
403
+ it "should get the commit comment information" do
404
+ comment = github.repos.update_comment user, repo, comment_id, inputs
405
+ comment.user.login.should == 'octocat'
406
+ end
407
+ end
408
+
409
+ context "failed to update resource" do
410
+ before do
411
+ stub_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).
412
+ to_return(:body => fixture('repos/commit_comment.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
413
+
414
+ end
415
+
416
+ it "should fail to retrieve resource" do
417
+ expect {
418
+ github.repos.update_comment user, repo, comment_id, inputs
419
+ }.to raise_error(Github::ResourceNotFound)
420
+ end
421
+ end
422
+ end # update_comment
423
+
424
+ end # Github::Repos::Commits