github_api 0.4.11 → 0.5.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data/README.md +76 -72
  2. data/features/cassettes/gists/starred.yml +48 -0
  3. data/features/cassettes/pagination/repos/commits/list.yml +193 -0
  4. data/features/cassettes/pagination/repos/commits/next.yml +183 -0
  5. data/features/cassettes/pagination/repos/diff/next.yml +45 -0
  6. data/features/cassettes/pagination/repos/list.yml +176 -0
  7. data/features/cassettes/pagination/repos/list/next.yml +222 -0
  8. data/features/cassettes/pagination/repos/per_page/each_page.yml +45 -0
  9. data/features/cassettes/repos/list.yml +92 -0
  10. data/features/error_codes.feature +1 -1
  11. data/features/gists.feature +12 -3
  12. data/features/gists/comments.feature +3 -3
  13. data/features/github_api.feature +13 -2
  14. data/features/pagination.feature +40 -39
  15. data/features/repos.feature +2 -2
  16. data/features/step_definitions/common_steps.rb +12 -0
  17. data/features/step_definitions/github_api_steps.rb +12 -1
  18. data/lib/github_api.rb +1 -1
  19. data/lib/github_api/api.rb +4 -2
  20. data/lib/github_api/api_factory.rb +11 -5
  21. data/lib/github_api/authorizations.rb +23 -32
  22. data/lib/github_api/client.rb +1 -0
  23. data/lib/github_api/events.rb +38 -38
  24. data/lib/github_api/filter.rb +1 -1
  25. data/lib/github_api/gists.rb +47 -42
  26. data/lib/github_api/gists/comments.rb +77 -84
  27. data/lib/github_api/git_data.rb +25 -6
  28. data/lib/github_api/git_data/blobs.rb +48 -45
  29. data/lib/github_api/git_data/commits.rb +76 -73
  30. data/lib/github_api/git_data/references.rb +137 -118
  31. data/lib/github_api/git_data/tags.rb +74 -70
  32. data/lib/github_api/git_data/trees.rb +88 -85
  33. data/lib/github_api/issues.rb +43 -31
  34. data/lib/github_api/issues/comments.rb +116 -119
  35. data/lib/github_api/issues/events.rb +20 -19
  36. data/lib/github_api/issues/labels.rb +200 -197
  37. data/lib/github_api/issues/milestones.rb +137 -134
  38. data/lib/github_api/orgs.rb +27 -23
  39. data/lib/github_api/orgs/members.rb +105 -108
  40. data/lib/github_api/orgs/teams.rb +236 -237
  41. data/lib/github_api/paged_request.rb +1 -1
  42. data/lib/github_api/pull_requests.rb +40 -42
  43. data/lib/github_api/pull_requests/comments.rb +140 -143
  44. data/lib/github_api/repos.rb +101 -67
  45. data/lib/github_api/repos/collaborators.rb +64 -68
  46. data/lib/github_api/repos/commits.rb +50 -39
  47. data/lib/github_api/repos/downloads.rb +107 -110
  48. data/lib/github_api/repos/forks.rb +38 -39
  49. data/lib/github_api/repos/hooks.rb +161 -167
  50. data/lib/github_api/repos/keys.rb +86 -86
  51. data/lib/github_api/repos/pub_sub_hubbub.rb +99 -87
  52. data/lib/github_api/repos/watching.rb +80 -82
  53. data/lib/github_api/request.rb +5 -9
  54. data/lib/github_api/users.rb +26 -16
  55. data/lib/github_api/users/emails.rb +47 -47
  56. data/lib/github_api/users/followers.rb +85 -86
  57. data/lib/github_api/users/keys.rb +73 -75
  58. data/lib/github_api/validations.rb +25 -0
  59. data/lib/github_api/validations/format.rb +23 -0
  60. data/lib/github_api/validations/presence.rb +25 -0
  61. data/lib/github_api/validations/required.rb +21 -0
  62. data/lib/github_api/validations/token.rb +41 -0
  63. data/lib/github_api/version.rb +3 -3
  64. data/spec/fixtures/repos/commit_comparison.json +112 -0
  65. data/spec/github/api_factory_spec.rb +17 -1
  66. data/spec/github/authorizations_spec.rb +36 -34
  67. data/spec/github/gists/comments_spec.rb +39 -45
  68. data/spec/github/gists_spec.rb +50 -53
  69. data/spec/github/git_data/blobs_spec.rb +27 -20
  70. data/spec/github/git_data/commits_spec.rb +20 -19
  71. data/spec/github/git_data/references_spec.rb +83 -46
  72. data/spec/github/git_data/tags_spec.rb +16 -15
  73. data/spec/github/git_data/trees_spec.rb +20 -19
  74. data/spec/github/git_data_spec.rb +10 -1
  75. data/spec/github/issues/comments_spec.rb +78 -68
  76. data/spec/github/issues/events_spec.rb +42 -34
  77. data/spec/github/issues/labels_spec.rb +89 -101
  78. data/spec/github/issues/milestones_spec.rb +76 -54
  79. data/spec/github/issues_spec.rb +53 -57
  80. data/spec/github/orgs/members_spec.rb +64 -49
  81. data/spec/github/orgs/teams_spec.rb +112 -101
  82. data/spec/github/orgs_spec.rb +41 -31
  83. data/spec/github/paged_request_spec.rb +6 -5
  84. data/spec/github/pull_requests/comments_spec.rb +39 -44
  85. data/spec/github/pull_requests_spec.rb +32 -48
  86. data/spec/github/repos/collaborators_spec.rb +40 -29
  87. data/spec/github/repos/commits_spec.rb +108 -64
  88. data/spec/github/repos/downloads_spec.rb +46 -45
  89. data/spec/github/repos/forks_spec.rb +23 -24
  90. data/spec/github/repos/hooks_spec.rb +69 -71
  91. data/spec/github/repos/keys_spec.rb +39 -34
  92. data/spec/github/repos/pub_sub_hubbub_spec.rb +4 -4
  93. data/spec/github/repos/watching_spec.rb +31 -33
  94. data/spec/github/repos_spec.rb +74 -83
  95. data/spec/github/request_spec.rb +31 -2
  96. data/spec/github/users/emails_spec.rb +19 -17
  97. data/spec/github/users/followers_spec.rb +30 -28
  98. data/spec/github/users/keys_spec.rb +37 -33
  99. data/spec/github/users_spec.rb +124 -125
  100. data/spec/github/validations/format_spec.rb +42 -0
  101. data/spec/github/validations/presence_spec.rb +18 -0
  102. data/spec/github/validations/required_spec.rb +28 -0
  103. data/spec/github/validations/token_spec.rb +19 -0
  104. data/spec/github/validations_spec.rb +23 -0
  105. metadata +33 -10
  106. data/features/cassettes/pagination/repos.yml +0 -177
  107. data/features/cassettes/pagination/repos/next.yml +0 -177
  108. data/lib/github_api/validation.rb +0 -53
  109. data/spec/github/validation_spec.rb +0 -62
@@ -9,30 +9,33 @@ describe Github::Repos::Keys do
9
9
 
10
10
  it { described_class::VALID_KEY_PARAM_NAMES.should_not be_nil }
11
11
 
12
- describe "keys" do
12
+ describe "#list" do
13
+ it { github.repos.keys.should respond_to :all }
14
+
13
15
  context "resource found" do
14
16
  before do
15
17
  stub_get("/repos/#{user}/#{repo}/keys").
16
- to_return(:body => fixture("repos/keys.json"), :status => 200, :headers => {})
18
+ to_return(:body => fixture("repos/keys.json"),
19
+ :status => 200, :headers => {})
17
20
  end
18
21
 
19
22
  it "should fail to get resource without username" do
20
- expect { github.repos.keys }.to raise_error(ArgumentError)
23
+ expect { github.repos.keys.list }.to raise_error(ArgumentError)
21
24
  end
22
25
 
23
26
  it "should get the resources" do
24
- github.repos.keys(user, repo)
27
+ github.repos.keys.list user, repo
25
28
  a_get("/repos/#{user}/#{repo}/keys").should have_been_made
26
29
  end
27
30
 
28
31
  it "should return array of resources" do
29
- keys = github.repos.keys(user, repo)
32
+ keys = github.repos.keys.list user, repo
30
33
  keys.should be_an Array
31
34
  keys.should have(1).items
32
35
  end
33
36
 
34
37
  it "should get key information" do
35
- keys = github.repos.keys(user, repo)
38
+ keys = github.repos.keys.list user, repo
36
39
  keys.first.title.should == 'octocat@octomac'
37
40
  end
38
41
  end
@@ -45,15 +48,17 @@ describe Github::Repos::Keys do
45
48
 
46
49
  it "should fail to retrieve resource" do
47
50
  expect {
48
- github.repos.keys user, repo
51
+ github.repos.keys.list user, repo
49
52
  }.to raise_error(Github::Error::NotFound)
50
53
  end
51
54
  end
52
- end
55
+ end # list
53
56
 
54
- describe "get_key" do
57
+ describe "#get" do
55
58
  let(:key_id) { 1 }
56
59
 
60
+ it { github.repos.keys.should respond_to :find }
61
+
57
62
  context "resource found" do
58
63
  before do
59
64
  stub_get("/repos/#{user}/#{repo}/keys/#{key_id}").
@@ -62,17 +67,17 @@ describe Github::Repos::Keys do
62
67
 
63
68
  it "should fail to get resource without key" do
64
69
  expect {
65
- github.repos.get_key(user, repo, nil)
70
+ github.repos.keys.get user, repo, nil
66
71
  }.to raise_error(ArgumentError)
67
72
  end
68
73
 
69
74
  it "should get the resource" do
70
- github.repos.get_key(user, repo, key_id)
75
+ github.repos.keys.get user, repo, key_id
71
76
  a_get("/repos/#{user}/#{repo}/keys/#{key_id}").should have_been_made
72
77
  end
73
78
 
74
79
  it "should get key information" do
75
- key = github.repos.get_key(user, repo, key_id)
80
+ key = github.repos.keys.get user, repo, key_id
76
81
  key.id.should == key_id
77
82
  end
78
83
  end
@@ -85,13 +90,13 @@ describe Github::Repos::Keys do
85
90
 
86
91
  it "should fail to retrieve resource" do
87
92
  expect {
88
- github.repos.get_key(user, repo, key_id)
93
+ github.repos.keys.get user, repo, key_id
89
94
  }.to raise_error(Github::Error::NotFound)
90
95
  end
91
96
  end
92
- end
97
+ end # get
93
98
 
94
- describe "create_key" do
99
+ describe "#create" do
95
100
  let(:inputs) { {:title => "octocat@octomac", :key => "ssh-rsa AAA..." } }
96
101
 
97
102
  context "resource created" do
@@ -102,23 +107,23 @@ describe Github::Repos::Keys do
102
107
 
103
108
  it "should fail to create resource if 'title' input is missing" do
104
109
  expect {
105
- github.repos.create_key(user, repo, :key => 'ssh-rsa AAA...')
110
+ github.repos.keys.create user, repo, :key => 'ssh-rsa AAA...'
106
111
  }.to raise_error(Github::Error::RequiredParams)
107
112
  end
108
113
 
109
114
  it "should fail to create resource if 'key' input is missing" do
110
115
  expect {
111
- github.repos.create_key(user, repo, :title => 'octocat@octomac')
116
+ github.repos.keys.create user, repo, :title => 'octocat@octomac'
112
117
  }.to raise_error(Github::Error::RequiredParams)
113
118
  end
114
119
 
115
120
  it "should create the resource" do
116
- github.repos.create_key(user, repo, inputs)
121
+ github.repos.keys.create user, repo, inputs
117
122
  a_post("/repos/#{user}/#{repo}/keys").with(inputs).should have_been_made
118
123
  end
119
124
 
120
125
  it "should get the key information back" do
121
- key = github.repos.create_key(user, repo, inputs)
126
+ key = github.repos.keys.create user, repo, inputs
122
127
  key.title.should == 'octocat@octomac'
123
128
  end
124
129
  end
@@ -131,13 +136,13 @@ describe Github::Repos::Keys do
131
136
 
132
137
  it "should fail to retrieve resource" do
133
138
  expect {
134
- github.repos.create_key(user, repo, inputs)
139
+ github.repos.keys.create user, repo, inputs
135
140
  }.to raise_error(Github::Error::NotFound)
136
141
  end
137
142
  end
138
- end
143
+ end # create
139
144
 
140
- describe "edit_key" do
145
+ describe "#edit" do
141
146
  let(:key_id) { 1 }
142
147
  let(:inputs) { {:title => "octocat@octomac", :key => "ssh-rsa AAA..." } }
143
148
 
@@ -148,12 +153,12 @@ describe Github::Repos::Keys do
148
153
  end
149
154
 
150
155
  it "should edit the resource" do
151
- github.repos.edit_key(user, repo, key_id, inputs)
156
+ github.repos.keys.edit user, repo, key_id, inputs
152
157
  a_patch("/repos/#{user}/#{repo}/keys/#{key_id}").should have_been_made
153
158
  end
154
159
 
155
160
  it "should get the key information back" do
156
- key = github.repos.edit_key(user, repo, key_id, inputs)
161
+ key = github.repos.keys.edit user, repo, key_id, inputs
157
162
  key.id.should == key_id
158
163
  key.title.should == 'octocat@octomac'
159
164
  end
@@ -167,34 +172,34 @@ describe Github::Repos::Keys do
167
172
 
168
173
  it "should fail to retrieve resource" do
169
174
  expect {
170
- github.repos.edit_key(user, repo, key_id, inputs)
175
+ github.repos.keys.edit user, repo, key_id, inputs
171
176
  }.to raise_error(Github::Error::NotFound)
172
177
  end
173
178
  end
174
- end
179
+ end # edit
175
180
 
176
- describe "delete_key" do
181
+ describe "#delete" do
177
182
  let(:key_id) { 1 }
178
183
 
179
184
  context "resource found successfully" do
180
185
  before do
181
186
  stub_delete("/repos/#{user}/#{repo}/keys/#{key_id}").
182
- to_return(:body => "", :status => 204, :headers => { :content_type => "application/json; charset=utf-8"} )
187
+ to_return(:body => "", :status => 204,
188
+ :headers => { :content_type => "application/json; charset=utf-8"} )
183
189
  end
184
190
 
185
191
  it "should fail to delete without 'user/repo' parameters" do
186
- github.user, github.repo = nil, nil
187
- expect { github.repos.delete_key }.to raise_error(ArgumentError)
192
+ expect { github.repos.keys.delete }.to raise_error(ArgumentError)
188
193
  end
189
194
 
190
195
  it "should fail to delete resource without key id" do
191
196
  expect {
192
- github.repos.delete_key user, repo, nil
197
+ github.repos.keys.delete user, repo, nil
193
198
  }.to raise_error(ArgumentError)
194
199
  end
195
200
 
196
201
  it "should delete the resource" do
197
- github.repos.delete_key(user, repo, key_id)
202
+ github.repos.keys.delete user, repo, key_id
198
203
  a_delete("/repos/#{user}/#{repo}/keys/#{key_id}").should have_been_made
199
204
  end
200
205
  end
@@ -206,10 +211,10 @@ describe Github::Repos::Keys do
206
211
  end
207
212
  it "should fail to find resource" do
208
213
  expect {
209
- github.repos.delete_key(user, repo, key_id)
214
+ github.repos.keys.delete user, repo, key_id
210
215
  }.to raise_error(Github::Error::NotFound)
211
216
  end
212
217
  end
213
- end
218
+ end # delete
214
219
 
215
220
  end # Github::Repos::Keys
@@ -25,7 +25,7 @@ describe Github::Repos::PubSubHubbub do
25
25
  end
26
26
 
27
27
  it "should subscribe to hub" do
28
- github.repos.subscribe topic, callback
28
+ github.repos.pubsubhubbub.subscribe topic, callback
29
29
  a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
30
30
  end
31
31
  end
@@ -39,7 +39,7 @@ describe Github::Repos::PubSubHubbub do
39
39
 
40
40
  it "should fail to subscribe to hub" do
41
41
  expect {
42
- github.repos.subscribe topic, callback
42
+ github.repos.pubsubhubbub.subscribe topic, callback
43
43
  }.to raise_error(Github::Error::NotFound)
44
44
  end
45
45
  end
@@ -54,7 +54,7 @@ describe Github::Repos::PubSubHubbub do
54
54
  end
55
55
 
56
56
  it "should subscribe to hub" do
57
- github.repos.unsubscribe topic, callback
57
+ github.repos.pubsubhubbub.unsubscribe topic, callback
58
58
  a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
59
59
  end
60
60
  end
@@ -68,7 +68,7 @@ describe Github::Repos::PubSubHubbub do
68
68
 
69
69
  it "should fail to subscribe to hub" do
70
70
  expect {
71
- github.repos.unsubscribe topic, callback
71
+ github.repos.pubsubhubbub.unsubscribe topic, callback
72
72
  }.to raise_error(Github::Error::NotFound)
73
73
  end
74
74
  end
@@ -11,38 +11,41 @@ describe Github::Repos::Watching do
11
11
 
12
12
  describe "watchers" do
13
13
  before do
14
- github.oauth_token = nil
15
14
  stub_get("/repos/#{user}/#{repo}/watchers").
16
- to_return(:body => fixture("repos/watchers.json"), :status => 200, :headers => {})
15
+ to_return(:body => fixture("repos/watchers.json"),
16
+ :status => 200, :headers => {})
17
17
  end
18
18
 
19
19
  it "should fail to get resource without username" do
20
- expect { github.repos.watchers }.to raise_error(ArgumentError)
20
+ expect {
21
+ github.repos.watching.watchers
22
+ }.to raise_error(ArgumentError)
21
23
  end
22
24
 
23
25
  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
+ github.repos.watching.should_receive(:watchers).
27
+ with(user, repo).and_yield('github')
28
+ github.repos.watching.watchers(user, repo) { |param| 'github' }
26
29
  end
27
30
 
28
31
  it "should get the resources" do
29
- github.repos.watchers(user, repo)
32
+ github.repos.watching.watchers user, repo
30
33
  a_get("/repos/#{user}/#{repo}/watchers").should have_been_made
31
34
  end
32
35
 
33
36
  it "should return array of resources" do
34
- watchers = github.repos.watchers(user, repo)
37
+ watchers = github.repos.watching.watchers user, repo
35
38
  watchers.should be_an Array
36
39
  watchers.should have(1).items
37
40
  end
38
41
 
39
42
  it "should return result of mash type" do
40
- watchers = github.repos.watchers user, repo
43
+ watchers = github.repos.watching.watchers user, repo
41
44
  watchers.first.should be_a Hashie::Mash
42
45
  end
43
46
 
44
47
  it "should get watcher information" do
45
- watchers = github.repos.watchers(user, repo)
48
+ watchers = github.repos.watching.watchers user, repo
46
49
  watchers.first.login.should == 'octocat'
47
50
  end
48
51
 
@@ -54,7 +57,7 @@ describe Github::Repos::Watching do
54
57
 
55
58
  it "should return 404 not found message" do
56
59
  expect {
57
- github.repos.watchers(user, repo)
60
+ github.repos.watching.watchers user, repo
58
61
  }.to raise_error(Github::Error::NotFound)
59
62
  end
60
63
  end
@@ -62,20 +65,18 @@ describe Github::Repos::Watching do
62
65
 
63
66
  describe "#watched" do
64
67
  context "if user unauthenticated" do
65
- before { github.oauth_token = nil }
66
-
67
68
  it "should fail to get resource without username " do
68
69
  stub_get("/user/watched").
69
70
  to_return(:body => fixture("repos/watched.json"), :status => 401, :headers => {})
70
71
  expect {
71
- github.repos.watched
72
+ github.repos.watching.watched
72
73
  }.to raise_error(Github::Error::Unauthorized)
73
74
  end
74
75
 
75
76
  it "should get the resource with username" do
76
77
  stub_get("/users/#{user}/watched").
77
78
  to_return(:body => fixture("repos/watched.json"), :status => 200, :headers => {})
78
- github.repos.watched(:user => user)
79
+ github.repos.watching.watched :user => user
79
80
  a_get("/users/#{user}/watched").should have_been_made
80
81
  end
81
82
  end
@@ -88,22 +89,20 @@ describe Github::Repos::Watching do
88
89
  to_return(:body => fixture("repos/watched.json"), :status => 200, :headers => {})
89
90
  end
90
91
 
91
- after { github.oauth_token = nil }
92
-
93
92
  it "should get the resources" do
94
- github.repos.watched
93
+ github.repos.watching.watched
95
94
  a_get("/user/watched").with(:query => {:access_token => OAUTH_TOKEN}).
96
95
  should have_been_made
97
96
  end
98
97
 
99
98
  it "should return array of resources" do
100
- watched = github.repos.watched
99
+ watched = github.repos.watching.watched
101
100
  watched.should be_an Array
102
101
  watched.should have(1).items
103
102
  end
104
103
 
105
104
  it "should get watched information" do
106
- watched = github.repos.watched
105
+ watched = github.repos.watching.watched
107
106
  watched.first.name.should == 'Hello-World'
108
107
  watched.first.owner.login.should == 'octocat'
109
108
  end
@@ -115,25 +114,28 @@ describe Github::Repos::Watching do
115
114
  context "this repo is being watched by the user"
116
115
  before do
117
116
  stub_get("/user/watched/#{user}/#{repo}").
118
- to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
117
+ to_return(:body => "", :status => 404,
118
+ :headers => {:user_agent => github.user_agent})
119
119
  end
120
120
 
121
121
  it "should return false if resource not found" do
122
- watching = github.repos.watching? user, repo
122
+ watching = github.repos.watching.watching? user, repo
123
123
  watching.should be_false
124
124
  end
125
125
 
126
126
  it "should return true if resoure found" do
127
127
  stub_get("/user/watched/#{user}/#{repo}").
128
128
  to_return(:body => "", :status => 200, :headers => {:user_agent => github.user_agent})
129
- watching = github.repos.watching? user, repo
129
+ watching = github.repos.watching.watching? user, repo
130
130
  watching.should be_true
131
131
  end
132
132
  end
133
133
 
134
134
  context "without username and reponame passed" do
135
135
  it "should fail validation " do
136
- expect { github.repos.watching?(nil, nil) }.to raise_error(ArgumentError)
136
+ expect {
137
+ github.repos.watching.watching?(nil, nil)
138
+ }.to raise_error(ArgumentError)
137
139
  end
138
140
  end
139
141
  end # watching?
@@ -148,10 +150,8 @@ describe Github::Repos::Watching do
148
150
  to_return(:body => "", :status => 204, :headers => {})
149
151
  end
150
152
 
151
- after { github.oauth_token = nil }
152
-
153
153
  it "should successfully watch a repo" do
154
- github.repos.start_watching(user, repo)
154
+ github.repos.watching.start_watching user, repo
155
155
  a_put("/user/watched/#{user}/#{repo}").
156
156
  with(:query => {:access_token => OAUTH_TOKEN}).
157
157
  should have_been_made
@@ -161,11 +161,10 @@ describe Github::Repos::Watching do
161
161
 
162
162
  context "user unauthenticated" do
163
163
  it "should fail" do
164
- github.oauth_token = nil
165
164
  stub_put("/user/watched/#{user}/#{repo}").
166
165
  to_return(:body => "", :status => 401, :headers => {})
167
166
  expect {
168
- github.repos.start_watching(user, repo)
167
+ github.repos.watching.start_watching user, repo
169
168
  }.to raise_error(Github::Error::Unauthorized)
170
169
  end
171
170
  end
@@ -175,26 +174,25 @@ describe Github::Repos::Watching do
175
174
  context "user authenticated" do
176
175
  context "with correct information" do
177
176
  before do
178
- github.user, github.repo = nil, nil
179
177
  github.oauth_token = OAUTH_TOKEN
180
178
  stub_delete("/user/watched/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").
181
179
  to_return(:body => "", :status => 204, :headers => {})
182
180
  end
183
181
 
184
182
  it "should successfully watch a repo" do
185
- github.repos.stop_watching(user, repo)
186
- a_delete("/user/watched/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").should have_been_made
183
+ github.repos.watching.stop_watching user, repo
184
+ a_delete("/user/watched/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").
185
+ should have_been_made
187
186
  end
188
187
  end
189
188
  end
190
189
 
191
190
  context "user unauthenticated" do
192
191
  it "should fail" do
193
- github.oauth_token = nil
194
192
  stub_delete("/user/watched/#{user}/#{repo}").
195
193
  to_return(:body => "", :status => 401, :headers => {})
196
194
  expect {
197
- github.repos.stop_watching(user, repo)
195
+ github.repos.watching.stop_watching(user, repo)
198
196
  }.to raise_error(Github::Error::Unauthorized)
199
197
  end
200
198
  end
@@ -9,7 +9,18 @@ describe Github::Repos do
9
9
 
10
10
  after { reset_authentication_for github }
11
11
 
12
- describe "branches" do
12
+ context 'access to apis' do
13
+ it { subject.collaborators.should be_a Github::Repos::Collaborators }
14
+ it { subject.commits.should be_a Github::Repos::Commits }
15
+ it { subject.downloads.should be_a Github::Repos::Downloads }
16
+ it { subject.forks.should be_a Github::Repos::Forks }
17
+ it { subject.hooks.should be_a Github::Repos::Hooks }
18
+ it { subject.keys.should be_a Github::Repos::Keys }
19
+ it { subject.watching.should be_a Github::Repos::Watching }
20
+ it { subject.pubsubhubbub.should be_a Github::Repos::PubSubHubbub }
21
+ end
22
+
23
+ describe "#branches" do
13
24
  context "resource found" do
14
25
  before do
15
26
  stub_get("/repos/#{user}/#{repo}/branches").
@@ -77,13 +88,13 @@ describe Github::Repos do
77
88
 
78
89
  it "should raise error when no user/repo parameters" do
79
90
  expect {
80
- github.repos.contributors
91
+ github.repos.contributors nil, repo
81
92
  }.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
82
93
  end
83
94
 
84
95
  it "should raise error when no repository" do
85
96
  expect {
86
- github.repos.contributors user
97
+ github.repos.contributors user, nil
87
98
  }.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
88
99
  end
89
100
 
@@ -124,36 +135,35 @@ describe Github::Repos do
124
135
  end
125
136
  end # contributors
126
137
 
127
- describe "create_repo" do
128
- let(:inputs) { {:name => 'web', :description => "This is your first repo", :homepage => "https://github.com", :private => false, :has_issues => true, :has_wiki => true}}
138
+ describe "#create" do
139
+ let(:inputs) { {:name => 'web', :description => "This is your first repo", :homepage => "https://github.com", :public => true, :has_issues => true, :has_wiki => true}}
129
140
 
130
141
  context "resource created successfully for the authenticated user" do
131
142
  before do
132
143
  github.oauth_token = OAUTH_TOKEN
133
144
  stub_post("/user/repos?access_token=#{OAUTH_TOKEN}").with(inputs).
134
- to_return(:body => fixture('repos/repo.json'), :status => 201,:headers => {:content_type => "application/json; charset=utf-8"} )
145
+ to_return(:body => fixture('repos/repo.json'), :status => 201,
146
+ :headers => {:content_type => "application/json; charset=utf-8"} )
135
147
  end
136
148
 
137
- after { github.oauth_token = nil }
138
-
139
149
  it "should faile to create resource if 'name' inputs is missing" do
140
150
  expect {
141
- github.repos.create_repo inputs.except(:name)
151
+ github.repos.create inputs.except(:name)
142
152
  }.to raise_error(Github::Error::RequiredParams)
143
153
  end
144
154
 
145
155
  it "should create resource" do
146
- github.repos.create_repo inputs
156
+ github.repos.create inputs
147
157
  a_post("/user/repos?access_token=#{OAUTH_TOKEN}").with(inputs).should have_been_made
148
158
  end
149
159
 
150
160
  it "should return the resource" do
151
- repository = github.repos.create_repo inputs
161
+ repository = github.repos.create inputs
152
162
  repository.name.should == 'Hello-World'
153
163
  end
154
164
 
155
165
  it "should return mash type" do
156
- repository = github.repos.create_repo inputs
166
+ repository = github.repos.create inputs
157
167
  repository.should be_a Hashie::Mash
158
168
  end
159
169
  end
@@ -161,43 +171,33 @@ describe Github::Repos do
161
171
  context "resource created for the authenticated user belonging to organization" do
162
172
  let(:org) { '37signals' }
163
173
  before do
164
- github.user = nil
165
174
  github.oauth_token = OAUTH_TOKEN
166
175
  stub_post("/orgs/#{org}/repos?access_token=#{OAUTH_TOKEN}").with(inputs).
167
176
  to_return(:body => fixture('repos/repo.json'), :status => 201,:headers => {:content_type => "application/json; charset=utf-8"} )
168
177
  end
169
178
 
170
- after do
171
- github.user, github.oauth_token = nil, nil
172
- end
173
-
174
179
  it "should get the resource" do
175
- github.repos.create_repo inputs.merge(:org => org)
180
+ github.repos.create inputs.merge(:org => org)
176
181
  a_post("/orgs/#{org}/repos?access_token=#{OAUTH_TOKEN}").with(inputs).should have_been_made
177
182
  end
178
183
  end
179
184
 
180
185
  context "failed to create" do
181
186
  before do
182
- github.user = nil
183
187
  github.oauth_token = OAUTH_TOKEN
184
188
  stub_post("/user/repos?access_token=#{OAUTH_TOKEN}").with(inputs).
185
189
  to_return(:body => '', :status => 404,:headers => {:content_type => "application/json; charset=utf-8"} )
186
190
  end
187
191
 
188
- after do
189
- github.user, github.oauth_token = nil, nil
190
- end
191
-
192
192
  it "should faile to retrieve resource" do
193
193
  expect {
194
- github.repos.create_repo inputs
194
+ github.repos.create inputs
195
195
  }.to raise_error(Github::Error::NotFound)
196
196
  end
197
197
  end
198
198
  end
199
199
 
200
- describe "edit_repo" do
200
+ describe "#edit" do
201
201
  let(:inputs) do
202
202
  { :name => 'web',
203
203
  :description => "This is your first repo",
@@ -210,32 +210,32 @@ describe Github::Repos do
210
210
  context "resource edited successfully" do
211
211
  before do
212
212
  stub_patch("/repos/#{user}/#{repo}").with(inputs).
213
- to_return(:body => fixture("repos/repo.json"), :status => 200, :headers => { :content_type => "application/json; charset=utf-8"})
213
+ to_return(:body => fixture("repos/repo.json"), :status => 200,
214
+ :headers => { :content_type => "application/json; charset=utf-8"})
214
215
  end
215
216
 
216
217
  it "should fail to edit without 'user/repo' parameters" do
217
- # github.user, github.repo = nil, nil
218
- expect { github.repos.edit_repo }.to raise_error(ArgumentError)
218
+ expect { github.repos.edit user, nil }.to raise_error(ArgumentError)
219
219
  end
220
220
 
221
221
  it "should fail to edit resource without 'name' parameter" do
222
222
  expect{
223
- github.repos.edit_hook user, repo, inputs.except(:name)
223
+ github.repos.edit user, repo, inputs.except(:name)
224
224
  }.to raise_error(Github::Error::RequiredParams)
225
225
  end
226
226
 
227
227
  it "should edit the resource" do
228
- github.repos.edit_repo user, repo, inputs
228
+ github.repos.edit user, repo, inputs
229
229
  a_patch("/repos/#{user}/#{repo}").with(inputs).should have_been_made
230
230
  end
231
231
 
232
232
  it "should return resource" do
233
- repository = github.repos.edit_repo user, repo, inputs
233
+ repository = github.repos.edit user, repo, inputs
234
234
  repository.should be_a Hashie::Mash
235
235
  end
236
236
 
237
237
  it "should be able to retrieve information" do
238
- repository = github.repos.edit_repo user, repo, inputs
238
+ repository = github.repos.edit user, repo, inputs
239
239
  repository.name.should == 'Hello-World'
240
240
  end
241
241
  end
@@ -243,18 +243,19 @@ describe Github::Repos do
243
243
  context "failed to edit resource" do
244
244
  before do
245
245
  stub_patch("/repos/#{user}/#{repo}").with(inputs).
246
- to_return(:body => fixture("repos/repo.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
246
+ to_return(:body => fixture("repos/repo.json"), :status => 404,
247
+ :headers => { :content_type => "application/json; charset=utf-8"})
247
248
  end
248
249
 
249
250
  it "should fail to find resource" do
250
251
  expect {
251
- github.repos.edit_repo user, repo, inputs
252
+ github.repos.edit user, repo, inputs
252
253
  }.to raise_error(Github::Error::NotFound)
253
254
  end
254
255
  end
255
- end # edit_repo
256
+ end # edit
256
257
 
257
- describe "get_repo" do
258
+ describe "#get" do
258
259
  context "resource found" do
259
260
  before do
260
261
  stub_get("/repos/#{user}/#{repo}").
@@ -262,31 +263,31 @@ describe Github::Repos do
262
263
  end
263
264
 
264
265
  it "should raise error when no user/repo parameters" do
265
- github.user, github.repo = nil, nil
266
+ # github.user, github.repo = nil, nil
266
267
  expect {
267
- github.repos.get_repo
268
+ github.repos.get nil, repo
268
269
  }.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
269
270
  end
270
271
 
271
272
  it "should raise error when no repository" do
272
- github.user, github.repo = nil, nil
273
+ # github.user, github.repo = nil, nil
273
274
  expect {
274
- github.repos.get_repo user
275
+ github.repos.get user, nil
275
276
  }.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
276
277
  end
277
278
 
278
279
  it "should find resources" do
279
- github.repos.get_repo user, repo
280
+ github.repos.get user, repo
280
281
  a_get("/repos/#{user}/#{repo}").should have_been_made
281
282
  end
282
283
 
283
284
  it "should return repository mash" do
284
- repository = github.repos.get_repo user, repo
285
+ repository = github.repos.get user, repo
285
286
  repository.should be_a Hashie::Mash
286
287
  end
287
288
 
288
289
  it "should get repository information" do
289
- repository = github.repos.get_repo user, repo
290
+ repository = github.repos.get user, repo
290
291
  repository.name.should == 'Hello-World'
291
292
  end
292
293
  end
@@ -294,18 +295,19 @@ describe Github::Repos do
294
295
  context "resource not found" do
295
296
  before do
296
297
  stub_get("/repos/#{user}/#{repo}").
297
- to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
298
+ to_return(:body => '', :status => 404,
299
+ :headers => {:content_type => "application/json; charset=utf-8"})
298
300
  end
299
301
 
300
302
  it "should fail to get resource" do
301
303
  expect {
302
- github.repos.get_repo user, repo
304
+ github.repos.get user, repo
303
305
  }.to raise_error(Github::Error::NotFound)
304
306
  end
305
307
  end
306
- end # get_repo
308
+ end # get
307
309
 
308
- describe "languages" do
310
+ describe "#languages" do
309
311
  context "resource found" do
310
312
  before do
311
313
  stub_get("/repos/#{user}/#{repo}/languages").
@@ -313,16 +315,14 @@ describe Github::Repos do
313
315
  end
314
316
 
315
317
  it "should raise error when no user/repo parameters" do
316
- # github.user, github.repo = nil, nil
317
318
  expect {
318
- github.repos.languages
319
+ github.repos.languages nil, repo
319
320
  }.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
320
321
  end
321
322
 
322
323
  it "should raise error when no repository" do
323
- # github.user, github.repo = nil, nil
324
324
  expect {
325
- github.repos.languages user
325
+ github.repos.languages user, nil
326
326
  }.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
327
327
  end
328
328
 
@@ -362,46 +362,40 @@ describe Github::Repos do
362
362
  end
363
363
  end # languages
364
364
 
365
- describe "repos" do
365
+ describe "#list" do
366
366
  context "resource found for authenticated user" do
367
367
  before do
368
- # github.user = nil
369
368
  github.oauth_token = OAUTH_TOKEN
370
369
  stub_get("/user/repos?access_token=#{OAUTH_TOKEN}").
371
370
  to_return(:body => fixture('repos/repos.json'), :status => 200,:headers => {:content_type => "application/json; charset=utf-8"} )
372
371
  end
373
372
 
374
- after do
375
- github.oauth_token = nil
376
- # github.user, github.repo = nil, nil
377
- end
378
-
379
373
  it "fails if user is unauthenticated" do
380
374
  github.oauth_token = nil
381
375
  stub_get("/user/repos").
382
376
  to_return(:body => '', :status => 401,:headers => {:content_type => "application/json; charset=utf-8"} )
383
- expect { github.repos.repos}.to raise_error(Github::Error::Unauthorized)
377
+ expect { github.repos.list }.to raise_error(Github::Error::Unauthorized)
384
378
  end
385
379
 
386
380
  it "should get the resources" do
387
- github.repos.repos
381
+ github.repos.list
388
382
  a_get("/user/repos?access_token=#{OAUTH_TOKEN}").should have_been_made
389
383
  end
390
384
 
391
385
  it "should return array of resources" do
392
- repositories = github.repos.repos
386
+ repositories = github.repos.list
393
387
  repositories.should be_an Array
394
388
  repositories.should have(1).items
395
389
  end
396
390
 
397
391
  it "should get resource information" do
398
- repositories = github.repos.repos
392
+ repositories = github.repos.list
399
393
  repositories.first.name.should == 'Hello-World'
400
394
  end
401
395
 
402
396
  it "should yield repositories to a block" do
403
- github.repos.should_receive(:repos).and_yield('octocat')
404
- github.repos.repos { |repo| 'octocat' }
397
+ github.repos.should_receive(:list).and_yield('octocat')
398
+ github.repos.list { |repo| 'octocat' }
405
399
  end
406
400
  end
407
401
 
@@ -409,46 +403,43 @@ describe Github::Repos do
409
403
  let(:org) { '37signals' }
410
404
 
411
405
  before do
412
- # github.user = nil
413
- github.oauth_token = nil
414
406
  stub_get("/orgs/#{org}/repos").
415
- to_return(:body => fixture('repos/repos.json'), :status => 200,:headers => {:content_type => "application/json; charset=utf-8"} )
407
+ to_return(:body => fixture('repos/repos.json'), :status => 200,
408
+ :headers => {:content_type => "application/json; charset=utf-8"} )
416
409
  end
417
410
 
418
411
  it "should get the resources" do
419
- github.repos.repos :org => org
412
+ github.repos.list :org => org
420
413
  a_get("/orgs/#{org}/repos").should have_been_made
421
414
  end
422
-
423
415
  end
424
416
 
425
417
  context "resource found for organization" do
426
418
  before do
427
419
  stub_get("/users/#{user}/repos").
428
- to_return(:body => fixture('repos/repos.json'), :status => 200,:headers => {:content_type => "application/json; charset=utf-8"} )
420
+ to_return(:body => fixture('repos/repos.json'), :status => 200,
421
+ :headers => {:content_type => "application/json; charset=utf-8"} )
429
422
  end
430
423
 
431
424
  it "should get the resources" do
432
- github.repos.repos :user => user
425
+ github.repos.list :user => user
433
426
  a_get("/users/#{user}/repos").should have_been_made
434
427
  end
435
428
  end
436
429
 
437
430
  context "rosource not found for authenticated user" do
438
431
  before do
439
- # github.user = nil
440
432
  github.oauth_token = OAUTH_TOKEN
441
433
  stub_get("/user/repos?access_token=#{OAUTH_TOKEN}").
442
- to_return(:body => '', :status => 404,:headers => {:content_type => "application/json; charset=utf-8"} )
434
+ to_return(:body => '', :status => 404,
435
+ :headers => {:content_type => "application/json; charset=utf-8"} )
443
436
  end
444
437
 
445
- after { github.oauth_token = nil }
446
-
447
438
  it "fail to find resources" do
448
- expect { github.repos.repos }.to raise_error(Github::Error::NotFound)
439
+ expect { github.repos.list }.to raise_error(Github::Error::NotFound)
449
440
  end
450
441
  end
451
- end # repos
442
+ end # list
452
443
 
453
444
  describe "tags" do
454
445
  context "resource found" do
@@ -459,13 +450,13 @@ describe Github::Repos do
459
450
 
460
451
  it "should raise error when no user/repo parameters" do
461
452
  expect {
462
- github.repos.tags
453
+ github.repos.tags nil, repo
463
454
  }.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
464
455
  end
465
456
 
466
457
  it "should raise error when no repository" do
467
458
  expect {
468
- github.repos.tags user
459
+ github.repos.tags user, nil
469
460
  }.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
470
461
  end
471
462
 
@@ -503,9 +494,9 @@ describe Github::Repos do
503
494
  }.to raise_error(Github::Error::NotFound)
504
495
  end
505
496
  end
506
- end #tags
497
+ end # tags
507
498
 
508
- describe "teams" do
499
+ describe "#teams" do
509
500
  context "resource found" do
510
501
  before do
511
502
  stub_get("/repos/#{user}/#{repo}/teams").
@@ -514,13 +505,13 @@ describe Github::Repos do
514
505
 
515
506
  it "should raise error when no user/repo parameters" do
516
507
  expect {
517
- github.repos.teams
508
+ github.repos.teams nil, repo
518
509
  }.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
519
510
  end
520
511
 
521
512
  it "should raise error when no repository" do
522
513
  expect {
523
- github.repos.teams user
514
+ github.repos.teams user, nil
524
515
  }.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
525
516
  end
526
517