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,217 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::Keys do
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach'}
7
+ let(:repo) { 'github' }
8
+
9
+ it { described_class::VALID_KEY_PARAM_NAMES.should_not be_nil }
10
+
11
+ describe "keys" do
12
+ context "resource found" do
13
+ before do
14
+ stub_get("/repos/#{user}/#{repo}/keys").
15
+ to_return(:body => fixture("repos/keys.json"), :status => 200, :headers => {})
16
+ end
17
+
18
+ it "should fail to get resource without username" do
19
+ github.user, github.repo = nil, nil
20
+ expect { github.repos.keys }.to raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should get the resources" do
24
+ github.repos.keys(user, repo)
25
+ a_get("/repos/#{user}/#{repo}/keys").should have_been_made
26
+ end
27
+
28
+ it "should return array of resources" do
29
+ keys = github.repos.keys(user, repo)
30
+ keys.should be_an Array
31
+ keys.should have(1).items
32
+ end
33
+
34
+ it "should get key information" do
35
+ keys = github.repos.keys(user, repo)
36
+ keys.first.title.should == 'octocat@octomac'
37
+ end
38
+ end
39
+
40
+ context "resource not found" do
41
+ before do
42
+ stub_get("/repos/#{user}/#{repo}/keys").
43
+ to_return(:body => fixture("repos/keys.json"), :status => 404)
44
+ end
45
+
46
+ it "should fail to retrieve resource" do
47
+ expect {
48
+ github.repos.keys user, repo
49
+ }.to raise_error(Github::ResourceNotFound)
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ describe "get_key" do
56
+ let(:key_id) { 1 }
57
+
58
+ context "resource found" do
59
+ before do
60
+ stub_get("/repos/#{user}/#{repo}/keys/#{key_id}").
61
+ to_return(:body => fixture("repos/key.json"), :status => 200)
62
+ end
63
+
64
+ it "should fail to get resource without key" do
65
+ expect {
66
+ github.repos.get_key(user, repo, nil)
67
+ }.to raise_error(ArgumentError)
68
+ end
69
+
70
+ it "should get the resource" do
71
+ github.repos.get_key(user, repo, key_id)
72
+ a_get("/repos/#{user}/#{repo}/keys/#{key_id}").should have_been_made
73
+ end
74
+
75
+ it "should get key information" do
76
+ key = github.repos.get_key(user, repo, key_id)
77
+ key.id.should == key_id
78
+ end
79
+ end
80
+
81
+ context "resource not found" do
82
+ before do
83
+ stub_get("/repos/#{user}/#{repo}/keys/#{key_id}").
84
+ to_return(:body => fixture("repos/keys.json"), :status => 404)
85
+ end
86
+
87
+ it "should fail to retrieve resource" do
88
+ expect {
89
+ github.repos.get_key(user, repo, key_id)
90
+ }.to raise_error(Github::ResourceNotFound)
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "create_key" do
96
+ let(:inputs) { {:title => "octocat@octomac", :key => "ssh-rsa AAA..." } }
97
+
98
+ context "resource created" do
99
+ before do
100
+ stub_post("/repos/#{user}/#{repo}/keys").with(inputs).
101
+ to_return(:body => fixture("repos/key.json"), :status => 201)
102
+ end
103
+
104
+ it "should fail to create resource if 'title' input is missing" do
105
+ expect {
106
+ github.repos.create_key(user, repo, :key => 'ssh-rsa AAA...')
107
+ }.to raise_error(ArgumentError)
108
+ end
109
+
110
+ it "should fail to create resource if 'key' input is missing" do
111
+ expect {
112
+ github.repos.create_key(user, repo, :title => 'octocat@octomac')
113
+ }.to raise_error(ArgumentError)
114
+ end
115
+
116
+ it "should create the resource" do
117
+ github.repos.create_key(user, repo, inputs)
118
+ a_post("/repos/#{user}/#{repo}/keys").with(inputs).should have_been_made
119
+ end
120
+
121
+ it "should get the key information back" do
122
+ key = github.repos.create_key(user, repo, inputs)
123
+ key.title.should == 'octocat@octomac'
124
+ end
125
+ end
126
+
127
+ context "failed to create resource" do
128
+ before do
129
+ stub_post("/repos/#{user}/#{repo}/keys").
130
+ to_return(:body => fixture("repos/key.json"), :status => 404)
131
+ end
132
+
133
+ it "should fail to retrieve resource" do
134
+ expect {
135
+ github.repos.create_key(user, repo, inputs)
136
+ }.to raise_error(Github::ResourceNotFound)
137
+ end
138
+ end
139
+ end
140
+
141
+ describe "edit_key" do
142
+ let(:key_id) { 1 }
143
+ let(:inputs) { {:title => "octocat@octomac", :key => "ssh-rsa AAA..." } }
144
+
145
+ context "resource edited successfully" do
146
+ before do
147
+ stub_patch("/repos/#{user}/#{repo}/keys/#{key_id}").
148
+ to_return(:body => fixture("repos/key.json"), :status => 200)
149
+ end
150
+
151
+ it "should edit the resource" do
152
+ github.repos.edit_key(user, repo, key_id, inputs)
153
+ a_patch("/repos/#{user}/#{repo}/keys/#{key_id}").should have_been_made
154
+ end
155
+
156
+ it "should get the key information back" do
157
+ key = github.repos.edit_key(user, repo, key_id, inputs)
158
+ key.id.should == key_id
159
+ key.title.should == 'octocat@octomac'
160
+ end
161
+ end
162
+
163
+ context "failed to edit resource" do
164
+ before do
165
+ stub_patch("/repos/#{user}/#{repo}/keys/#{key_id}").
166
+ to_return(:body => fixture("repos/key.json"), :status => 404)
167
+ end
168
+
169
+ it "should fail to retrieve resource" do
170
+ expect {
171
+ github.repos.edit_key(user, repo, key_id, inputs)
172
+ }.to raise_error(Github::ResourceNotFound)
173
+ end
174
+ end
175
+
176
+ end
177
+
178
+ describe "delete_key" do
179
+ let(:key_id) { 1 }
180
+
181
+ context "resource found successfully" do
182
+ before do
183
+ stub_delete("/repos/#{user}/#{repo}/keys/#{key_id}").
184
+ to_return(:body => "", :status => 204, :headers => { :content_type => "application/json; charset=utf-8"} )
185
+ end
186
+
187
+ it "should fail to delete without 'user/repo' parameters" do
188
+ github.user, github.repo = nil, nil
189
+ expect { github.repos.delete_key }.to raise_error(ArgumentError)
190
+ end
191
+
192
+ it "should fail to delete resource without key id" do
193
+ expect {
194
+ github.repos.delete_key user, repo, nil
195
+ }.to raise_error(ArgumentError)
196
+ end
197
+
198
+ it "should delete the resource" do
199
+ github.repos.delete_key(user, repo, key_id)
200
+ a_delete("/repos/#{user}/#{repo}/keys/#{key_id}").should have_been_made
201
+ end
202
+ end
203
+
204
+ context "failed to find resource" do
205
+ before do
206
+ stub_delete("/repos/#{user}/#{repo}/keys/#{key_id}").
207
+ to_return(:body => "", :status => 404)
208
+ end
209
+ it "should fail to find resource" do
210
+ expect {
211
+ github.repos.delete_key(user, repo, key_id)
212
+ }.to raise_error(Github::ResourceNotFound)
213
+ end
214
+ end
215
+ end
216
+
217
+ end # Github::Repos::Keys
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::PubSubHubbub do
4
+
5
+ let(:github) { Github.new }
6
+ let(:topic) { "https://github.com/peter-murach/github/events/push"}
7
+ let(:callback) { "github://campfire?subdomain=github&room=Commits&token=abc123" }
8
+ let(:hub_inputs) {
9
+ {
10
+ "hub.mode" => 'subscribe',
11
+ "hub.topic" => topic,
12
+ "hub.callback" => callback,
13
+ "hub.verify" => 'sync',
14
+ "hub.secret" => ''
15
+ }
16
+ }
17
+
18
+ describe "subscribe" do
19
+ context "success" do
20
+ before do
21
+ github.oauth_token = OAUTH_TOKEN
22
+ stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).
23
+ to_return(:body => '', :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+
26
+ after do
27
+ github.oauth_token = nil
28
+ end
29
+
30
+ it "should subscribe to hub" do
31
+ github.repos.subscribe topic, callback
32
+ a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
33
+ end
34
+ end
35
+
36
+ context "failure" do
37
+ before do
38
+ github.oauth_token = OAUTH_TOKEN
39
+ stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).
40
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
41
+ end
42
+
43
+ it "should fail to subscribe to hub" do
44
+ expect {
45
+ github.repos.subscribe topic, callback
46
+ }.to raise_error(Github::ResourceNotFound)
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "unsubscribe" do
52
+ context "success" do
53
+ before do
54
+ github.oauth_token = OAUTH_TOKEN
55
+ stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs.merge("hub.mode" => 'unsubscribe')).
56
+ to_return(:body => '', :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
57
+ end
58
+
59
+ after do
60
+ github.oauth_token = nil
61
+ end
62
+
63
+ it "should subscribe to hub" do
64
+ github.repos.unsubscribe topic, callback
65
+ a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
66
+ end
67
+ end
68
+
69
+ context "failure" do
70
+ before do
71
+ github.oauth_token = OAUTH_TOKEN
72
+ stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs.merge("hub.mode" => 'unsubscribe')).
73
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
74
+ end
75
+
76
+ it "should fail to subscribe to hub" do
77
+ expect {
78
+ github.repos.unsubscribe topic, callback
79
+ }.to raise_error(Github::ResourceNotFound)
80
+ end
81
+ end
82
+ end
83
+ end # Github::Repos::PubSubHubbub
@@ -0,0 +1,222 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Watching do
6
+
7
+ let(:github) { Github.new }
8
+ let(:user) { 'peter-murach' }
9
+ let(:repo) { 'github' }
10
+
11
+ describe "watchers" do
12
+ before do
13
+ github.oauth_token = nil
14
+ stub_get("/repos/#{user}/#{repo}/watchers").
15
+ to_return(:body => fixture("repos/watchers.json"), :status => 200, :headers => {})
16
+ end
17
+
18
+ it "should fail to get resource without username" do
19
+ github.user, github.repo = nil, nil
20
+ expect { github.repos.watchers }.to raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should yield iterator if block given" do
24
+ github.repos.should_receive(:watchers).with(user, repo).and_yield('github')
25
+ github.repos.watchers(user, repo) { |param| 'github' }
26
+ end
27
+
28
+ it "should get the resources" do
29
+ github.repos.watchers(user, repo)
30
+ a_get("/repos/#{user}/#{repo}/watchers").should have_been_made
31
+ end
32
+
33
+ it "should return array of resources" do
34
+ watchers = github.repos.watchers(user, repo)
35
+ watchers.should be_an Array
36
+ watchers.should have(1).items
37
+ end
38
+
39
+ it "should return result of mash type" do
40
+ watchers = github.repos.watchers user, repo
41
+ watchers.first.should be_a Hashie::Mash
42
+ end
43
+
44
+ it "should get watcher information" do
45
+ watchers = github.repos.watchers(user, repo)
46
+ watchers.first.login.should == 'octocat'
47
+ end
48
+
49
+ context "fail to find resource" do
50
+ before do
51
+ stub_get("/repos/#{user}/#{repo}/watchers").
52
+ to_return(:body => "", :status => 404)
53
+ end
54
+
55
+ it "should return 404 not found message" do
56
+ lambda { github.repos.watchers(user, repo) }.should raise_error(Github::ResourceNotFound)
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ describe "watched" do
64
+
65
+ context "if user unauthenticated" do
66
+ before do
67
+ github.oauth_token = nil
68
+ WebMock.reset!
69
+ end
70
+
71
+ it "should fail to get resource without username " do
72
+ stub_get("/user/watched").
73
+ to_return(:body => fixture("repos/watched.json"), :status => 401, :headers => {})
74
+ expect {
75
+ github.user = nil
76
+ github.repos.watched
77
+ }.to raise_error(Github::Unauthorised)
78
+ end
79
+
80
+ it "should get the resource with username" do
81
+ stub_get("/users/#{user}/watched").
82
+ to_return(:body => fixture("repos/watched.json"), :status => 200, :headers => {})
83
+ github.repos.watched(user)
84
+ a_get("/users/#{user}/watched").should have_been_made
85
+ end
86
+ end
87
+
88
+ context "if user authenticated" do
89
+ before do
90
+ github.user = nil
91
+ github.oauth_token = OAUTH_TOKEN
92
+ stub_get("/user/watched?access_token=#{OAUTH_TOKEN}").
93
+ to_return(:body => fixture("repos/watched.json"), :status => 200, :headers => {})
94
+ end
95
+
96
+ it "should get the resources" do
97
+ github.repos.watched
98
+ a_get("/user/watched?access_token=#{OAUTH_TOKEN}").should have_been_made
99
+ end
100
+
101
+ it "should return array of resources" do
102
+ watched = github.repos.watched
103
+ watched.should be_an Array
104
+ watched.should have(1).items
105
+ end
106
+
107
+ it "should get watched information" do
108
+ watched = github.repos.watched
109
+ watched.first.name.should == 'Hello-World'
110
+ watched.first.owner.login.should == 'octocat'
111
+ end
112
+ end
113
+ end
114
+
115
+ describe "watching?" do
116
+
117
+ context "with username ane reponame passed" do
118
+
119
+ context "this repo is being watched by the user"
120
+ before do
121
+ github.oauth_token = nil
122
+ github.user = nil
123
+ stub_get("/user/watched/#{user}/#{repo}").
124
+ to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
125
+ end
126
+
127
+ it "should return false if resource not found" do
128
+ watching = github.repos.watching? user, repo
129
+ watching.should be_false
130
+ end
131
+
132
+ it "should return true if resoure found" do
133
+ stub_get("/user/watched/#{user}/#{repo}").
134
+ to_return(:body => "", :status => 200, :headers => {:user_agent => github.user_agent})
135
+ watching = github.repos.watching? user, repo
136
+ watching.should be_true
137
+ end
138
+
139
+ end
140
+
141
+ context "without username and reponame passed" do
142
+ it "should fail validation " do
143
+ expect { github.repos.watching?(nil, nil) }.to raise_error(ArgumentError)
144
+ end
145
+ end
146
+ end
147
+
148
+ describe "start_watching" do
149
+
150
+ context "user authenticated" do
151
+
152
+ context "with correct information" do
153
+ before do
154
+ github.user, github.repo = nil, nil
155
+ github.oauth_token = OAUTH_TOKEN
156
+ stub_put("/user/watched/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").
157
+ to_return(:body => "", :status => 204, :headers => {})
158
+ end
159
+
160
+ after do
161
+ github.oauth_token = nil # ensure authentication is reset
162
+ end
163
+
164
+ it "should successfully watch a repo" do
165
+ github.repos.start_watching(user, repo)
166
+ a_put("/user/watched/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").should have_been_made
167
+ end
168
+ end
169
+
170
+ context "without correct information" do
171
+
172
+ end
173
+ end
174
+
175
+ context "user unauthenticated" do
176
+ it "should fail" do
177
+ github.oauth_token = nil
178
+ stub_put("/user/watched/#{user}/#{repo}").
179
+ to_return(:body => "", :status => 401, :headers => {})
180
+ expect {
181
+ github.repos.start_watching(user, repo)
182
+ }.to raise_error(Github::Unauthorised)
183
+ end
184
+ end
185
+ end
186
+
187
+ describe "stop_watching" do
188
+
189
+ context "user authenticated" do
190
+
191
+ context "with correct information" do
192
+ before do
193
+ github.user, github.repo = nil, nil
194
+ github.oauth_token = OAUTH_TOKEN
195
+ stub_delete("/user/watched/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").
196
+ to_return(:body => "", :status => 204, :headers => {})
197
+ end
198
+
199
+ it "should successfully watch a repo" do
200
+ github.repos.stop_watching(user, repo)
201
+ a_delete("/user/watched/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").should have_been_made
202
+ end
203
+ end
204
+
205
+ context "without correct information" do
206
+
207
+ end
208
+ end
209
+
210
+ context "user unauthenticated" do
211
+ it "should fail" do
212
+ github.oauth_token = nil
213
+ stub_delete("/user/watched/#{user}/#{repo}").
214
+ to_return(:body => "", :status => 401, :headers => {})
215
+ expect {
216
+ github.repos.stop_watching(user, repo)
217
+ }.to raise_error(Github::Unauthorised)
218
+ end
219
+ end
220
+ end
221
+
222
+ end # Github::Respos::Watching