github_api 0.4.2 → 0.4.3
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 +2 -2
- data/features/authentication.feature +8 -0
- data/features/cassettes/errors/repos/create.yml +36 -0
- data/features/cassettes/gists/gist.yml +64 -0
- data/features/cassettes/gists/gist/first.yml +65 -0
- data/features/cassettes/gists/gists/public_all.yml +71 -0
- data/features/cassettes/gists/gists/user_all.yml +48 -0
- data/features/cassettes/gists/star.yml +34 -0
- data/features/cassettes/pagination/repos/per_page/1.yml +134 -0
- data/features/cassettes/pagination/repos/per_page/each_page.yml +395 -0
- data/features/cassettes/pagination/repos/per_page/first.yml +135 -0
- data/features/error_codes.feature +13 -0
- data/features/gists.feature +31 -0
- data/features/pagination.feature +10 -0
- data/features/repos.feature +12 -10
- data/features/step_definitions/github_api_steps.rb +20 -5
- data/features/support/env.rb +8 -0
- data/features/support/helpers.rb +7 -0
- data/lib/github_api.rb +6 -6
- data/lib/github_api/api.rb +19 -11
- data/lib/github_api/authorization.rb +3 -3
- data/lib/github_api/connection.rb +1 -1
- data/lib/github_api/core_ext/array.rb +1 -2
- data/lib/github_api/core_ext/hash.rb +16 -2
- data/lib/github_api/deprecation.rb +39 -0
- data/lib/github_api/gists.rb +27 -10
- data/lib/github_api/page_uri_processor.rb +6 -2
- data/lib/github_api/response/raise_error.rb +1 -1
- data/lib/github_api/result.rb +2 -1
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/gists/gist.json +58 -0
- data/spec/fixtures/gists/gists.json +28 -0
- data/spec/github/api_spec.rb +15 -0
- data/spec/github/authorization_spec.rb +5 -0
- data/spec/github/client_spec.rb +4 -0
- data/spec/github/core_ext/hash_spec.rb +45 -18
- data/spec/github/deprecation_spec.rb +31 -0
- data/spec/github/gists_spec.rb +461 -3
- data/spec/github/repos/watching_spec.rb +12 -4
- data/spec/github/request_spec.rb +3 -0
- data/spec/github_spec.rb +34 -29
- data/spec/spec_helper.rb +1 -0
- metadata +22 -4
@@ -11,11 +11,15 @@ module Github
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def resource_link
|
14
|
-
|
14
|
+
link
|
15
15
|
end
|
16
16
|
|
17
17
|
def query_hash
|
18
|
-
|
18
|
+
parsed_query = parse_query(query_string)
|
19
|
+
params = {}
|
20
|
+
if parsed_query.include? :last_sha
|
21
|
+
params[:sha] = parsed_query[:last_sha]
|
22
|
+
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -18,7 +18,7 @@ module Github
|
|
18
18
|
raise Github::ResourceNotFound.new(response_message(env), env[:response_headers])
|
19
19
|
|
20
20
|
when 422
|
21
|
-
raise Github::
|
21
|
+
raise Github::UnprocessableEntity.new(response_message(env), env[:response_headers])
|
22
22
|
when 500
|
23
23
|
raise Github::InternalServerError.new(response_message(env), env[:response_headers])
|
24
24
|
when 503
|
data/lib/github_api/result.rb
CHANGED
@@ -56,8 +56,9 @@ module Github
|
|
56
56
|
# Iterator like each for response pages. If there are no pages to
|
57
57
|
# iterate over this method will return nothing.
|
58
58
|
def each_page
|
59
|
+
yield self.body
|
59
60
|
while page_iterator.has_next?
|
60
|
-
yield next_page
|
61
|
+
yield next_page
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
data/lib/github_api/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"url": "https://api.github.com/gists/1",
|
3
|
+
"id": "1",
|
4
|
+
"description": "description of gist",
|
5
|
+
"public": true,
|
6
|
+
"user": {
|
7
|
+
"login": "octocat",
|
8
|
+
"id": 1,
|
9
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
10
|
+
"gravatar_id": "somehexcode",
|
11
|
+
"url": "https://api.github.com/users/octocat"
|
12
|
+
},
|
13
|
+
"files": {
|
14
|
+
"ring.erl": {
|
15
|
+
"size": 932,
|
16
|
+
"filename": "ring.erl",
|
17
|
+
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
|
18
|
+
"content": "contents of gist"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
"comments": 0,
|
22
|
+
"html_url": "https://gist.github.com/1",
|
23
|
+
"git_pull_url": "git://gist.github.com/1.git",
|
24
|
+
"git_push_url": "git@gist.github.com:1.git",
|
25
|
+
"created_at": "2010-04-14T02:15:15Z",
|
26
|
+
"forks": [
|
27
|
+
{
|
28
|
+
"user": {
|
29
|
+
"login": "octocat",
|
30
|
+
"id": 1,
|
31
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
32
|
+
"gravatar_id": "somehexcode",
|
33
|
+
"url": "https://api.github.com/users/octocat"
|
34
|
+
},
|
35
|
+
"url": "https://api.github.com/gists/5",
|
36
|
+
"created_at": "2011-04-14T16:00:49Z"
|
37
|
+
}
|
38
|
+
],
|
39
|
+
"history": [
|
40
|
+
{
|
41
|
+
"url": "https://api.github.com/gists/1/57a7f021a713b1c5a6a199b54cc514735d2d462f",
|
42
|
+
"version": "57a7f021a713b1c5a6a199b54cc514735d2d462f",
|
43
|
+
"user": {
|
44
|
+
"login": "octocat",
|
45
|
+
"id": 1,
|
46
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
47
|
+
"gravatar_id": "somehexcode",
|
48
|
+
"url": "https://api.github.com/users/octocat"
|
49
|
+
},
|
50
|
+
"change_status": {
|
51
|
+
"deletions": 0,
|
52
|
+
"additions": 180,
|
53
|
+
"total": 180
|
54
|
+
},
|
55
|
+
"committed_at": "2010-04-14T02:15:15Z"
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"url": "https://api.github.com/gists/1",
|
4
|
+
"id": "1",
|
5
|
+
"description": "description of gist",
|
6
|
+
"public": true,
|
7
|
+
"user": {
|
8
|
+
"login": "octocat",
|
9
|
+
"id": 1,
|
10
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
11
|
+
"gravatar_id": "somehexcode",
|
12
|
+
"url": "https://api.github.com/users/octocat"
|
13
|
+
},
|
14
|
+
"files": {
|
15
|
+
"ring.erl": {
|
16
|
+
"size": 932,
|
17
|
+
"filename": "ring.erl",
|
18
|
+
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
|
19
|
+
"content": "contents of gist"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"comments": 0,
|
23
|
+
"html_url": "https://gist.github.com/1",
|
24
|
+
"git_pull_url": "git://gist.github.com/1.git",
|
25
|
+
"git_push_url": "git@gist.github.com:1.git",
|
26
|
+
"created_at": "2010-04-14T02:15:15Z"
|
27
|
+
}
|
28
|
+
]
|
data/spec/github/api_spec.rb
CHANGED
@@ -29,6 +29,21 @@ describe Github::API do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
context '_process_basic_auth' do
|
33
|
+
it 'should parse authentication params' do
|
34
|
+
github = Github.new :basic_auth => 'login:password'
|
35
|
+
github.login.should eq 'login'
|
36
|
+
github.password.should eq 'password'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context '_set_api_client' do
|
41
|
+
it 'should set instantiated api class as main api client' do
|
42
|
+
repos_instance = repos.new
|
43
|
+
Github.api_client.should eq repos_instance
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
32
47
|
context '_normalize_params_keys' do
|
33
48
|
before do
|
34
49
|
@params = { 'a' => { :b => { 'c' => 1 }, 'd' => [ 'a', { :e => 2 }] } }
|
@@ -125,6 +125,10 @@ describe Github::Authorization do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
context ".basic_authed?" do
|
128
|
+
before do
|
129
|
+
github.stub(:basic_auth?).and_return false
|
130
|
+
end
|
131
|
+
|
128
132
|
it { github.should respond_to :basic_authed? }
|
129
133
|
|
130
134
|
it "should return false if login is missing" do
|
@@ -164,6 +168,7 @@ describe Github::Authorization do
|
|
164
168
|
context 'login & password' do
|
165
169
|
before do
|
166
170
|
github = Github.new :login => 'github', :password => 'pass'
|
171
|
+
github.basic_auth = nil
|
167
172
|
end
|
168
173
|
|
169
174
|
it "should return hash with login & password params" do
|
data/spec/github/client_spec.rb
CHANGED
@@ -32,6 +32,10 @@ describe Github::Client do
|
|
32
32
|
github.users.should be_a Github::Users
|
33
33
|
end
|
34
34
|
|
35
|
+
it "should return Github::Authorizations instance" do
|
36
|
+
github.oauth.should be_a Github::Authorizations
|
37
|
+
end
|
38
|
+
|
35
39
|
it "should respond to repos" do
|
36
40
|
github.should respond_to :repos
|
37
41
|
end
|
@@ -10,35 +10,62 @@ describe Hash do
|
|
10
10
|
@symbols = { :a => { :b => { :c => 1 } } }
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
context '#except!' do
|
14
|
+
it "should respond to except!" do
|
15
|
+
@nested_hash.should respond_to :except!
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
context '#except' do
|
20
|
+
it "should respond to except" do
|
21
|
+
@nested_hash.should respond_to :except
|
22
|
+
end
|
20
23
|
|
21
|
-
|
22
|
-
|
24
|
+
it "should remove key from the hash" do
|
25
|
+
@nested_hash.except('a').should be_empty
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
|
-
|
26
|
-
|
29
|
+
context '#symbolize_keys' do
|
30
|
+
it "should respond to symbolize_keys" do
|
31
|
+
@nested_hash.should respond_to :symbolize_keys
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
|
-
|
30
|
-
|
35
|
+
context '#symbolize_keys!' do
|
36
|
+
it "should respond to symbolize_keys!" do
|
37
|
+
@nested_hash.should respond_to :symbolize_keys!
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should convert nested keys to symbols" do
|
41
|
+
@nested_hash.symbolize_keys!.should == @symbols
|
42
|
+
end
|
31
43
|
end
|
32
44
|
|
33
|
-
|
34
|
-
|
45
|
+
context '#serialize' do
|
46
|
+
it "should respond to serialize" do
|
47
|
+
@nested_hash.should respond_to :serialize
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should serialize hash" do
|
51
|
+
@hash.serialize.should == @serialized
|
52
|
+
end
|
35
53
|
end
|
36
54
|
|
37
|
-
|
38
|
-
|
55
|
+
context '#all_keys' do
|
56
|
+
it "should respond to all_keys" do
|
57
|
+
@nested_hash.should respond_to :all_keys
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return all keys for nested hash" do
|
61
|
+
@nested_hash.all_keys.should eq ['a', 'b', 'c']
|
62
|
+
end
|
39
63
|
end
|
40
64
|
|
41
|
-
|
42
|
-
|
65
|
+
context '#has_deep_key?' do
|
66
|
+
it 'should find key inside nested hash' do
|
67
|
+
@nested_hash.has_deep_key?('c').should be_true
|
68
|
+
end
|
43
69
|
end
|
44
|
-
|
70
|
+
|
71
|
+
end # Hash
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Github do
|
4
|
+
|
5
|
+
let(:method) { 'create_repos'}
|
6
|
+
let(:alt_method) { 'repos.create'}
|
7
|
+
|
8
|
+
it { described_class.constants.should include :DEPRECATION_PREFIX }
|
9
|
+
|
10
|
+
context '.deprecate' do
|
11
|
+
before do
|
12
|
+
Github.deprecation_tracker = []
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'tracks messages' do
|
16
|
+
Github.should_receive(:warn).once()
|
17
|
+
Github.deprecate(method)
|
18
|
+
Github.deprecate(method)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'prints the message through Kernel' do
|
22
|
+
Github.should_receive(:warn).once()
|
23
|
+
Github.deprecate method
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'prints the message through Kernel' do
|
28
|
+
Github.should_receive(:warn)
|
29
|
+
Github.warn_deprecation method
|
30
|
+
end
|
31
|
+
end # Github
|
data/spec/github/gists_spec.rb
CHANGED
@@ -1,5 +1,463 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Github::Gists do
|
4
|
-
|
5
|
-
|
3
|
+
describe Github::Gists, :type => :base do
|
4
|
+
|
5
|
+
let(:gist_id) { '1' }
|
6
|
+
|
7
|
+
describe "#gists" do
|
8
|
+
context 'check aliases' do
|
9
|
+
it { github.gists.should respond_to :gists }
|
10
|
+
it { github.gists.should respond_to :list_gists }
|
11
|
+
end
|
12
|
+
|
13
|
+
context "- unauthenticated user" do
|
14
|
+
context "resource found" do
|
15
|
+
before do
|
16
|
+
stub_get("/users/#{user}/gists").
|
17
|
+
to_return(:body => fixture('gists/gists.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should get the resources" do
|
21
|
+
github.gists.gists user
|
22
|
+
a_get("/users/#{user}/gists").should have_been_made
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return array of resources" do
|
26
|
+
gists = github.gists.gists user
|
27
|
+
gists.should be_an Array
|
28
|
+
gists.should have(1).items
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be a mash type" do
|
32
|
+
gists = github.gists.gists user
|
33
|
+
gists.first.should be_a Hashie::Mash
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should get gist information" do
|
37
|
+
gists = github.gists.gists user
|
38
|
+
gists.first.user.login.should == 'octocat'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should yield to a block" do
|
42
|
+
github.gists.should_receive(:gists).with(user).and_yield('web')
|
43
|
+
github.gists.gists(user) { |param| 'web' }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "resource not found" do
|
48
|
+
before do
|
49
|
+
stub_get("/users/#{user}/gists").
|
50
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return 404 with a message 'Not Found'" do
|
54
|
+
expect {
|
55
|
+
github.gists.gists user
|
56
|
+
}.to raise_error(Github::ResourceNotFound)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end # unauthenticated user
|
60
|
+
|
61
|
+
context '- public' do
|
62
|
+
before do
|
63
|
+
github.user = nil
|
64
|
+
stub_get("/gists/public").
|
65
|
+
to_return(:body => fixture('gists/gists.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should get the resources" do
|
69
|
+
github.gists.gists
|
70
|
+
a_get("/gists/public").should have_been_made
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context '- authenticated user' do
|
75
|
+
before do
|
76
|
+
github.user = nil
|
77
|
+
github.oauth_token = OAUTH_TOKEN
|
78
|
+
stub_get("/gists").
|
79
|
+
with(:query => {:access_token => OAUTH_TOKEN}).
|
80
|
+
to_return(:body => fixture('gists/gists.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
81
|
+
end
|
82
|
+
after do
|
83
|
+
github.oauth_token = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should get the resources" do
|
87
|
+
github.gists.gists
|
88
|
+
a_get("/gists").with(:query => {:access_token => OAUTH_TOKEN}).
|
89
|
+
should have_been_made
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end # gists
|
93
|
+
|
94
|
+
describe "#starred" do
|
95
|
+
context "resource found" do
|
96
|
+
before do
|
97
|
+
stub_get("/gists/starred").
|
98
|
+
to_return(:body => fixture('gists/gists.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should get the resources" do
|
102
|
+
github.gists.starred
|
103
|
+
a_get("/gists/starred").should have_been_made
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return array of resources" do
|
107
|
+
gists = github.gists.starred
|
108
|
+
gists.should be_an Array
|
109
|
+
gists.should have(1).items
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should be a mash type" do
|
113
|
+
gists = github.gists.starred
|
114
|
+
gists.first.should be_a Hashie::Mash
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should get gist information" do
|
118
|
+
gists = github.gists.starred
|
119
|
+
gists.first.user.login.should == 'octocat'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should yield to a block" do
|
123
|
+
github.gists.should_receive(:starred).and_yield('web')
|
124
|
+
github.gists.starred() { |param| 'web' }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "resource not found" do
|
129
|
+
before do
|
130
|
+
stub_get("/gists/starred").
|
131
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return 404 with a message 'Not Found'" do
|
135
|
+
expect {
|
136
|
+
github.gists.starred
|
137
|
+
}.to raise_error(Github::ResourceNotFound)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end # starred
|
142
|
+
|
143
|
+
describe "#gist" do
|
144
|
+
let(:gist_id) { '1' }
|
145
|
+
|
146
|
+
context 'check aliases' do
|
147
|
+
it { github.gists.should respond_to :gist }
|
148
|
+
it { github.gists.should respond_to :get_gist }
|
149
|
+
end
|
150
|
+
|
151
|
+
context "resource found" do
|
152
|
+
before do
|
153
|
+
stub_get("/gists/#{gist_id}").
|
154
|
+
to_return(:body => fixture('gists/gist.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should fail to get resource without gist id" do
|
158
|
+
expect { github.gists.gist(nil)}.to raise_error(ArgumentError)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should get the resource" do
|
162
|
+
github.gists.gist gist_id
|
163
|
+
a_get("/gists/#{gist_id}").should have_been_made
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should get gist information" do
|
167
|
+
gist = github.gists.gist gist_id
|
168
|
+
gist.id.should eq gist_id
|
169
|
+
gist.user.login.should == 'octocat'
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should return mash" do
|
173
|
+
gist = github.gists.gist gist_id
|
174
|
+
gist.should be_a Hashie::Mash
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "resource not found" do
|
179
|
+
before do
|
180
|
+
stub_get("/gists/#{gist_id}").
|
181
|
+
to_return(:body => fixture('gists/gist.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should fail to retrive resource" do
|
185
|
+
expect {
|
186
|
+
github.gists.gist gist_id
|
187
|
+
}.to raise_error(Github::ResourceNotFound)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end # gist
|
191
|
+
|
192
|
+
describe "#create_gist" do
|
193
|
+
let(:inputs) {
|
194
|
+
{
|
195
|
+
"description" => "the description for this gist",
|
196
|
+
"public" => true,
|
197
|
+
"files" => {
|
198
|
+
"file1.txt" => {
|
199
|
+
"content" => "String file contents"
|
200
|
+
}
|
201
|
+
},
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
context "resouce created" do
|
206
|
+
before do
|
207
|
+
stub_post("/gists").
|
208
|
+
with(:body => JSON.generate(inputs)).
|
209
|
+
to_return(:body => fixture('gists/gist.json'),
|
210
|
+
:status => 201,
|
211
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should fail to create resource if 'content' input is missing" do
|
215
|
+
expect {
|
216
|
+
github.gists.create_gist inputs.except('files')
|
217
|
+
}.to raise_error(ArgumentError)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should fail to create resource if 'encoding' input is missing" do
|
221
|
+
expect {
|
222
|
+
github.gists.create_gist inputs.except('public')
|
223
|
+
}.to raise_error(ArgumentError)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should create resource successfully" do
|
227
|
+
github.gists.create_gist inputs
|
228
|
+
a_post("/gists").with(inputs).should have_been_made
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should return the resource" do
|
232
|
+
gist = github.gists.create_gist inputs
|
233
|
+
gist.should be_a Hashie::Mash
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should get the gist information" do
|
237
|
+
gist = github.gists.create_gist inputs
|
238
|
+
gist.user.login.should == 'octocat'
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context "failed to create resource" do
|
243
|
+
before do
|
244
|
+
stub_post("/gists").with(inputs).
|
245
|
+
to_return(:body => fixture('gists/gist.json'),
|
246
|
+
:status => 404,
|
247
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should faile to retrieve resource" do
|
251
|
+
expect {
|
252
|
+
github.gists.create_gist inputs
|
253
|
+
}.to raise_error(Github::ResourceNotFound)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end # create_gist
|
257
|
+
|
258
|
+
describe "#edit_gist" do
|
259
|
+
let(:inputs) {
|
260
|
+
{
|
261
|
+
"description" => "the description for this gist",
|
262
|
+
"files" => {
|
263
|
+
"file1.txt" => {
|
264
|
+
"content" => "updated file contents"
|
265
|
+
},
|
266
|
+
"old_name.txt" => {
|
267
|
+
"filename" => "new_name.txt",
|
268
|
+
"content" => "modified contents"
|
269
|
+
},
|
270
|
+
"new_file.txt" => {
|
271
|
+
"content" => "a new file"
|
272
|
+
},
|
273
|
+
"delete_this_file.txt" => nil
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
context "resouce edited" do
|
279
|
+
before do
|
280
|
+
stub_patch("/gists/#{gist_id}").
|
281
|
+
with(:body => JSON.generate(inputs)).
|
282
|
+
to_return(:body => fixture('gists/gist.json'),
|
283
|
+
:status => 200,
|
284
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should edit resource successfully" do
|
288
|
+
github.gists.edit_gist gist_id, inputs
|
289
|
+
a_patch("/gists/#{gist_id}").with(inputs).should have_been_made
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should return the resource" do
|
293
|
+
gist = github.gists.edit_gist gist_id, inputs
|
294
|
+
gist.should be_a Hashie::Mash
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should get the gist information" do
|
298
|
+
gist = github.gists.edit_gist gist_id, inputs
|
299
|
+
gist.user.login.should == 'octocat'
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context "failed to edit resource" do
|
304
|
+
before do
|
305
|
+
stub_patch("/gists/#{gist_id}").with(inputs).
|
306
|
+
to_return(:body => fixture('gists/gist.json'),
|
307
|
+
:status => 404,
|
308
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should fail to retrieve resource" do
|
312
|
+
expect {
|
313
|
+
github.gists.edit_gist gist_id, inputs
|
314
|
+
}.to raise_error(Github::ResourceNotFound)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end # edit_gist
|
318
|
+
|
319
|
+
context '#star' do
|
320
|
+
before do
|
321
|
+
stub_put("/gists/#{gist_id}/star").
|
322
|
+
to_return(:body => '',
|
323
|
+
:status => 204,
|
324
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should raise error if gist id not present" do
|
328
|
+
expect {
|
329
|
+
github.gists.star nil
|
330
|
+
}.to raise_error(ArgumentError)
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'successfully stars a gist' do
|
334
|
+
github.gists.star(gist_id)
|
335
|
+
a_put("/gists/#{gist_id}/star").should have_been_made
|
336
|
+
end
|
337
|
+
|
338
|
+
it "should return 204 with a message 'Not Found'" do
|
339
|
+
github.gists.star(gist_id).status.should be 204
|
340
|
+
end
|
341
|
+
end # star
|
342
|
+
|
343
|
+
context '#unstar' do
|
344
|
+
before do
|
345
|
+
stub_delete("/gists/#{gist_id}/star").
|
346
|
+
to_return(:body => '',
|
347
|
+
:status => 204,
|
348
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should raise error if gist id not present" do
|
352
|
+
expect {
|
353
|
+
github.gists.unstar nil
|
354
|
+
}.to raise_error(ArgumentError)
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'successfully stars a gist' do
|
358
|
+
github.gists.unstar(gist_id)
|
359
|
+
a_delete("/gists/#{gist_id}/star").should have_been_made
|
360
|
+
end
|
361
|
+
|
362
|
+
it "should return 204 with a message 'Not Found'" do
|
363
|
+
github.gists.unstar(gist_id).status.should be 204
|
364
|
+
end
|
365
|
+
end # unstar
|
366
|
+
|
367
|
+
context '#starred?' do
|
368
|
+
before do
|
369
|
+
stub_get("/gists/#{gist_id}/star").
|
370
|
+
to_return(:body => '',
|
371
|
+
:status => 204,
|
372
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'should raise error if gist id not present' do
|
376
|
+
expect {
|
377
|
+
github.gists.starred? nil
|
378
|
+
}.to raise_error(ArgumentError)
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'should return true if gist is already starred' do
|
382
|
+
github.gists.starred?(gist_id).should be_true
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'should return false if gist is not starred' do
|
386
|
+
stub_get("/gists/#{gist_id}/star").
|
387
|
+
to_return(:body => '',
|
388
|
+
:status => 404,
|
389
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
390
|
+
github.gists.starred?(gist_id).should be_false
|
391
|
+
end
|
392
|
+
end # starred?
|
393
|
+
|
394
|
+
context '#fork' do
|
395
|
+
before do
|
396
|
+
stub_post("/gists/#{gist_id}/fork").
|
397
|
+
to_return(:body => fixture('gists/gist.json'),
|
398
|
+
:status => 201,
|
399
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
400
|
+
end
|
401
|
+
|
402
|
+
|
403
|
+
it "should fail to fork gist without gist id" do
|
404
|
+
expect { github.gists.fork(nil) }.to raise_error(ArgumentError)
|
405
|
+
end
|
406
|
+
|
407
|
+
it "should fork resource successfully" do
|
408
|
+
github.gists.fork gist_id
|
409
|
+
a_post("/gists/#{gist_id}/fork").should have_been_made
|
410
|
+
end
|
411
|
+
|
412
|
+
it "should return the resource" do
|
413
|
+
gist = github.gists.fork gist_id
|
414
|
+
gist.should be_a Hashie::Mash
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should get the gist information" do
|
418
|
+
gist = github.gists.fork gist_id
|
419
|
+
gist.user.login.should == 'octocat'
|
420
|
+
end
|
421
|
+
|
422
|
+
it 'fails to retrieve resource' do
|
423
|
+
stub_post("/gists/#{gist_id}/fork").
|
424
|
+
to_return(:body => '',
|
425
|
+
:status => 404,
|
426
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
427
|
+
expect {
|
428
|
+
github.gists.fork gist_id
|
429
|
+
}.to raise_error(Github::ResourceNotFound)
|
430
|
+
end
|
431
|
+
end # fork
|
432
|
+
|
433
|
+
context "#delete_gist" do
|
434
|
+
before do
|
435
|
+
stub_delete("/gists/#{gist_id}").
|
436
|
+
to_return(:body => fixture('gists/gist.json'),
|
437
|
+
:status => 204,
|
438
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
439
|
+
end
|
440
|
+
|
441
|
+
it 'should raise error if gist id not present' do
|
442
|
+
expect {
|
443
|
+
github.gists.delete_gist nil
|
444
|
+
}.to raise_error(ArgumentError)
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should remove resource successfully" do
|
448
|
+
github.gists.delete_gist gist_id
|
449
|
+
a_delete("/gists/#{gist_id}").should have_been_made
|
450
|
+
end
|
451
|
+
|
452
|
+
it "fails to delete resource" do
|
453
|
+
stub_delete("/gists/#{gist_id}").
|
454
|
+
to_return(:body => '',
|
455
|
+
:status => 404,
|
456
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
457
|
+
expect {
|
458
|
+
github.gists.delete_gist gist_id
|
459
|
+
}.to raise_error(Github::ResourceNotFound)
|
460
|
+
end
|
461
|
+
end # delete_gist
|
462
|
+
|
463
|
+
end # Github::Gists
|