github_api 0.8.11 → 0.9.0
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.
- data/README.md +21 -14
- data/features/activity/notifications.feature +15 -0
- data/features/cassettes/activity/notifications/list_user.yml +54 -0
- data/features/step_definitions/common_steps.rb +8 -9
- data/lib/github_api.rb +3 -4
- data/lib/github_api/activity.rb +8 -13
- data/lib/github_api/activity/events.rb +0 -5
- data/lib/github_api/activity/notifications.rb +0 -5
- data/lib/github_api/api.rb +27 -22
- data/lib/github_api/api_factory.rb +13 -12
- data/lib/github_api/authorizations.rb +0 -5
- data/lib/github_api/client.rb +33 -33
- data/lib/github_api/configuration.rb +10 -2
- data/lib/github_api/connection.rb +2 -3
- data/lib/github_api/constants.rb +0 -3
- data/lib/github_api/gists.rb +2 -7
- data/lib/github_api/git_data.rb +10 -15
- data/lib/github_api/git_data/blobs.rb +0 -5
- data/lib/github_api/git_data/commits.rb +0 -5
- data/lib/github_api/git_data/references.rb +3 -7
- data/lib/github_api/git_data/tags.rb +0 -5
- data/lib/github_api/git_data/trees.rb +0 -5
- data/lib/github_api/gitignore.rb +0 -5
- data/lib/github_api/issues.rb +10 -15
- data/lib/github_api/issues/comments.rb +0 -5
- data/lib/github_api/issues/events.rb +0 -5
- data/lib/github_api/issues/labels.rb +0 -5
- data/lib/github_api/issues/milestones.rb +0 -5
- data/lib/github_api/markdown.rb +0 -5
- data/lib/github_api/meta.rb +0 -5
- data/lib/github_api/orgs.rb +4 -9
- data/lib/github_api/page_iterator.rb +44 -29
- data/lib/github_api/paged_request.rb +12 -12
- data/lib/github_api/{result.rb → pagination.rb} +19 -86
- data/lib/github_api/params_hash.rb +1 -1
- data/lib/github_api/pull_requests.rb +2 -7
- data/lib/github_api/repos.rb +22 -27
- data/lib/github_api/request.rb +7 -4
- data/lib/github_api/response/header.rb +76 -0
- data/lib/github_api/response_wrapper.rb +126 -0
- data/lib/github_api/scopes.rb +1 -1
- data/lib/github_api/search.rb +0 -5
- data/lib/github_api/users.rb +6 -11
- data/lib/github_api/version.rb +2 -2
- data/spec/github/activity/notifications/get_spec.rb +1 -1
- data/spec/github/activity/starring/starred_spec.rb +1 -1
- data/spec/github/activity/watching/watched_spec.rb +1 -1
- data/spec/github/api_factory_spec.rb +7 -8
- data/spec/github/api_spec.rb +0 -7
- data/spec/github/authorization_spec.rb +22 -32
- data/spec/github/authorizations/create_spec.rb +49 -0
- data/spec/github/authorizations/delete_spec.rb +39 -0
- data/spec/github/authorizations/get_spec.rb +49 -0
- data/spec/github/authorizations/list_spec.rb +55 -0
- data/spec/github/authorizations/update_spec.rb +50 -0
- data/spec/github/authorizations_spec.rb +2 -236
- data/spec/github/gists/comments/create_spec.rb +1 -1
- data/spec/github/gists/comments/edit_spec.rb +1 -1
- data/spec/github/gists/comments/get_spec.rb +1 -1
- data/spec/github/gists/create_spec.rb +1 -1
- data/spec/github/gists/edit_spec.rb +1 -1
- data/spec/github/gists/fork_spec.rb +1 -1
- data/spec/github/gists/get_spec.rb +1 -1
- data/spec/github/git_data/blobs/create_spec.rb +1 -1
- data/spec/github/git_data/blobs/get_spec.rb +1 -1
- data/spec/github/git_data/commits/create_spec.rb +1 -1
- data/spec/github/git_data/commits/get_spec.rb +1 -1
- data/spec/github/git_data/references/create_spec.rb +2 -2
- data/spec/github/git_data/references/get_spec.rb +1 -1
- data/spec/github/git_data/references/list_spec.rb +16 -6
- data/spec/github/git_data/tags/create_spec.rb +1 -1
- data/spec/github/git_data/tags/get_spec.rb +1 -1
- data/spec/github/git_data/trees/create_spec.rb +1 -1
- data/spec/github/git_data/trees/get_spec.rb +4 -4
- data/spec/github/issues/comments/create_spec.rb +1 -1
- data/spec/github/issues/comments/edit_spec.rb +1 -1
- data/spec/github/issues/comments/get_spec.rb +1 -1
- data/spec/github/issues/create_spec.rb +1 -1
- data/spec/github/issues/edit_spec.rb +1 -1
- data/spec/github/issues/events/get_spec.rb +1 -1
- data/spec/github/issues/get_spec.rb +1 -1
- data/spec/github/issues/labels/create_spec.rb +1 -1
- data/spec/github/issues/labels/get_spec.rb +1 -1
- data/spec/github/issues/labels/update_spec.rb +1 -1
- data/spec/github/issues/milestones/create_spec.rb +1 -1
- data/spec/github/issues/milestones/delete_spec.rb +1 -1
- data/spec/github/issues/milestones/get_spec.rb +1 -1
- data/spec/github/issues/milestones/update_spec.rb +1 -1
- data/spec/github/orgs/edit_spec.rb +1 -1
- data/spec/github/orgs/get_spec.rb +1 -1
- data/spec/github/orgs/teams/create_spec.rb +1 -1
- data/spec/github/orgs/teams/edit_spec.rb +1 -1
- data/spec/github/orgs/teams/get_spec.rb +1 -1
- data/spec/github/paged_request_spec.rb +34 -29
- data/spec/github/pagination/iterator/number_spec.rb +118 -0
- data/spec/github/pagination/iterator/sha_spec.rb +67 -0
- data/spec/github/pull_requests/comments/create_spec.rb +1 -1
- data/spec/github/pull_requests/comments/edit_spec.rb +1 -1
- data/spec/github/pull_requests/comments/get_spec.rb +1 -1
- data/spec/github/pull_requests/create_spec.rb +1 -1
- data/spec/github/pull_requests/get_spec.rb +1 -1
- data/spec/github/pull_requests/update_spec.rb +1 -1
- data/spec/github/repos/branch_spec.rb +1 -1
- data/spec/github/repos/comments/create_spec.rb +1 -1
- data/spec/github/repos/comments/get_spec.rb +1 -1
- data/spec/github/repos/comments/update_spec.rb +1 -1
- data/spec/github/repos/commits/get_spec.rb +1 -1
- data/spec/github/repos/create_spec.rb +1 -1
- data/spec/github/repos/downloads/create_spec.rb +1 -1
- data/spec/github/repos/downloads/get_spec.rb +1 -1
- data/spec/github/repos/edit_spec.rb +1 -1
- data/spec/github/repos/forks/create_spec.rb +1 -1
- data/spec/github/repos/get_spec.rb +1 -1
- data/spec/github/repos/hooks/create_spec.rb +1 -1
- data/spec/github/repos/hooks/edit_spec.rb +1 -1
- data/spec/github/repos/hooks/get_spec.rb +1 -1
- data/spec/github/repos/languages_spec.rb +1 -1
- data/spec/github/repos/merging/merge_spec.rb +1 -1
- data/spec/github/repos/statuses/create_spec.rb +1 -1
- data/spec/github/repos/tags_spec.rb +1 -1
- data/spec/github/repos/teams_spec.rb +1 -1
- data/spec/github/request/endpoint_spec.rb +24 -0
- data/spec/github/request/request_spec.rb +38 -0
- data/spec/github/{result_spec.rb → response_wrapper_spec.rb} +14 -13
- data/spec/github/users/emails/list_spec.rb +1 -1
- data/spec/github/users/get_spec.rb +2 -7
- data/spec/github/users/keys/create_spec.rb +1 -1
- data/spec/github/users/keys/get_spec.rb +1 -1
- data/spec/github/users/keys/update_spec.rb +1 -1
- data/spec/github/users/update_spec.rb +1 -1
- data/spec/github_spec.rb +1 -6
- data/spec/{github/activity → integration}/activity_spec.rb +0 -0
- data/spec/{github/gists → integration}/gists_spec.rb +2 -0
- data/spec/{github/git_data → integration}/git_data_spec.rb +0 -0
- data/spec/{github/issues → integration}/issues_spec.rb +2 -0
- data/spec/integration/options_spec.rb +103 -23
- data/spec/{github/orgs → integration}/orgs_spec.rb +0 -0
- data/spec/{github/pull_requests → integration}/pull_requests_spec.rb +0 -0
- data/spec/{github → integration}/repos_spec.rb +2 -0
- data/spec/{github/users → integration}/users_spec.rb +0 -0
- data/spec/shared/array_of_resources_behaviour.rb +1 -1
- metadata +55 -46
- data/lib/github_api/page_uri_processor.rb +0 -25
- data/lib/github_api/response/helpers.rb +0 -21
- data/spec/github/page_iterator_spec.rb +0 -260
- data/spec/github/response/helpers_spec.rb +0 -16
data/lib/github_api/scopes.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Github
|
|
|
11
11
|
#
|
|
12
12
|
def list(params={})
|
|
13
13
|
response = get_request("/user", params)
|
|
14
|
-
response.oauth_scopes ? response.oauth_scopes.split(',') : response
|
|
14
|
+
response.headers.oauth_scopes ? response.headers.oauth_scopes.split(',') : response
|
|
15
15
|
end
|
|
16
16
|
alias :all :list
|
|
17
17
|
|
data/lib/github_api/search.rb
CHANGED
data/lib/github_api/users.rb
CHANGED
|
@@ -20,24 +20,19 @@ module Github
|
|
|
20
20
|
bio
|
|
21
21
|
].freeze
|
|
22
22
|
|
|
23
|
-
# Creates new Repos API
|
|
24
|
-
def initialize(options = {})
|
|
25
|
-
super(options)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
23
|
# Access to Users::Emails API
|
|
29
|
-
def emails
|
|
30
|
-
@emails ||= ApiFactory.new
|
|
24
|
+
def emails(options={}, &block)
|
|
25
|
+
@emails ||= ApiFactory.new('Users::Emails', current_options.merge(options), &block)
|
|
31
26
|
end
|
|
32
27
|
|
|
33
28
|
# Access to Users::Followers API
|
|
34
|
-
def followers
|
|
35
|
-
@followers ||= ApiFactory.new
|
|
29
|
+
def followers(options={}, &block)
|
|
30
|
+
@followers ||= ApiFactory.new('Users::Followers', current_options.merge(options), &block)
|
|
36
31
|
end
|
|
37
32
|
|
|
38
33
|
# Access to Users::Keys API
|
|
39
|
-
def keys
|
|
40
|
-
@keys ||= ApiFactory.new
|
|
34
|
+
def keys(options={}, &block)
|
|
35
|
+
@keys ||= ApiFactory.new('Users::Keys', current_options.merge(options), &block)
|
|
41
36
|
end
|
|
42
37
|
|
|
43
38
|
# List all users.
|
data/lib/github_api/version.rb
CHANGED
|
@@ -4,28 +4,27 @@ require 'spec_helper'
|
|
|
4
4
|
|
|
5
5
|
describe Github::ApiFactory do
|
|
6
6
|
|
|
7
|
+
subject(:factory) { described_class }
|
|
8
|
+
|
|
7
9
|
context '#new' do
|
|
8
10
|
it 'throws error if klass type is ommitted' do
|
|
9
|
-
expect {
|
|
11
|
+
expect { factory.new nil }.to raise_error(ArgumentError)
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
it 'instantiates a new object' do
|
|
13
|
-
|
|
15
|
+
expect(factory.new('Repos')).to be_a Github::Repos
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
context '#create_instance' do
|
|
18
|
-
it '
|
|
19
|
-
|
|
20
|
-
Github.should_receive(:api_client=).twice().and_return instance
|
|
21
|
-
described_class.create_instance('Issues::Labels', {})
|
|
20
|
+
it 'creates class instance' do
|
|
21
|
+
expect(factory.create_instance('Issues::Labels', {})).to be_kind_of(Github::Issues::Labels)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
context '#convert_to_constant' do
|
|
26
26
|
it 'knows how to convert nested classes' do
|
|
27
|
-
|
|
28
|
-
should == Github::Issues::Labels
|
|
27
|
+
expect(factory.convert_to_constant('Issues::Labels')).to eql Github::Issues::Labels
|
|
29
28
|
end
|
|
30
29
|
end
|
|
31
30
|
end # Github::ApiFactory
|
data/spec/github/api_spec.rb
CHANGED
|
@@ -39,13 +39,6 @@ describe Github::API do
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
context '_set_api_client' do
|
|
43
|
-
it 'should set instantiated api class as main api client' do
|
|
44
|
-
repos_instance = repos.new
|
|
45
|
-
Github.api_client.should eq repos_instance
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
42
|
context 'normalize!' do
|
|
50
43
|
before do
|
|
51
44
|
@params = { 'a' => { :b => { 'c' => 1 }, 'd' => [ 'a', { :e => 2 }] } }
|
|
@@ -6,17 +6,16 @@ describe Github::Authorization do
|
|
|
6
6
|
let(:client_id) { '234jl23j4l23j4l' }
|
|
7
7
|
let(:client_secret) { 'asasd79sdf9a7asfd7sfd97s' }
|
|
8
8
|
let(:code) { 'c9798sdf97df98ds'}
|
|
9
|
-
let(:
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
let(:options) { {} }
|
|
10
|
+
|
|
11
|
+
subject(:github) { Github.new options }
|
|
12
12
|
|
|
13
13
|
after do
|
|
14
|
-
github.client_id, github.client_secret = nil, nil
|
|
15
14
|
reset_authentication_for github
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
context '.client' do
|
|
19
|
-
it {
|
|
18
|
+
it { should respond_to :client }
|
|
20
19
|
|
|
21
20
|
it "should return OAuth2::Client instance" do
|
|
22
21
|
github.client.should be_a OAuth2::Client
|
|
@@ -39,12 +38,10 @@ describe Github::Authorization do
|
|
|
39
38
|
let(:oauth) { OAuth2::Client.new(client_id, client_secret) }
|
|
40
39
|
|
|
41
40
|
it "should throw an error if no client_id" do
|
|
42
|
-
github.client_id = nil
|
|
43
41
|
expect { github.auth_code }.to raise_error(ArgumentError)
|
|
44
42
|
end
|
|
45
43
|
|
|
46
44
|
it "should throw an error if no client_secret" do
|
|
47
|
-
github.client_secret = nil
|
|
48
45
|
expect { github.auth_code }.to raise_error(ArgumentError)
|
|
49
46
|
end
|
|
50
47
|
|
|
@@ -57,9 +54,9 @@ describe Github::Authorization do
|
|
|
57
54
|
end
|
|
58
55
|
|
|
59
56
|
context "authorize_url" do
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
let(:options) { {:client_id => client_id, :client_secret => client_secret} }
|
|
58
|
+
|
|
59
|
+
it { should respond_to(:authorize_url) }
|
|
63
60
|
|
|
64
61
|
it "should return address containing client_id" do
|
|
65
62
|
github.authorize_url.should =~ /client_id=#{client_id}/
|
|
@@ -75,14 +72,14 @@ describe Github::Authorization do
|
|
|
75
72
|
end
|
|
76
73
|
|
|
77
74
|
context "get_token" do
|
|
75
|
+
let(:options) { {:client_id => client_id, :client_secret => client_secret} }
|
|
76
|
+
|
|
78
77
|
before do
|
|
79
78
|
stub_request(:post, 'https://github.com/login/oauth/access_token').
|
|
80
79
|
to_return(:body => '', :status => 200, :headers => {})
|
|
81
80
|
end
|
|
82
81
|
|
|
83
|
-
it
|
|
84
|
-
github.should respond_to :get_token
|
|
85
|
-
end
|
|
82
|
+
it { should respond_to(:get_token) }
|
|
86
83
|
|
|
87
84
|
it "should make the authorization request" do
|
|
88
85
|
expect {
|
|
@@ -97,11 +94,11 @@ describe Github::Authorization do
|
|
|
97
94
|
end
|
|
98
95
|
|
|
99
96
|
context ".authenticated?" do
|
|
100
|
-
it {
|
|
97
|
+
it { should respond_to(:authenticated?) }
|
|
101
98
|
|
|
102
99
|
it "should return false if falied on basic authentication" do
|
|
103
100
|
github.stub(:basic_authed?).and_return false
|
|
104
|
-
github.authenticated
|
|
101
|
+
expect(github.authenticated?).to be_false
|
|
105
102
|
end
|
|
106
103
|
|
|
107
104
|
it "should return true if basic authentication performed" do
|
|
@@ -120,7 +117,7 @@ describe Github::Authorization do
|
|
|
120
117
|
github.stub(:basic_auth?).and_return false
|
|
121
118
|
end
|
|
122
119
|
|
|
123
|
-
it {
|
|
120
|
+
it { should respond_to(:basic_authed?) }
|
|
124
121
|
|
|
125
122
|
it "should return false if login is missing" do
|
|
126
123
|
github.stub(:login?).and_return false
|
|
@@ -130,41 +127,34 @@ describe Github::Authorization do
|
|
|
130
127
|
it "should return true if login && password provided" do
|
|
131
128
|
github.stub(:login?).and_return true
|
|
132
129
|
github.stub(:password?).and_return true
|
|
133
|
-
github.basic_authed
|
|
130
|
+
expect(github.basic_authed?).to be_true
|
|
134
131
|
end
|
|
135
132
|
end
|
|
136
133
|
|
|
137
134
|
context "authentication" do
|
|
138
|
-
it
|
|
139
|
-
github.should respond_to :authentication
|
|
140
|
-
end
|
|
135
|
+
it { should respond_to(:authentication) }
|
|
141
136
|
|
|
142
137
|
it "should return empty hash if no basic authentication params available" do
|
|
143
138
|
github.stub(:login?).and_return false
|
|
144
139
|
github.stub(:basic_auth?).and_return false
|
|
145
|
-
github.authentication.
|
|
140
|
+
expect(github.authentication).to be_empty
|
|
146
141
|
end
|
|
147
142
|
|
|
148
143
|
context 'basic_auth' do
|
|
149
|
-
|
|
150
|
-
github = Github.new :basic_auth => 'github:pass'
|
|
151
|
-
end
|
|
144
|
+
let(:options) { { :basic_auth => 'github:pass' } }
|
|
152
145
|
|
|
153
146
|
it "should return hash with basic auth params" do
|
|
154
|
-
github.authentication.
|
|
155
|
-
github.authentication.
|
|
147
|
+
expect(github.authentication).to be_a Hash
|
|
148
|
+
expect(github.authentication).to have_key(:basic_auth)
|
|
156
149
|
end
|
|
157
150
|
end
|
|
158
151
|
|
|
159
152
|
context 'login & password' do
|
|
160
|
-
|
|
161
|
-
github = Github.new :login => 'github', :password => 'pass'
|
|
162
|
-
github.basic_auth = nil
|
|
163
|
-
end
|
|
153
|
+
let(:options) { { :login => 'github', :password => 'pass' } }
|
|
164
154
|
|
|
165
155
|
it "should return hash with login & password params" do
|
|
166
|
-
github.authentication.
|
|
167
|
-
github.authentication.
|
|
156
|
+
expect(github.authentication).to be_a Hash
|
|
157
|
+
expect(github.authentication).to have_key(:login)
|
|
168
158
|
end
|
|
169
159
|
end
|
|
170
160
|
end # authentication
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Github::Authorizations, '#create' do
|
|
6
|
+
let(:basic_auth) { 'login:password' }
|
|
7
|
+
let(:request_path) { "/authorizations" }
|
|
8
|
+
let(:host) { "https://#{basic_auth}@api.github.com" }
|
|
9
|
+
let(:inputs) { { :scopes => ['repo'] } }
|
|
10
|
+
|
|
11
|
+
before {
|
|
12
|
+
stub_post(request_path, host).to_return(:body => body, :status => status,
|
|
13
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
before { subject.basic_auth = basic_auth }
|
|
17
|
+
|
|
18
|
+
after { reset_authentication_for(subject) }
|
|
19
|
+
|
|
20
|
+
context "resouce created" do
|
|
21
|
+
let(:body) { fixture('auths/authorization.json') }
|
|
22
|
+
let(:status) { 201 }
|
|
23
|
+
|
|
24
|
+
it "should fail to get resource without basic authentication" do
|
|
25
|
+
reset_authentication_for subject
|
|
26
|
+
expect { subject.create }.to raise_error(ArgumentError)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should create resource successfully" do
|
|
30
|
+
subject.create inputs
|
|
31
|
+
a_post(request_path, host).with(inputs).should have_been_made
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should return the resource" do
|
|
35
|
+
authorization = subject.create inputs
|
|
36
|
+
authorization.should be_a Github::ResponseWrapper
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should get the authorization information" do
|
|
40
|
+
authorization = subject.create inputs
|
|
41
|
+
authorization.token.should == 'abc123'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it_should_behave_like 'request failure' do
|
|
46
|
+
let(:requestable) { subject.create inputs }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end # create
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Github::Authorizations, '#delete' do
|
|
6
|
+
let(:basic_auth) { 'login:password' }
|
|
7
|
+
let(:request_path) { "/authorizations/#{authorization_id}" }
|
|
8
|
+
let(:host) { "https://#{basic_auth}@api.github.com" }
|
|
9
|
+
let(:authorization_id) { 1 }
|
|
10
|
+
|
|
11
|
+
before {
|
|
12
|
+
stub_delete(request_path, host).to_return(:body => body, :status => status,
|
|
13
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
before { subject.basic_auth = basic_auth }
|
|
17
|
+
|
|
18
|
+
after { reset_authentication_for(subject) }
|
|
19
|
+
|
|
20
|
+
context "resouce deleted" do
|
|
21
|
+
let(:body) { '' }
|
|
22
|
+
let(:status) { 204 }
|
|
23
|
+
|
|
24
|
+
it "should fail to get resource without basic authentication" do
|
|
25
|
+
reset_authentication_for subject
|
|
26
|
+
expect { subject.delete nil }.to raise_error(ArgumentError)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should delete resource successfully" do
|
|
30
|
+
subject.delete authorization_id
|
|
31
|
+
a_delete(request_path, host).should have_been_made
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it_should_behave_like 'request failure' do
|
|
36
|
+
let(:requestable) { subject.delete authorization_id }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end # delete
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Github::Authorizations, '#get' do
|
|
6
|
+
let(:basic_auth) { 'login:password' }
|
|
7
|
+
let(:request_path) { "/authorizations/#{authorization_id}" }
|
|
8
|
+
let(:host) { "https://#{basic_auth}@api.github.com" }
|
|
9
|
+
let(:authorization_id) { 1 }
|
|
10
|
+
|
|
11
|
+
before {
|
|
12
|
+
stub_get(request_path, host).to_return(:body => body, :status => status,
|
|
13
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
before { subject.basic_auth = basic_auth }
|
|
17
|
+
|
|
18
|
+
after { reset_authentication_for(subject) }
|
|
19
|
+
|
|
20
|
+
context "resource found" do
|
|
21
|
+
let(:body) { fixture('auths/authorization.json') }
|
|
22
|
+
let(:status) { 200 }
|
|
23
|
+
|
|
24
|
+
it "should fail to get resource without authorization id" do
|
|
25
|
+
expect { subject.get nil }.to raise_error(ArgumentError)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should get the resource" do
|
|
29
|
+
subject.get authorization_id
|
|
30
|
+
a_get(request_path, host).should have_been_made
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should get authorization information" do
|
|
34
|
+
authorization = subject.get authorization_id
|
|
35
|
+
authorization.id.should == authorization_id
|
|
36
|
+
authorization.token.should == 'abc123'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should return mash" do
|
|
40
|
+
authorization = subject.get authorization_id
|
|
41
|
+
authorization.should be_a Github::ResponseWrapper
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it_should_behave_like 'request failure' do
|
|
46
|
+
let(:requestable) { subject.get authorization_id }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end # list
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Github::Authorizations, '#list' do
|
|
6
|
+
let(:basic_auth) { 'login:password' }
|
|
7
|
+
let(:request_path) { "/authorizations" }
|
|
8
|
+
let(:host) { "https://#{basic_auth}@api.github.com" }
|
|
9
|
+
|
|
10
|
+
before {
|
|
11
|
+
stub_get(request_path, host).to_return(:body => body, :status => status,
|
|
12
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
before { subject.basic_auth = basic_auth }
|
|
16
|
+
|
|
17
|
+
after { reset_authentication_for(subject) }
|
|
18
|
+
|
|
19
|
+
context "resource found" do
|
|
20
|
+
let(:body) { fixture('auths/authorizations.json') }
|
|
21
|
+
let(:status) { 200 }
|
|
22
|
+
|
|
23
|
+
it { should respond_to :all }
|
|
24
|
+
|
|
25
|
+
it "should fail to get resource without basic authentication" do
|
|
26
|
+
reset_authentication_for subject
|
|
27
|
+
expect { subject.list }.to raise_error(ArgumentError)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should get the resources" do
|
|
31
|
+
subject.list
|
|
32
|
+
a_get(request_path, host).should have_been_made
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it_should_behave_like 'an array of resources' do
|
|
36
|
+
let(:requestable) { subject.list }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should get authorization information" do
|
|
40
|
+
authorizations = subject.list
|
|
41
|
+
authorizations.first.token.should == 'abc123'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should yield to a block" do
|
|
45
|
+
yielded = []
|
|
46
|
+
result = subject.list { |obj| yielded << obj }
|
|
47
|
+
yielded.should == result
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it_should_behave_like 'request failure' do
|
|
52
|
+
let(:requestable) { subject.list }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end # authorizations
|