github_api 0.8.11 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/README.md +21 -14
  2. data/features/activity/notifications.feature +15 -0
  3. data/features/cassettes/activity/notifications/list_user.yml +54 -0
  4. data/features/step_definitions/common_steps.rb +8 -9
  5. data/lib/github_api.rb +3 -4
  6. data/lib/github_api/activity.rb +8 -13
  7. data/lib/github_api/activity/events.rb +0 -5
  8. data/lib/github_api/activity/notifications.rb +0 -5
  9. data/lib/github_api/api.rb +27 -22
  10. data/lib/github_api/api_factory.rb +13 -12
  11. data/lib/github_api/authorizations.rb +0 -5
  12. data/lib/github_api/client.rb +33 -33
  13. data/lib/github_api/configuration.rb +10 -2
  14. data/lib/github_api/connection.rb +2 -3
  15. data/lib/github_api/constants.rb +0 -3
  16. data/lib/github_api/gists.rb +2 -7
  17. data/lib/github_api/git_data.rb +10 -15
  18. data/lib/github_api/git_data/blobs.rb +0 -5
  19. data/lib/github_api/git_data/commits.rb +0 -5
  20. data/lib/github_api/git_data/references.rb +3 -7
  21. data/lib/github_api/git_data/tags.rb +0 -5
  22. data/lib/github_api/git_data/trees.rb +0 -5
  23. data/lib/github_api/gitignore.rb +0 -5
  24. data/lib/github_api/issues.rb +10 -15
  25. data/lib/github_api/issues/comments.rb +0 -5
  26. data/lib/github_api/issues/events.rb +0 -5
  27. data/lib/github_api/issues/labels.rb +0 -5
  28. data/lib/github_api/issues/milestones.rb +0 -5
  29. data/lib/github_api/markdown.rb +0 -5
  30. data/lib/github_api/meta.rb +0 -5
  31. data/lib/github_api/orgs.rb +4 -9
  32. data/lib/github_api/page_iterator.rb +44 -29
  33. data/lib/github_api/paged_request.rb +12 -12
  34. data/lib/github_api/{result.rb → pagination.rb} +19 -86
  35. data/lib/github_api/params_hash.rb +1 -1
  36. data/lib/github_api/pull_requests.rb +2 -7
  37. data/lib/github_api/repos.rb +22 -27
  38. data/lib/github_api/request.rb +7 -4
  39. data/lib/github_api/response/header.rb +76 -0
  40. data/lib/github_api/response_wrapper.rb +126 -0
  41. data/lib/github_api/scopes.rb +1 -1
  42. data/lib/github_api/search.rb +0 -5
  43. data/lib/github_api/users.rb +6 -11
  44. data/lib/github_api/version.rb +2 -2
  45. data/spec/github/activity/notifications/get_spec.rb +1 -1
  46. data/spec/github/activity/starring/starred_spec.rb +1 -1
  47. data/spec/github/activity/watching/watched_spec.rb +1 -1
  48. data/spec/github/api_factory_spec.rb +7 -8
  49. data/spec/github/api_spec.rb +0 -7
  50. data/spec/github/authorization_spec.rb +22 -32
  51. data/spec/github/authorizations/create_spec.rb +49 -0
  52. data/spec/github/authorizations/delete_spec.rb +39 -0
  53. data/spec/github/authorizations/get_spec.rb +49 -0
  54. data/spec/github/authorizations/list_spec.rb +55 -0
  55. data/spec/github/authorizations/update_spec.rb +50 -0
  56. data/spec/github/authorizations_spec.rb +2 -236
  57. data/spec/github/gists/comments/create_spec.rb +1 -1
  58. data/spec/github/gists/comments/edit_spec.rb +1 -1
  59. data/spec/github/gists/comments/get_spec.rb +1 -1
  60. data/spec/github/gists/create_spec.rb +1 -1
  61. data/spec/github/gists/edit_spec.rb +1 -1
  62. data/spec/github/gists/fork_spec.rb +1 -1
  63. data/spec/github/gists/get_spec.rb +1 -1
  64. data/spec/github/git_data/blobs/create_spec.rb +1 -1
  65. data/spec/github/git_data/blobs/get_spec.rb +1 -1
  66. data/spec/github/git_data/commits/create_spec.rb +1 -1
  67. data/spec/github/git_data/commits/get_spec.rb +1 -1
  68. data/spec/github/git_data/references/create_spec.rb +2 -2
  69. data/spec/github/git_data/references/get_spec.rb +1 -1
  70. data/spec/github/git_data/references/list_spec.rb +16 -6
  71. data/spec/github/git_data/tags/create_spec.rb +1 -1
  72. data/spec/github/git_data/tags/get_spec.rb +1 -1
  73. data/spec/github/git_data/trees/create_spec.rb +1 -1
  74. data/spec/github/git_data/trees/get_spec.rb +4 -4
  75. data/spec/github/issues/comments/create_spec.rb +1 -1
  76. data/spec/github/issues/comments/edit_spec.rb +1 -1
  77. data/spec/github/issues/comments/get_spec.rb +1 -1
  78. data/spec/github/issues/create_spec.rb +1 -1
  79. data/spec/github/issues/edit_spec.rb +1 -1
  80. data/spec/github/issues/events/get_spec.rb +1 -1
  81. data/spec/github/issues/get_spec.rb +1 -1
  82. data/spec/github/issues/labels/create_spec.rb +1 -1
  83. data/spec/github/issues/labels/get_spec.rb +1 -1
  84. data/spec/github/issues/labels/update_spec.rb +1 -1
  85. data/spec/github/issues/milestones/create_spec.rb +1 -1
  86. data/spec/github/issues/milestones/delete_spec.rb +1 -1
  87. data/spec/github/issues/milestones/get_spec.rb +1 -1
  88. data/spec/github/issues/milestones/update_spec.rb +1 -1
  89. data/spec/github/orgs/edit_spec.rb +1 -1
  90. data/spec/github/orgs/get_spec.rb +1 -1
  91. data/spec/github/orgs/teams/create_spec.rb +1 -1
  92. data/spec/github/orgs/teams/edit_spec.rb +1 -1
  93. data/spec/github/orgs/teams/get_spec.rb +1 -1
  94. data/spec/github/paged_request_spec.rb +34 -29
  95. data/spec/github/pagination/iterator/number_spec.rb +118 -0
  96. data/spec/github/pagination/iterator/sha_spec.rb +67 -0
  97. data/spec/github/pull_requests/comments/create_spec.rb +1 -1
  98. data/spec/github/pull_requests/comments/edit_spec.rb +1 -1
  99. data/spec/github/pull_requests/comments/get_spec.rb +1 -1
  100. data/spec/github/pull_requests/create_spec.rb +1 -1
  101. data/spec/github/pull_requests/get_spec.rb +1 -1
  102. data/spec/github/pull_requests/update_spec.rb +1 -1
  103. data/spec/github/repos/branch_spec.rb +1 -1
  104. data/spec/github/repos/comments/create_spec.rb +1 -1
  105. data/spec/github/repos/comments/get_spec.rb +1 -1
  106. data/spec/github/repos/comments/update_spec.rb +1 -1
  107. data/spec/github/repos/commits/get_spec.rb +1 -1
  108. data/spec/github/repos/create_spec.rb +1 -1
  109. data/spec/github/repos/downloads/create_spec.rb +1 -1
  110. data/spec/github/repos/downloads/get_spec.rb +1 -1
  111. data/spec/github/repos/edit_spec.rb +1 -1
  112. data/spec/github/repos/forks/create_spec.rb +1 -1
  113. data/spec/github/repos/get_spec.rb +1 -1
  114. data/spec/github/repos/hooks/create_spec.rb +1 -1
  115. data/spec/github/repos/hooks/edit_spec.rb +1 -1
  116. data/spec/github/repos/hooks/get_spec.rb +1 -1
  117. data/spec/github/repos/languages_spec.rb +1 -1
  118. data/spec/github/repos/merging/merge_spec.rb +1 -1
  119. data/spec/github/repos/statuses/create_spec.rb +1 -1
  120. data/spec/github/repos/tags_spec.rb +1 -1
  121. data/spec/github/repos/teams_spec.rb +1 -1
  122. data/spec/github/request/endpoint_spec.rb +24 -0
  123. data/spec/github/request/request_spec.rb +38 -0
  124. data/spec/github/{result_spec.rb → response_wrapper_spec.rb} +14 -13
  125. data/spec/github/users/emails/list_spec.rb +1 -1
  126. data/spec/github/users/get_spec.rb +2 -7
  127. data/spec/github/users/keys/create_spec.rb +1 -1
  128. data/spec/github/users/keys/get_spec.rb +1 -1
  129. data/spec/github/users/keys/update_spec.rb +1 -1
  130. data/spec/github/users/update_spec.rb +1 -1
  131. data/spec/github_spec.rb +1 -6
  132. data/spec/{github/activity → integration}/activity_spec.rb +0 -0
  133. data/spec/{github/gists → integration}/gists_spec.rb +2 -0
  134. data/spec/{github/git_data → integration}/git_data_spec.rb +0 -0
  135. data/spec/{github/issues → integration}/issues_spec.rb +2 -0
  136. data/spec/integration/options_spec.rb +103 -23
  137. data/spec/{github/orgs → integration}/orgs_spec.rb +0 -0
  138. data/spec/{github/pull_requests → integration}/pull_requests_spec.rb +0 -0
  139. data/spec/{github → integration}/repos_spec.rb +2 -0
  140. data/spec/{github/users → integration}/users_spec.rb +0 -0
  141. data/spec/shared/array_of_resources_behaviour.rb +1 -1
  142. metadata +55 -46
  143. data/lib/github_api/page_uri_processor.rb +0 -25
  144. data/lib/github_api/response/helpers.rb +0 -21
  145. data/spec/github/page_iterator_spec.rb +0 -260
  146. data/spec/github/response/helpers_spec.rb +0 -16
@@ -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
 
@@ -4,11 +4,6 @@ module Github
4
4
  class Search < API
5
5
  include Github::Utils::Url
6
6
 
7
- # Creates new Search API
8
- def initialize(options = {})
9
- super(options)
10
- end
11
-
12
7
  # Search issues
13
8
  #
14
9
  # Find issues by state and keyword.
@@ -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 'Users::Emails'
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 'Users::Followers'
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 'Users::Keys'
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.
@@ -3,8 +3,8 @@
3
3
  module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
- MINOR = 8
7
- PATCH = 11
6
+ MINOR = 9
7
+ PATCH = 0
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -30,7 +30,7 @@ describe Github::Activity::Notifications, '#get' do
30
30
 
31
31
  it "should return repository mash" do
32
32
  threads = subject.get thread_id
33
- threads.should be_an Array
33
+ threads.should be_an Enumerable
34
34
  threads.should have(1).items
35
35
  end
36
36
 
@@ -40,7 +40,7 @@ describe Github::Activity::Starring, '#starred' do
40
40
 
41
41
  it "should return array of resources" do
42
42
  starred = subject.starred
43
- starred.should be_an Array
43
+ starred.should be_an Enumerable
44
44
  starred.should have(1).items
45
45
  end
46
46
 
@@ -40,7 +40,7 @@ describe Github::Activity::Watching, '#watched' do
40
40
 
41
41
  it "should return array of resources" do
42
42
  watched = subject.watched
43
- watched.should be_an Array
43
+ watched.should be_an Enumerable
44
44
  watched.should have(1).items
45
45
  end
46
46
 
@@ -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 { described_class.new nil }.to raise_error(ArgumentError)
11
+ expect { factory.new nil }.to raise_error(ArgumentError)
10
12
  end
11
13
 
12
14
  it 'instantiates a new object' do
13
- described_class.new('Repos').should be_a Github::Repos
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 'sets api client' do
19
- instance = Github::Issues::Labels.new
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
- described_class.convert_to_constant('Issues::Labels').
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
@@ -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(:github) {
10
- Github.new :client_id => client_id, :client_secret => client_secret
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 { github.should respond_to :client }
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
- it "should respond to 'authorize_url' " do
61
- github.should respond_to :authorize_url
62
- end
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 "should respond to 'get_token' " do
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 { github.should respond_to :authenticated? }
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?.should be_false
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 { github.should respond_to :basic_authed? }
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?.should be_true
130
+ expect(github.basic_authed?).to be_true
134
131
  end
135
132
  end
136
133
 
137
134
  context "authentication" do
138
- it "should respond to 'authentication'" do
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.should be_empty
140
+ expect(github.authentication).to be_empty
146
141
  end
147
142
 
148
143
  context 'basic_auth' do
149
- before do
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.should be_a Hash
155
- github.authentication.should have_key :basic_auth
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
- before do
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.should be_a Hash
167
- github.authentication.should have_key :login
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