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,29 @@
1
+ [
2
+ {
3
+ "url": "https://api.github.com/repos/octocat/Hello-World",
4
+ "html_url": "https://github.com/octocat/Hello-World",
5
+ "clone_url": "https://github.com/octocat/Hello-World.git",
6
+ "git_url": "git://github.com/octocat/Hello-World.git",
7
+ "ssh_url": "git@github.com:octocat/Hello-World.git",
8
+ "svn_url": "https://svn.github.com/octocat/Hello-World",
9
+ "owner": {
10
+ "login": "octocat",
11
+ "id": 1,
12
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
13
+ "url": "https://api.github.com/users/octocat"
14
+ },
15
+ "name": "Hello-World",
16
+ "description": "This your first repo!",
17
+ "homepage": "https://github.com",
18
+ "language": null,
19
+ "private": false,
20
+ "fork": false,
21
+ "forks": 9,
22
+ "watchers": 80,
23
+ "size": 108,
24
+ "master_branch": "master",
25
+ "open_issues": 0,
26
+ "pushed_at": "2011-01-26T19:06:43Z",
27
+ "created_at": "2011-01-26T19:01:12Z"
28
+ }
29
+ ]
@@ -0,0 +1,8 @@
1
+ [
2
+ {
3
+ "login": "octocat",
4
+ "id": 1,
5
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
6
+ "url": "https://api.github.com/users/octocat"
7
+ }
8
+ ]
@@ -0,0 +1,32 @@
1
+ {
2
+ "login": "octocat",
3
+ "id": 1,
4
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
5
+ "gravatar_id": "somehexcode",
6
+ "url": "https://api.github.com/users/octocat",
7
+ "name": "monalisa octocat",
8
+ "company": "GitHub",
9
+ "blog": "https://github.com/blog",
10
+ "location": "San Francisco",
11
+ "email": "octocat@github.com",
12
+ "hireable": false,
13
+ "bio": "There once was...",
14
+ "public_repos": 2,
15
+ "public_gists": 1,
16
+ "followers": 20,
17
+ "following": 0,
18
+ "html_url": "https://github.com/octocat",
19
+ "created_at": "2008-01-14T04:33:35Z",
20
+ "type": "User",
21
+ "total_private_repos": 100,
22
+ "owned_private_repos": 100,
23
+ "private_gists": 81,
24
+ "disk_usage": 10000,
25
+ "collaborators": 8,
26
+ "plan": {
27
+ "name": "Medium",
28
+ "space": 400,
29
+ "collaborators": 10,
30
+ "private_repos": 20
31
+ }
32
+ }
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::API do
4
+
5
+ let(:api) { Github::API.new }
6
+
7
+ before(:each) do
8
+ @params = { 'a' => { :b => { 'c' => 1 }, 'd' => [ 'a', { :e => 2 }] } }
9
+ end
10
+
11
+ it "should stringify all the keys inside nested hash" do
12
+ actual = api.send(:_normalize_params_keys, @params)
13
+ expected = { 'a' => { 'b'=> { 'c' => 1 }, 'd' => [ 'a', { 'e'=> 2 }] } }
14
+ actual.should == expected
15
+ end
16
+
17
+ it "should filter param keys" do
18
+ valid = ['a', 'b', 'e']
19
+ hash = {'a' => 1, 'b' => 3, 'c' => 2, 'd'=> 4, 'e' => 5 }
20
+ actual = api.send(:_filter_params_keys, valid, hash)
21
+ expected = {'a' => 1, 'b' => 3, 'e' => 5 }
22
+ actual.should == expected
23
+ end
24
+
25
+ end
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Authorization do
4
+
5
+ let(:client_id) { '234jl23j4l23j4l' }
6
+ let(:client_secret) { 'asasd79sdf9a7asfd7sfd97s' }
7
+ let(:code) { 'c9798sdf97df98ds'}
8
+ let(:github) { Github.new }
9
+
10
+ it "should instantiate oauth2 instance" do
11
+ github.client.should be_a OAuth2::Client
12
+ end
13
+
14
+ it "should assign site from the options hash" do
15
+ github.client.site.should == 'https://github.com'
16
+ end
17
+
18
+ it "should assign 'authorize_url" do
19
+ github.client.authorize_url.should == 'https://github.com/login/oauth/authorize'
20
+ end
21
+
22
+ it "should assign 'token_url" do
23
+ github.client.token_url.should == 'https://github.com/login/oauth/access_token'
24
+ end
25
+
26
+ context '.client' do
27
+ it { github.should respond_to :client }
28
+
29
+ it "should return OAuth2::Client instance" do
30
+ github.client.should be_a OAuth2::Client
31
+ end
32
+ end
33
+
34
+ context '.auth_code' do
35
+ let(:oauth) { OAuth2::Client.new(client_id, client_secret) }
36
+
37
+ before do
38
+ github = Github.new :client_id => client_id, :client_secret => client_secret
39
+ end
40
+
41
+ after do
42
+ github.client_id, github.client_secret = nil, nil
43
+ end
44
+
45
+ it "should throw an error if no client_id" do
46
+ github.client_id = nil
47
+ expect { github.auth_code }.should raise_error(ArgumentError)
48
+ end
49
+
50
+ it "should throw an error if no client_secret" do
51
+ github.client_secret = nil
52
+ expect { github.auth_code }.should raise_error(ArgumentError)
53
+ end
54
+
55
+ it "should return authentication token code" do
56
+ github.client_id = client_id
57
+ github.client_secret = client_secret
58
+ github.client.stub(:auth_code).and_return code
59
+ github.auth_code.should == code
60
+ end
61
+ end
62
+
63
+ context "authorize_url" do
64
+ before do
65
+ github = Github.new :client_id => client_id, :client_secret => client_secret
66
+ end
67
+
68
+ it "should respond to 'authorize_url' " do
69
+ github.should respond_to :authorize_url
70
+ end
71
+
72
+ it "should return address containing client_id" do
73
+ github.authorize_url.should =~ /client_id=#{client_id}/
74
+ end
75
+
76
+ it "should return address containing scopes" do
77
+ github.authorize_url(:scope => 'user').should =~ /scope=user/
78
+ end
79
+
80
+ it "should return address containing redirect_uri" do
81
+ github.authorize_url(:redirect_uri => 'http://localhost').should =~ /redirect_uri/
82
+ end
83
+ end
84
+
85
+ context "get_token" do
86
+ before do
87
+ github = Github.new :client_id => client_id, :client_secret => client_secret
88
+ stub_request(:post, 'https://github.com/login/oauth/access_token').
89
+ to_return(:body => '', :status => 200, :headers => {})
90
+ end
91
+
92
+ it "should respond to 'get_token' " do
93
+ github.should respond_to :get_token
94
+ end
95
+
96
+ it "should make the authorization request" do
97
+ expect {
98
+ github.get_token code
99
+ a_request(:post, "https://github.com/login/oauth/access_token").should have_been_made
100
+ }.to raise_error(OAuth2::Error)
101
+ end
102
+
103
+ it "should fail to get_token without authorization code" do
104
+ expect { github.get_token }.to raise_error(ArgumentError)
105
+ end
106
+ end
107
+
108
+ context ".authenticated?" do
109
+ it { github.should respond_to :authenticated? }
110
+
111
+ it "should return false if falied on basic authentication" do
112
+ github.stub(:basic_authed?).and_return false
113
+ github.authenticated?.should be_false
114
+ end
115
+
116
+ it "should return true if basic authentication performed" do
117
+ github.stub(:basic_authed?).and_return true
118
+ github.authenticated?.should be_true
119
+ end
120
+
121
+ it "should return true if basic authentication performed" do
122
+ github.stub(:oauth_token?).and_return true
123
+ github.authenticated?.should be_true
124
+ end
125
+ end
126
+
127
+ context ".basic_authed?" do
128
+ it { github.should respond_to :basic_authed? }
129
+
130
+ it "should return false if login is missing" do
131
+ github.stub(:login?).and_return false
132
+ github.basic_authed?.should be_false
133
+ end
134
+
135
+ it "should return true if login && password provided" do
136
+ github.stub(:login?).and_return true
137
+ github.stub(:password?).and_return true
138
+ github.basic_authed?.should be_true
139
+ end
140
+ end
141
+
142
+ context "authentication" do
143
+ it "should respond to 'authentication'" do
144
+ github.should respond_to :authentication
145
+ end
146
+
147
+ it "should return empty hash if no basic authentication params available" do
148
+ github.stub(:login?).and_return false
149
+ github.stub(:basic_auth?).and_return false
150
+ github.authentication.should be_empty
151
+ end
152
+
153
+ context 'basic_auth' do
154
+ before do
155
+ github = Github.new :basic_auth => 'github:pass'
156
+ end
157
+
158
+ it "should return hash with basic auth params" do
159
+ github.authentication.should be_a Hash
160
+ github.authentication.should have_key :basic_auth
161
+ end
162
+ end
163
+
164
+ context 'login & password' do
165
+ before do
166
+ github = Github.new :login => 'github', :password => 'pass'
167
+ end
168
+
169
+ it "should return hash with login & password params" do
170
+ github.authentication.should be_a Hash
171
+ github.authentication.should have_key :login
172
+ end
173
+ end
174
+ end # authentication
175
+
176
+ end # Github::Authorization
@@ -0,0 +1,242 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Authorizations do
4
+
5
+ let(:github) { Github.new }
6
+ let(:basic_auth) { 'login:password' }
7
+
8
+ before do
9
+ github.basic_auth = basic_auth
10
+ end
11
+
12
+ after do
13
+ reset_authentication_for github
14
+ end
15
+
16
+ describe "authorizations" do
17
+ context "resource found" do
18
+ before do
19
+ stub_get("/authorizations", "https://#{basic_auth}@api.github.com").
20
+ to_return(:body => fixture('auths/authorizations.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
21
+ end
22
+
23
+
24
+ it "should fail to get resource without basic authentication" do
25
+ reset_authentication_for github
26
+ expect { github.oauth.authorizations }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "should get the resources" do
30
+ github.oauth.authorizations
31
+ a_get("/authorizations", "https://#{basic_auth}@api.github.com").should have_been_made
32
+ end
33
+
34
+ it "should return array of resources" do
35
+ authorizations = github.oauth.authorizations
36
+ authorizations.should be_an Array
37
+ authorizations.should have(1).items
38
+ end
39
+
40
+ it "should be a mash type" do
41
+ authorizations = github.oauth.authorizations
42
+ authorizations.first.should be_a Hashie::Mash
43
+ end
44
+
45
+ it "should get authorization information" do
46
+ authorizations = github.oauth.authorizations
47
+ authorizations.first.token.should == 'abc123'
48
+ end
49
+
50
+ it "should yield to a block" do
51
+ github.oauth.should_receive(:authorizations).and_yield('web')
52
+ github.oauth.authorizations { |param| 'web' }
53
+ end
54
+ end
55
+
56
+ context "resource not found" do
57
+ before do
58
+ stub_get("/authorizations", "https://#{basic_auth}@api.github.com").
59
+ to_return(:body => "", :status => [404, "Not Found"])
60
+ end
61
+
62
+ it "should return 404 with a message 'Not Found'" do
63
+ expect { github.oauth.authorizations }.to raise_error(Github::ResourceNotFound)
64
+ end
65
+ end
66
+ end # authorizations
67
+
68
+ describe "authorization" do
69
+ let(:authorization_id) { 1 }
70
+
71
+ context "resource found" do
72
+ before do
73
+ stub_get("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").
74
+ to_return(:body => fixture('auths/authorization.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
75
+ end
76
+
77
+ it "should fail to get resource without authorization id" do
78
+ expect { github.oauth.authorization nil }.to raise_error(ArgumentError)
79
+ end
80
+
81
+ it "should get the resource" do
82
+ github.oauth.authorization authorization_id
83
+ a_get("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").should have_been_made
84
+ end
85
+
86
+ it "should get authorization information" do
87
+ authorization = github.oauth.authorization authorization_id
88
+ authorization.id.should == authorization_id
89
+ authorization.token.should == 'abc123'
90
+ end
91
+
92
+ it "should return mash" do
93
+ authorization = github.oauth.authorization authorization_id
94
+ authorization.should be_a Hashie::Mash
95
+ end
96
+ end
97
+
98
+ context "resource not found" do
99
+ before do
100
+ stub_get("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").
101
+ to_return(:body => fixture('auths/authorization.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
102
+ end
103
+
104
+ it "should fail to retrive resource" do
105
+ expect {
106
+ github.oauth.authorization authorization_id
107
+ }.to raise_error(Github::ResourceNotFound)
108
+ end
109
+ end
110
+ end # authorization
111
+
112
+ describe "create_authorization" do
113
+ let(:inputs) { { :scopes => ['repo'] } }
114
+
115
+ context "resouce created" do
116
+
117
+ it "should fail to get resource without basic authentication" do
118
+ reset_authentication_for github
119
+ expect { github.oauth.create_authorization }.to raise_error(ArgumentError)
120
+ end
121
+
122
+ before do
123
+ stub_post("/authorizations", "https://#{basic_auth}@api.github.com").with(inputs).
124
+ to_return(:body => fixture('auths/authorization.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
125
+ end
126
+
127
+ it "should create resource successfully" do
128
+ github.oauth.create_authorization inputs
129
+ a_post("/authorizations", "https://#{basic_auth}@api.github.com").with(inputs).should have_been_made
130
+ end
131
+
132
+ it "should return the resource" do
133
+ authorization = github.oauth.create_authorization inputs
134
+ authorization.should be_a Hashie::Mash
135
+ end
136
+
137
+ it "should get the authorization information" do
138
+ authorization = github.oauth.create_authorization inputs
139
+ authorization.token.should == 'abc123'
140
+ end
141
+ end
142
+
143
+ context "failed to create resource" do
144
+ before do
145
+ stub_post("/authorizations", "https://#{basic_auth}@api.github.com").with(inputs).
146
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
147
+
148
+ end
149
+
150
+ it "should fail to retrieve resource" do
151
+ expect {
152
+ github.oauth.create_authorization inputs
153
+ }.to raise_error(Github::ResourceNotFound)
154
+ end
155
+ end
156
+ end # create_authorization
157
+
158
+ describe "update_authorization" do
159
+ let(:authorization_id) { 1 }
160
+ let(:inputs) { { :add_scopes => ['repo'] } }
161
+
162
+ context "resouce updated" do
163
+
164
+ it "should fail to get resource without basic authentication" do
165
+ reset_authentication_for github
166
+ expect { github.oauth.update_authorization }.to raise_error(ArgumentError)
167
+ end
168
+
169
+ before do
170
+ stub_patch("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").with(inputs).
171
+ to_return(:body => fixture('auths/authorization.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
172
+ end
173
+
174
+ it "should update resource successfully" do
175
+ github.oauth.update_authorization authorization_id, inputs
176
+ a_patch("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").with(inputs).should have_been_made
177
+ end
178
+
179
+ it "should return the resource" do
180
+ authorization = github.oauth.update_authorization authorization_id, inputs
181
+ authorization.should be_a Hashie::Mash
182
+ end
183
+
184
+ it "should get the authorization information" do
185
+ authorization = github.oauth.update_authorization authorization_id, inputs
186
+ authorization.token.should == 'abc123'
187
+ end
188
+ end
189
+
190
+ context "failed to update resource" do
191
+ before do
192
+ stub_patch("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").with(inputs).
193
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
194
+
195
+ end
196
+
197
+ it "should fail to retrieve resource" do
198
+ expect {
199
+ github.oauth.update_authorization authorization_id, inputs
200
+ }.to raise_error(Github::ResourceNotFound)
201
+ end
202
+ end
203
+ end # update_authorization
204
+
205
+ describe "delete_authorization" do
206
+ let(:authorization_id) { 1 }
207
+ let(:inputs) { { :add_scopes => ['repo'] } }
208
+
209
+ context "resouce deleted" do
210
+
211
+ it "should fail to get resource without basic authentication" do
212
+ reset_authentication_for github
213
+ expect { github.oauth.delete_authorization nil }.to raise_error(ArgumentError)
214
+ end
215
+
216
+ before do
217
+ stub_delete("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").
218
+ to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
219
+ end
220
+
221
+ it "should delete resource successfully" do
222
+ github.oauth.delete_authorization authorization_id
223
+ a_delete("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").should have_been_made
224
+ end
225
+ end
226
+
227
+ context "failed to create resource" do
228
+ before do
229
+ stub_delete("/authorizations/#{authorization_id}", "https://#{basic_auth}@api.github.com").
230
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
231
+
232
+ end
233
+
234
+ it "should fail to retrieve resource" do
235
+ expect {
236
+ github.oauth.delete_authorization authorization_id
237
+ }.to raise_error(Github::ResourceNotFound)
238
+ end
239
+ end
240
+ end # delete_authorization
241
+
242
+ end # Github::Authorizations