github_api 0.7.0 → 0.7.1
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 +11 -5
- data/Rakefile +2 -0
- data/features/repos/statuses.feature +12 -12
- data/lib/github_api/api.rb +1 -1
- data/lib/github_api/authorizations.rb +3 -3
- data/lib/github_api/events.rb +7 -7
- data/lib/github_api/gists.rb +7 -7
- data/lib/github_api/gists/comments.rb +4 -4
- data/lib/github_api/git_data/blobs.rb +2 -3
- data/lib/github_api/git_data/commits.rb +2 -3
- data/lib/github_api/git_data/references.rb +10 -17
- data/lib/github_api/git_data/tags.rb +2 -3
- data/lib/github_api/git_data/trees.rb +2 -3
- data/lib/github_api/issues.rb +4 -6
- data/lib/github_api/issues/assignees.rb +5 -4
- data/lib/github_api/issues/comments.rb +5 -10
- data/lib/github_api/issues/events.rb +2 -3
- data/lib/github_api/issues/labels.rb +11 -20
- data/lib/github_api/issues/milestones.rb +5 -8
- data/lib/github_api/orgs.rb +2 -2
- data/lib/github_api/orgs/members.rb +7 -7
- data/lib/github_api/orgs/teams.rb +13 -13
- data/lib/github_api/page_iterator.rb +3 -1
- data/lib/github_api/pull_requests.rb +8 -16
- data/lib/github_api/pull_requests/comments.rb +5 -10
- data/lib/github_api/repos.rb +27 -8
- data/lib/github_api/repos/collaborators.rb +4 -7
- data/lib/github_api/repos/commits.rb +9 -16
- data/lib/github_api/repos/downloads.rb +5 -7
- data/lib/github_api/repos/forks.rb +3 -3
- data/lib/github_api/repos/hooks.rb +10 -13
- data/lib/github_api/repos/keys.rb +5 -8
- data/lib/github_api/repos/pub_sub_hubbub.rb +4 -4
- data/lib/github_api/repos/starring.rb +4 -4
- data/lib/github_api/repos/statuses.rb +2 -2
- data/lib/github_api/repos/watching.rb +4 -4
- data/lib/github_api/users/followers.rb +3 -3
- data/lib/github_api/users/keys.rb +3 -3
- data/lib/github_api/validations/presence.rb +16 -17
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/repos/repos_sorted_by_pushed.json +56 -0
- data/spec/github/git_data_spec.rb +5 -7
- data/spec/github/issues_spec.rb +12 -12
- data/spec/github/orgs_spec.rb +2 -4
- data/spec/github/pull_requests_spec.rb +1 -1
- data/spec/github/repos/branch_spec.rb +48 -0
- data/spec/github/repos/branches_spec.rb +62 -0
- data/spec/github/repos/contributors_spec.rb +62 -0
- data/spec/github/repos/create_spec.rb +77 -0
- data/spec/github/repos/delete_spec.rb +43 -0
- data/spec/github/repos/downloads_spec.rb +51 -45
- data/spec/github/repos/edit_spec.rb +66 -0
- data/spec/github/repos/forks/create_spec.rb +49 -0
- data/spec/github/repos/forks/list_spec.rb +65 -0
- data/spec/github/repos/get_spec.rb +57 -0
- data/spec/github/repos/languages_spec.rb +61 -0
- data/spec/github/repos/list_spec.rb +99 -0
- data/spec/github/repos/tags_spec.rb +59 -0
- data/spec/github/repos/teams_spec.rb +59 -0
- data/spec/github/repos_spec.rb +13 -578
- data/spec/github/validations/presence_spec.rb +23 -4
- metadata +48 -42
- data/spec/github/repos/forks_spec.rb +0 -106
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos::Forks, '#list' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}/forks" }
|
9
|
+
|
10
|
+
before {
|
11
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
12
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for(subject) }
|
16
|
+
|
17
|
+
|
18
|
+
context "resource found" do
|
19
|
+
let(:body) { fixture('repos/forks.json') }
|
20
|
+
let(:status) { 200 }
|
21
|
+
|
22
|
+
it { should respond_to :all }
|
23
|
+
|
24
|
+
it "should fail to get resource without username" do
|
25
|
+
expect { subject.list }.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should get the resources" do
|
29
|
+
subject.list user, repo
|
30
|
+
a_get(request_path).should have_been_made
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return array of resources" do
|
34
|
+
forks = subject.list user, repo
|
35
|
+
forks.should be_an Array
|
36
|
+
forks.should have(1).items
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be a mash type" do
|
40
|
+
forks = subject.list user, repo
|
41
|
+
forks.first.should be_a Hashie::Mash
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should get fork information" do
|
45
|
+
forks = subject.list user, repo
|
46
|
+
forks.first.name.should == 'Hello-World'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should yield to a block" do
|
50
|
+
subject.should_receive(:list).with(user, repo).and_yield('web')
|
51
|
+
subject.list(user, repo) { |param| 'web' }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "resource not found" do
|
56
|
+
let(:body) { "" }
|
57
|
+
let(:status) { [404, "Not Found"] }
|
58
|
+
|
59
|
+
it "should return 404 with a message 'Not Found'" do
|
60
|
+
expect {
|
61
|
+
subject.list user, repo
|
62
|
+
}.to raise_error(Github::Error::NotFound)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end # list
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos, '#get' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}" }
|
9
|
+
|
10
|
+
before {
|
11
|
+
stub_get(request_path).
|
12
|
+
to_return(:body => body, :status => status, :headers => {:content_type => "application/json; charset=utf-8"})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for subject }
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture('repos/repo.json') }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it { should respond_to(:find) }
|
22
|
+
|
23
|
+
it "should raise error when no user/repo parameters" do
|
24
|
+
expect { subject.get nil, repo }.to raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise error when no repository" do
|
28
|
+
expect { subject.get user, nil }.to raise_error(ArgumentError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should find resources" do
|
32
|
+
subject.get user, repo
|
33
|
+
a_get(request_path).should have_been_made
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return repository mash" do
|
37
|
+
repository = subject.get user, repo
|
38
|
+
repository.should be_a Hashie::Mash
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should get repository information" do
|
42
|
+
repository = subject.get user, repo
|
43
|
+
repository.name.should == 'Hello-World'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "resource not found" do
|
48
|
+
let(:body) { '' }
|
49
|
+
let(:status) { 404 }
|
50
|
+
|
51
|
+
it "should fail to get resource" do
|
52
|
+
expect {
|
53
|
+
subject.get user, repo
|
54
|
+
}.to raise_error(Github::Error::NotFound)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end # get
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos, '#languages' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}/languages" }
|
9
|
+
|
10
|
+
before {
|
11
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
12
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for subject }
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture('repos/languages.json') }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it "should raise error when no user/repo parameters" do
|
22
|
+
expect { subject.languages nil, repo }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise error when no repository" do
|
26
|
+
expect { subject.languages user, nil }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should find resources" do
|
30
|
+
subject.languages user, repo
|
31
|
+
a_get(request_path).should have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return hash of languages" do
|
35
|
+
languages = subject.languages user, repo
|
36
|
+
languages.should be_an Hash
|
37
|
+
languages.should have(2).keys
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should get language information" do
|
41
|
+
languages = subject.languages user, repo
|
42
|
+
languages.keys.first.should == 'Ruby'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should yield to a block" do
|
46
|
+
subject.should_receive(:languages).with(user, repo).and_yield('web')
|
47
|
+
subject.languages(user, repo) { |param| 'web'}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "resource not found" do
|
52
|
+
let(:body) { '' }
|
53
|
+
let(:status) { 404 }
|
54
|
+
|
55
|
+
it "should fail to get resource" do
|
56
|
+
expect {
|
57
|
+
subject.languages user, repo
|
58
|
+
}.to raise_error(Github::Error::NotFound)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end # languages
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos, '#list' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/user/repos?access_token=#{OAUTH_TOKEN}" }
|
9
|
+
let(:body) { fixture('repos/repos.json') }
|
10
|
+
let(:status) { 200 }
|
11
|
+
|
12
|
+
after { reset_authentication_for subject }
|
13
|
+
|
14
|
+
it { should respond_to(:find) }
|
15
|
+
|
16
|
+
context "resource found for authenticated user" do
|
17
|
+
before {
|
18
|
+
subject.oauth_token = OAUTH_TOKEN
|
19
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
20
|
+
:headers => {:content_type => "application/json; charset=utf-8"} )
|
21
|
+
stub_get(request_path + "&sort=pushed").
|
22
|
+
to_return(:body => fixture('repos/repos_sorted_by_pushed.json'), :status => 200,:headers => {:content_type => "application/json; charset=utf-8"} )
|
23
|
+
}
|
24
|
+
|
25
|
+
it "fails if user is unauthenticated" do
|
26
|
+
subject.oauth_token = nil
|
27
|
+
stub_get("/user/repos").to_return(:body => '', :status => 401,
|
28
|
+
:headers => {:content_type => "application/json; charset=utf-8"} )
|
29
|
+
expect { subject.list }.to raise_error(Github::Error::Unauthorized)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should get the resources" do
|
33
|
+
subject.list
|
34
|
+
a_get(request_path).should have_been_made
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return array of resources" do
|
38
|
+
repositories = subject.list
|
39
|
+
repositories.should be_an Array
|
40
|
+
repositories.should have(1).items
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return array of resources sorted by pushed_at time" do
|
44
|
+
repositories = subject.list(:sort => 'pushed')
|
45
|
+
repositories.first.name.should == "Hello-World-2"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should get resource information" do
|
49
|
+
repositories = subject.list
|
50
|
+
repositories.first.name.should == 'Hello-World'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should yield repositories to a block" do
|
54
|
+
subject.should_receive(:list).and_yield('octocat')
|
55
|
+
subject.list { |repo| 'octocat' }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "resource found for organization" do
|
60
|
+
let(:org) { '37signals' }
|
61
|
+
let(:request_path) { "/orgs/#{org}/repos" }
|
62
|
+
|
63
|
+
before {
|
64
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
65
|
+
:headers => {:content_type => "application/json; charset=utf-8"} )
|
66
|
+
}
|
67
|
+
|
68
|
+
it "should get the resources" do
|
69
|
+
subject.list :org => org
|
70
|
+
a_get(request_path).should have_been_made
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "resource found for organization" do
|
75
|
+
let(:request_path) { "/users/#{user}/repos" }
|
76
|
+
|
77
|
+
before {
|
78
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
79
|
+
:headers => {:content_type => "application/json; charset=utf-8"} )
|
80
|
+
}
|
81
|
+
|
82
|
+
it "should get the resources" do
|
83
|
+
subject.list :user => user
|
84
|
+
a_get(request_path).should have_been_made
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "rosource not found for authenticated user" do
|
89
|
+
before {
|
90
|
+
subject.oauth_token = OAUTH_TOKEN
|
91
|
+
stub_get(request_path).to_return(:body => '', :status => 404,
|
92
|
+
:headers => {:content_type => "application/json; charset=utf-8"} )
|
93
|
+
}
|
94
|
+
|
95
|
+
it "fail to find resources" do
|
96
|
+
expect { subject.list }.to raise_error(Github::Error::NotFound)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end # list
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos, '#tags' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}/tags" }
|
9
|
+
|
10
|
+
before {
|
11
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
12
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for subject }
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture('repos/tags.json') }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it "should raise error when no user/repo parameters" do
|
22
|
+
expect { subject.tags nil, repo }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise error when no repository" do
|
26
|
+
expect { subject.tags user, nil }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should find resources" do
|
30
|
+
subject.tags user, repo
|
31
|
+
a_get(request_path).should have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return array of resources" do
|
35
|
+
tags = subject.tags user, repo
|
36
|
+
tags.should be_an Array
|
37
|
+
tags.should have(1).items
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should get tag information" do
|
41
|
+
tags = subject.tags user, repo
|
42
|
+
tags.first.name.should == 'v0.1'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should yield to a block" do
|
46
|
+
subject.should_receive(:tags).with(user, repo).and_yield('web')
|
47
|
+
subject.tags(user, repo) { |param| 'web'}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "resource not found" do
|
52
|
+
let(:body) { '' }
|
53
|
+
let(:status) { 404 }
|
54
|
+
|
55
|
+
it "should fail to get resource" do
|
56
|
+
expect { subject.tags user, repo }.to raise_error(Github::Error::NotFound)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end # tags
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos, '#teams' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}/teams" }
|
9
|
+
|
10
|
+
after { reset_authentication_for subject }
|
11
|
+
|
12
|
+
before {
|
13
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
14
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
15
|
+
}
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture('repos/teams.json') }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it "should raise error when no user/repo parameters" do
|
22
|
+
expect { subject.teams nil, repo }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise error when no repository" do
|
26
|
+
expect { subject.teams user, nil }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should find resources" do
|
30
|
+
subject.teams user, repo
|
31
|
+
a_get(request_path).should have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return array of resources" do
|
35
|
+
teams = subject.teams user, repo
|
36
|
+
teams.should be_an Array
|
37
|
+
teams.should have(1).items
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should get branch information" do
|
41
|
+
teams = subject.teams user, repo
|
42
|
+
teams.first.name.should == 'Owners'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should yield to a block" do
|
46
|
+
subject.should_receive(:teams).with(user, repo).and_yield('web')
|
47
|
+
subject.teams(user, repo) { |param| 'web'}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "resource not found" do
|
52
|
+
let(:body) { '' }
|
53
|
+
let(:status) { 404 }
|
54
|
+
|
55
|
+
it "should fail to get resource" do
|
56
|
+
expect { subject.teams user, repo }.to raise_error(Github::Error::NotFound)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end # teams
|
data/spec/github/repos_spec.rb
CHANGED
@@ -2,595 +2,30 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Github::Repos do
|
6
|
-
let(:github) { Github.new }
|
7
|
-
let(:user) { 'peter-murach' }
|
8
|
-
let(:repo) { 'github' }
|
5
|
+
describe Github::Repos, 'integration' do
|
9
6
|
|
10
|
-
after { reset_authentication_for
|
7
|
+
after { reset_authentication_for subject }
|
11
8
|
|
12
|
-
|
13
|
-
it { subject.collaborators.should be_a Github::Repos::Collaborators }
|
14
|
-
it { subject.commits.should be_a Github::Repos::Commits }
|
15
|
-
it { subject.downloads.should be_a Github::Repos::Downloads }
|
16
|
-
it { subject.forks.should be_a Github::Repos::Forks }
|
17
|
-
it { subject.hooks.should be_a Github::Repos::Hooks }
|
18
|
-
it { subject.keys.should be_a Github::Repos::Keys }
|
19
|
-
it { subject.watching.should be_a Github::Repos::Watching }
|
20
|
-
it { subject.pubsubhubbub.should be_a Github::Repos::PubSubHubbub }
|
21
|
-
end
|
9
|
+
its(:collaborators) { should be_a Github::Repos::Collaborators }
|
22
10
|
|
23
|
-
|
24
|
-
context "resource found" do
|
25
|
-
before do
|
26
|
-
stub_get("/repos/#{user}/#{repo}/branches").
|
27
|
-
to_return(:body => fixture('repos/branches.json'),
|
28
|
-
:status => 200,
|
29
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
30
|
-
end
|
11
|
+
its(:commits) { should be_a Github::Repos::Commits }
|
31
12
|
|
32
|
-
|
33
|
-
expect {
|
34
|
-
github.repos.branches nil, repo
|
35
|
-
}.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
|
36
|
-
end
|
13
|
+
its(:downloads) { should be_a Github::Repos::Downloads }
|
37
14
|
|
38
|
-
|
39
|
-
expect {
|
40
|
-
github.repos.branches user, nil
|
41
|
-
}.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
|
42
|
-
end
|
15
|
+
its(:forks) { should be_a Github::Repos::Forks }
|
43
16
|
|
44
|
-
|
45
|
-
github.repos.branches user, repo
|
46
|
-
a_get("/repos/#{user}/#{repo}/branches").should have_been_made
|
47
|
-
end
|
17
|
+
its(:keys) { should be_a Github::Repos::Keys }
|
48
18
|
|
49
|
-
|
50
|
-
branches = github.repos.branches user, repo
|
51
|
-
branches.should be_an Array
|
52
|
-
branches.should have(1).items
|
53
|
-
end
|
19
|
+
its(:hooks) { should be_a Github::Repos::Hooks }
|
54
20
|
|
55
|
-
|
56
|
-
branches = github.repos.branches user, repo
|
57
|
-
branches.first.name.should == 'master'
|
58
|
-
end
|
21
|
+
its(:merging) { should be_a Github::Repos::Merging }
|
59
22
|
|
60
|
-
|
61
|
-
block = lambda { |el| repo }
|
62
|
-
github.repos.should_receive(:branches).with(user, repo).and_yield repo
|
63
|
-
github.repos.branches(user, repo, &block)
|
64
|
-
end
|
65
|
-
end
|
23
|
+
its(:starring) { should be_a Github::Repos::Starring }
|
66
24
|
|
67
|
-
|
68
|
-
before do
|
69
|
-
stub_get("/repos/#{user}/#{repo}/branches").
|
70
|
-
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
25
|
+
its(:statuses) { should be_a Github::Repos::Statuses }
|
71
26
|
|
72
|
-
|
27
|
+
its(:watching) { should be_a Github::Repos::Watching }
|
73
28
|
|
74
|
-
|
75
|
-
expect {
|
76
|
-
github.repos.branches user, repo
|
77
|
-
}.to raise_error(Github::Error::NotFound)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end # branches
|
81
|
-
|
82
|
-
describe "#branch" do
|
83
|
-
let(:branch) { 'master' }
|
84
|
-
|
85
|
-
context "resource found" do
|
86
|
-
before do
|
87
|
-
stub_get("/repos/#{user}/#{repo}/branches/#{branch}").
|
88
|
-
to_return(:body => fixture('repos/branch.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should find resources" do
|
92
|
-
github.repos.branch user, repo, branch
|
93
|
-
a_get("/repos/#{user}/#{repo}/branches/#{branch}").should have_been_made
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should return repository mash" do
|
97
|
-
repo_branch = github.repos.branch user, repo, branch
|
98
|
-
repo_branch.should be_a Hashie::Mash
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should get repository branch information" do
|
102
|
-
repo_branch = github.repos.branch user, repo, branch
|
103
|
-
repo_branch.name.should == 'master'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "resource not found" do
|
108
|
-
before do
|
109
|
-
stub_get("/repos/#{user}/#{repo}/branches/#{branch}").
|
110
|
-
to_return(:body => '', :status => 404,
|
111
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should fail to get resource" do
|
115
|
-
expect {
|
116
|
-
github.repos.branch user, repo, branch
|
117
|
-
}.to raise_error(Github::Error::NotFound)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end # branch
|
121
|
-
|
122
|
-
describe "contributors" do
|
123
|
-
context "resource found" do
|
124
|
-
before do
|
125
|
-
stub_get("/repos/#{user}/#{repo}/contributors").
|
126
|
-
to_return(:body => fixture('repos/contributors.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should raise error when no user/repo parameters" do
|
130
|
-
expect {
|
131
|
-
github.repos.contributors nil, repo
|
132
|
-
}.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should raise error when no repository" do
|
136
|
-
expect {
|
137
|
-
github.repos.contributors user, nil
|
138
|
-
}.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should find resources" do
|
142
|
-
github.repos.contributors user, repo
|
143
|
-
a_get("/repos/#{user}/#{repo}/contributors").should have_been_made
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should return array of resources" do
|
147
|
-
contributors = github.repos.contributors user, repo
|
148
|
-
contributors.should be_an Array
|
149
|
-
contributors.should have(1).items
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should get branch information" do
|
153
|
-
contributors = github.repos.contributors user, repo
|
154
|
-
contributors.first.login.should == 'octocat'
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should yield to a block" do
|
158
|
-
github.repos.should_receive(:contributors).with(user, repo).and_yield('web')
|
159
|
-
github.repos.contributors(user, repo) { |param| 'web'}
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context "resource not found" do
|
164
|
-
before do
|
165
|
-
stub_get("/repos/#{user}/#{repo}/contributors").
|
166
|
-
to_return(:body => '', :status => 404,
|
167
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should fail to get resource" do
|
171
|
-
expect {
|
172
|
-
github.repos.contributors user, repo
|
173
|
-
}.to raise_error(Github::Error::NotFound)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end # contributors
|
177
|
-
|
178
|
-
describe "#create" do
|
179
|
-
let(:inputs) { {:name => 'web', :description => "This is your first repo", :homepage => "https://github.com", :public => true, :has_issues => true, :has_wiki => true}}
|
180
|
-
|
181
|
-
context "resource created successfully for the authenticated user" do
|
182
|
-
before do
|
183
|
-
github.oauth_token = OAUTH_TOKEN
|
184
|
-
stub_post("/user/repos?access_token=#{OAUTH_TOKEN}").with(inputs).
|
185
|
-
to_return(:body => fixture('repos/repo.json'), :status => 201,
|
186
|
-
:headers => {:content_type => "application/json; charset=utf-8"} )
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should faile to create resource if 'name' inputs is missing" do
|
190
|
-
expect {
|
191
|
-
github.repos.create inputs.except(:name)
|
192
|
-
}.to raise_error(Github::Error::RequiredParams)
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should create resource" do
|
196
|
-
github.repos.create inputs
|
197
|
-
a_post("/user/repos?access_token=#{OAUTH_TOKEN}").with(inputs).should have_been_made
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should return the resource" do
|
201
|
-
repository = github.repos.create inputs
|
202
|
-
repository.name.should == 'Hello-World'
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should return mash type" do
|
206
|
-
repository = github.repos.create inputs
|
207
|
-
repository.should be_a Hashie::Mash
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
context "resource created for the authenticated user belonging to organization" do
|
212
|
-
let(:org) { '37signals' }
|
213
|
-
before do
|
214
|
-
github.oauth_token = OAUTH_TOKEN
|
215
|
-
stub_post("/orgs/#{org}/repos?access_token=#{OAUTH_TOKEN}").with(inputs).
|
216
|
-
to_return(:body => fixture('repos/repo.json'), :status => 201,:headers => {:content_type => "application/json; charset=utf-8"} )
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should get the resource" do
|
220
|
-
github.repos.create inputs.merge(:org => org)
|
221
|
-
a_post("/orgs/#{org}/repos?access_token=#{OAUTH_TOKEN}").with(inputs).should have_been_made
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context "failed to create" do
|
226
|
-
before do
|
227
|
-
github.oauth_token = OAUTH_TOKEN
|
228
|
-
stub_post("/user/repos?access_token=#{OAUTH_TOKEN}").with(inputs).
|
229
|
-
to_return(:body => '', :status => 404,:headers => {:content_type => "application/json; charset=utf-8"} )
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should faile to retrieve resource" do
|
233
|
-
expect {
|
234
|
-
github.repos.create inputs
|
235
|
-
}.to raise_error(Github::Error::NotFound)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe "#edit" do
|
241
|
-
let(:inputs) do
|
242
|
-
{ :name => 'web',
|
243
|
-
:description => "This is your first repo",
|
244
|
-
:homepage => "https://github.com",
|
245
|
-
:private => false,
|
246
|
-
:has_issues => true,
|
247
|
-
:has_wiki => true }
|
248
|
-
end
|
249
|
-
|
250
|
-
context "resource edited successfully" do
|
251
|
-
before do
|
252
|
-
stub_patch("/repos/#{user}/#{repo}").with(inputs).
|
253
|
-
to_return(:body => fixture("repos/repo.json"), :status => 200,
|
254
|
-
:headers => { :content_type => "application/json; charset=utf-8"})
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should fail to edit without 'user/repo' parameters" do
|
258
|
-
expect { github.repos.edit user, nil }.to raise_error(ArgumentError)
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should fail to edit resource without 'name' parameter" do
|
262
|
-
expect{
|
263
|
-
github.repos.edit user, repo, inputs.except(:name)
|
264
|
-
}.to raise_error(Github::Error::RequiredParams)
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should edit the resource" do
|
268
|
-
github.repos.edit user, repo, inputs
|
269
|
-
a_patch("/repos/#{user}/#{repo}").with(inputs).should have_been_made
|
270
|
-
end
|
271
|
-
|
272
|
-
it "should return resource" do
|
273
|
-
repository = github.repos.edit user, repo, inputs
|
274
|
-
repository.should be_a Hashie::Mash
|
275
|
-
end
|
276
|
-
|
277
|
-
it "should be able to retrieve information" do
|
278
|
-
repository = github.repos.edit user, repo, inputs
|
279
|
-
repository.name.should == 'Hello-World'
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
context "failed to edit resource" do
|
284
|
-
before do
|
285
|
-
stub_patch("/repos/#{user}/#{repo}").with(inputs).
|
286
|
-
to_return(:body => fixture("repos/repo.json"), :status => 404,
|
287
|
-
:headers => { :content_type => "application/json; charset=utf-8"})
|
288
|
-
end
|
289
|
-
|
290
|
-
it "should fail to find resource" do
|
291
|
-
expect {
|
292
|
-
github.repos.edit user, repo, inputs
|
293
|
-
}.to raise_error(Github::Error::NotFound)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end # edit
|
297
|
-
|
298
|
-
describe "#get" do
|
299
|
-
context "resource found" do
|
300
|
-
before do
|
301
|
-
stub_get("/repos/#{user}/#{repo}").
|
302
|
-
to_return(:body => fixture('repos/repo.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
303
|
-
end
|
304
|
-
|
305
|
-
it "should raise error when no user/repo parameters" do
|
306
|
-
# github.user, github.repo = nil, nil
|
307
|
-
expect {
|
308
|
-
github.repos.get nil, repo
|
309
|
-
}.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
|
310
|
-
end
|
311
|
-
|
312
|
-
it "should raise error when no repository" do
|
313
|
-
# github.user, github.repo = nil, nil
|
314
|
-
expect {
|
315
|
-
github.repos.get user, nil
|
316
|
-
}.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
|
317
|
-
end
|
318
|
-
|
319
|
-
it "should find resources" do
|
320
|
-
github.repos.get user, repo
|
321
|
-
a_get("/repos/#{user}/#{repo}").should have_been_made
|
322
|
-
end
|
323
|
-
|
324
|
-
it "should return repository mash" do
|
325
|
-
repository = github.repos.get user, repo
|
326
|
-
repository.should be_a Hashie::Mash
|
327
|
-
end
|
328
|
-
|
329
|
-
it "should get repository information" do
|
330
|
-
repository = github.repos.get user, repo
|
331
|
-
repository.name.should == 'Hello-World'
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
context "resource not found" do
|
336
|
-
before do
|
337
|
-
stub_get("/repos/#{user}/#{repo}").
|
338
|
-
to_return(:body => '', :status => 404,
|
339
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
340
|
-
end
|
341
|
-
|
342
|
-
it "should fail to get resource" do
|
343
|
-
expect {
|
344
|
-
github.repos.get user, repo
|
345
|
-
}.to raise_error(Github::Error::NotFound)
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end # get
|
349
|
-
|
350
|
-
describe "#languages" do
|
351
|
-
context "resource found" do
|
352
|
-
before do
|
353
|
-
stub_get("/repos/#{user}/#{repo}/languages").
|
354
|
-
to_return(:body => fixture('repos/languages.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
355
|
-
end
|
356
|
-
|
357
|
-
it "should raise error when no user/repo parameters" do
|
358
|
-
expect {
|
359
|
-
github.repos.languages nil, repo
|
360
|
-
}.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
|
361
|
-
end
|
362
|
-
|
363
|
-
it "should raise error when no repository" do
|
364
|
-
expect {
|
365
|
-
github.repos.languages user, nil
|
366
|
-
}.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
|
367
|
-
end
|
368
|
-
|
369
|
-
it "should find resources" do
|
370
|
-
github.repos.languages user, repo
|
371
|
-
a_get("/repos/#{user}/#{repo}/languages").should have_been_made
|
372
|
-
end
|
373
|
-
|
374
|
-
it "should return hash of languages" do
|
375
|
-
languages = github.repos.languages user, repo
|
376
|
-
languages.should be_an Hash
|
377
|
-
languages.should have(2).keys
|
378
|
-
end
|
379
|
-
|
380
|
-
it "should get language information" do
|
381
|
-
languages = github.repos.languages user, repo
|
382
|
-
languages.keys.first.should == 'Ruby'
|
383
|
-
end
|
384
|
-
|
385
|
-
it "should yield to a block" do
|
386
|
-
github.repos.should_receive(:languages).with(user, repo).and_yield('web')
|
387
|
-
github.repos.languages(user, repo) { |param| 'web'}
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
context "resource not found" do
|
392
|
-
before do
|
393
|
-
stub_get("/repos/#{user}/#{repo}/languages").
|
394
|
-
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
395
|
-
end
|
396
|
-
|
397
|
-
it "should fail to get resource" do
|
398
|
-
expect {
|
399
|
-
github.repos.languages user, repo
|
400
|
-
}.to raise_error(Github::Error::NotFound)
|
401
|
-
end
|
402
|
-
end
|
403
|
-
end # languages
|
404
|
-
|
405
|
-
describe "#list" do
|
406
|
-
context "resource found for authenticated user" do
|
407
|
-
before do
|
408
|
-
github.oauth_token = OAUTH_TOKEN
|
409
|
-
stub_get("/user/repos?access_token=#{OAUTH_TOKEN}").
|
410
|
-
to_return(:body => fixture('repos/repos.json'), :status => 200,:headers => {:content_type => "application/json; charset=utf-8"} )
|
411
|
-
end
|
412
|
-
|
413
|
-
it "fails if user is unauthenticated" do
|
414
|
-
github.oauth_token = nil
|
415
|
-
stub_get("/user/repos").
|
416
|
-
to_return(:body => '', :status => 401,:headers => {:content_type => "application/json; charset=utf-8"} )
|
417
|
-
expect { github.repos.list }.to raise_error(Github::Error::Unauthorized)
|
418
|
-
end
|
419
|
-
|
420
|
-
it "should get the resources" do
|
421
|
-
github.repos.list
|
422
|
-
a_get("/user/repos?access_token=#{OAUTH_TOKEN}").should have_been_made
|
423
|
-
end
|
424
|
-
|
425
|
-
it "should return array of resources" do
|
426
|
-
repositories = github.repos.list
|
427
|
-
repositories.should be_an Array
|
428
|
-
repositories.should have(1).items
|
429
|
-
end
|
430
|
-
|
431
|
-
it "should get resource information" do
|
432
|
-
repositories = github.repos.list
|
433
|
-
repositories.first.name.should == 'Hello-World'
|
434
|
-
end
|
435
|
-
|
436
|
-
it "should yield repositories to a block" do
|
437
|
-
github.repos.should_receive(:list).and_yield('octocat')
|
438
|
-
github.repos.list { |repo| 'octocat' }
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
context "resource found for organization" do
|
443
|
-
let(:org) { '37signals' }
|
444
|
-
|
445
|
-
before do
|
446
|
-
stub_get("/orgs/#{org}/repos").
|
447
|
-
to_return(:body => fixture('repos/repos.json'), :status => 200,
|
448
|
-
:headers => {:content_type => "application/json; charset=utf-8"} )
|
449
|
-
end
|
450
|
-
|
451
|
-
it "should get the resources" do
|
452
|
-
github.repos.list :org => org
|
453
|
-
a_get("/orgs/#{org}/repos").should have_been_made
|
454
|
-
end
|
455
|
-
end
|
456
|
-
|
457
|
-
context "resource found for organization" do
|
458
|
-
before do
|
459
|
-
stub_get("/users/#{user}/repos").
|
460
|
-
to_return(:body => fixture('repos/repos.json'), :status => 200,
|
461
|
-
:headers => {:content_type => "application/json; charset=utf-8"} )
|
462
|
-
end
|
463
|
-
|
464
|
-
it "should get the resources" do
|
465
|
-
github.repos.list :user => user
|
466
|
-
a_get("/users/#{user}/repos").should have_been_made
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
context "rosource not found for authenticated user" do
|
471
|
-
before do
|
472
|
-
github.oauth_token = OAUTH_TOKEN
|
473
|
-
stub_get("/user/repos?access_token=#{OAUTH_TOKEN}").
|
474
|
-
to_return(:body => '', :status => 404,
|
475
|
-
:headers => {:content_type => "application/json; charset=utf-8"} )
|
476
|
-
end
|
477
|
-
|
478
|
-
it "fail to find resources" do
|
479
|
-
expect { github.repos.list }.to raise_error(Github::Error::NotFound)
|
480
|
-
end
|
481
|
-
end
|
482
|
-
end # list
|
483
|
-
|
484
|
-
describe "tags" do
|
485
|
-
context "resource found" do
|
486
|
-
before do
|
487
|
-
stub_get("/repos/#{user}/#{repo}/tags").
|
488
|
-
to_return(:body => fixture('repos/tags.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
489
|
-
end
|
490
|
-
|
491
|
-
it "should raise error when no user/repo parameters" do
|
492
|
-
expect {
|
493
|
-
github.repos.tags nil, repo
|
494
|
-
}.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
|
495
|
-
end
|
496
|
-
|
497
|
-
it "should raise error when no repository" do
|
498
|
-
expect {
|
499
|
-
github.repos.tags user, nil
|
500
|
-
}.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
|
501
|
-
end
|
502
|
-
|
503
|
-
it "should find resources" do
|
504
|
-
github.repos.tags user, repo
|
505
|
-
a_get("/repos/#{user}/#{repo}/tags").should have_been_made
|
506
|
-
end
|
507
|
-
|
508
|
-
it "should return array of resources" do
|
509
|
-
tags = github.repos.tags user, repo
|
510
|
-
tags.should be_an Array
|
511
|
-
tags.should have(1).items
|
512
|
-
end
|
513
|
-
|
514
|
-
it "should get tag information" do
|
515
|
-
tags = github.repos.tags user, repo
|
516
|
-
tags.first.name.should == 'v0.1'
|
517
|
-
end
|
518
|
-
|
519
|
-
it "should yield to a block" do
|
520
|
-
github.repos.should_receive(:tags).with(user, repo).and_yield('web')
|
521
|
-
github.repos.tags(user, repo) { |param| 'web'}
|
522
|
-
end
|
523
|
-
end
|
524
|
-
|
525
|
-
context "resource not found" do
|
526
|
-
before do
|
527
|
-
stub_get("/repos/#{user}/#{repo}/tags").
|
528
|
-
to_return(:body => '', :status => 404,
|
529
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
530
|
-
end
|
531
|
-
|
532
|
-
it "should fail to get resource" do
|
533
|
-
expect {
|
534
|
-
github.repos.tags user, repo
|
535
|
-
}.to raise_error(Github::Error::NotFound)
|
536
|
-
end
|
537
|
-
end
|
538
|
-
end # tags
|
539
|
-
|
540
|
-
describe "#teams" do
|
541
|
-
context "resource found" do
|
542
|
-
before do
|
543
|
-
stub_get("/repos/#{user}/#{repo}/teams").
|
544
|
-
to_return(:body => fixture('repos/teams.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
545
|
-
end
|
546
|
-
|
547
|
-
it "should raise error when no user/repo parameters" do
|
548
|
-
expect {
|
549
|
-
github.repos.teams nil, repo
|
550
|
-
}.to raise_error(ArgumentError, /\[user\] parameter cannot be nil/)
|
551
|
-
end
|
552
|
-
|
553
|
-
it "should raise error when no repository" do
|
554
|
-
expect {
|
555
|
-
github.repos.teams user, nil
|
556
|
-
}.to raise_error(ArgumentError, /\[repo\] parameter cannot be nil/)
|
557
|
-
end
|
558
|
-
|
559
|
-
it "should find resources" do
|
560
|
-
github.repos.teams user, repo
|
561
|
-
a_get("/repos/#{user}/#{repo}/teams").should have_been_made
|
562
|
-
end
|
563
|
-
|
564
|
-
it "should return array of resources" do
|
565
|
-
teams = github.repos.teams user, repo
|
566
|
-
teams.should be_an Array
|
567
|
-
teams.should have(1).items
|
568
|
-
end
|
569
|
-
|
570
|
-
it "should get branch information" do
|
571
|
-
teams = github.repos.teams user, repo
|
572
|
-
teams.first.name.should == 'Owners'
|
573
|
-
end
|
574
|
-
|
575
|
-
it "should yield to a block" do
|
576
|
-
github.repos.should_receive(:teams).with(user, repo).and_yield('web')
|
577
|
-
github.repos.teams(user, repo) { |param| 'web'}
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
context "resource not found" do
|
582
|
-
before do
|
583
|
-
stub_get("/repos/#{user}/#{repo}/teams").
|
584
|
-
to_return(:body => '', :status => 404,
|
585
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
586
|
-
end
|
587
|
-
|
588
|
-
it "should fail to get resource" do
|
589
|
-
expect {
|
590
|
-
github.repos.teams user, repo
|
591
|
-
}.to raise_error(Github::Error::NotFound)
|
592
|
-
end
|
593
|
-
end
|
594
|
-
end # teams
|
29
|
+
its(:pubsubhubbub) { should be_a Github::Repos::PubSubHubbub }
|
595
30
|
|
596
31
|
end # Github::Repos
|