git_hub 0.2.10 → 0.3.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.rdoc +43 -7
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/git_hub +1 -0
- data/git_hub.gemspec +36 -32
- data/lib/git_hub.rb +3 -5
- data/lib/git_hub/api.rb +8 -13
- data/lib/git_hub/base.rb +44 -42
- data/lib/git_hub/commit.rb +6 -4
- data/lib/git_hub/extensions.rb +25 -0
- data/lib/git_hub/repo.rb +21 -24
- data/lib/git_hub/user.rb +8 -6
- data/spec/git_hub/api_spec.rb +21 -0
- data/spec/git_hub/base_spec.rb +5 -5
- data/spec/git_hub/commit_spec.rb +2 -2
- data/spec/git_hub/extensions_spec.rb +55 -0
- data/spec/git_hub/repo_spec.rb +51 -40
- data/spec/git_hub/user_spec.rb +26 -20
- data/spec/spec_helper.rb +31 -46
- data/spec/stubs/{api_route_error.res → yaml/api_route_error.res} +0 -0
- data/spec/stubs/{commits → yaml/commits}/list/joe007/fine_repo/master.res +0 -0
- data/spec/stubs/{commits → yaml/commits}/list/joe007/fine_repo/master/README.res +0 -0
- data/spec/stubs/{commits → yaml/commits}/show/joe007/fine_repo/3a70f86293b719f193f778a8710b1f83f2f7bf38.res +0 -0
- data/spec/stubs/{commits → yaml/commits}/show/joe007/fine_repo/5e61f0687c40ca48214d09dc7ae2d0d0d8fbfeb8.res +0 -0
- data/spec/stubs/{commits → yaml/commits}/show/joe007/fine_repo/f7f5dddaa37deacc83f1f56876e2b135389d03ab.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/create.1.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/create.2.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/create.3.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/create.4.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/delete/new_repo.1.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/delete/new_repo.2.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/delete/new_repo.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/search/fine+repo.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/search/joe+repo.res +0 -0
- data/spec/stubs/yaml/repos/show/invalid_github_user/err_repo.res +14 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/err_repo.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/fine_repo.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/fine_repo/branches.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/fine_repo/tags.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/new_repo.res +0 -0
- data/spec/stubs/{user → yaml/user}/follow/arvicco.res +0 -0
- data/spec/stubs/{user → yaml/user}/search/joe+007.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/arvicco.res +0 -0
- data/spec/stubs/{user/show/joe_is_not_github_user.res → yaml/user/show/invalid_github_user.res} +7 -3
- data/spec/stubs/{user → yaml/user}/show/joe007.auth.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/joe007.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/joe007/followers.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/joe007/following.empty.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/joe007/following.res +0 -0
- metadata +36 -32
data/lib/git_hub/repo.rb
CHANGED
@@ -50,7 +50,7 @@ module GitHub
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def clone_url
|
53
|
-
url = private? ||
|
53
|
+
url = private? || API.auth['login'] == user ? "git@github.com:" : "git://github.com/"
|
54
54
|
url += "#{@user}/#{@name}.git"
|
55
55
|
end
|
56
56
|
|
@@ -67,7 +67,7 @@ module GitHub
|
|
67
67
|
# :path:: Only commits for specific path
|
68
68
|
# :sha/:id:: Only one commit with specific id (sha)
|
69
69
|
def commits opts = {}
|
70
|
-
|
70
|
+
Commit.find opts.merge(:user => @user, :repo => @name)
|
71
71
|
end
|
72
72
|
|
73
73
|
class << self # Repo class methods
|
@@ -76,8 +76,8 @@ module GitHub
|
|
76
76
|
# :owner/:user/:username:: Github user name
|
77
77
|
# :repo/:repository/:project/:name:: Repo name
|
78
78
|
# :query/:search:: Array of search terms as Strings or Symbols
|
79
|
-
def find(
|
80
|
-
user, repo, query = extract
|
79
|
+
def find( *args )
|
80
|
+
user, repo, query = extract args, :user, :repo, :query
|
81
81
|
path = if query
|
82
82
|
"/search/#{query.map(&:to_s).join('+')}"
|
83
83
|
elsif user && repo
|
@@ -94,24 +94,22 @@ module GitHub
|
|
94
94
|
alias search find
|
95
95
|
|
96
96
|
# Create new github repo, accepts Hash with :repo, :description, :homepage, :public/:private
|
97
|
-
def create(
|
98
|
-
repo, desc, homepage, public = extract
|
99
|
-
|
97
|
+
def create!(*args)
|
98
|
+
repo, desc, homepage, public = extract args, :repo, :desc, :homepage, :public
|
99
|
+
API.ensure_auth
|
100
100
|
instantiate post("/create", 'name' => repo, 'description' => desc,
|
101
|
-
|
101
|
+
'homepage' => homepage, 'public' => (public ? 1 : 0))
|
102
102
|
end
|
103
|
-
end
|
103
|
+
end
|
104
104
|
|
105
105
|
# Delete github repo, accepts optional Hash with authentication
|
106
|
-
def delete
|
107
|
-
|
106
|
+
def delete!
|
107
|
+
API.ensure_auth
|
108
108
|
result = post("/delete/#{@name}")
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
114
|
-
end
|
109
|
+
token = result['delete_token']
|
110
|
+
return result unless token
|
111
|
+
post("/delete/#{@name}", 'delete_token' => token)
|
112
|
+
end
|
115
113
|
|
116
114
|
def add_service
|
117
115
|
end
|
@@ -133,14 +131,13 @@ module GitHub
|
|
133
131
|
|
134
132
|
def hash_of_commits(resource)
|
135
133
|
result = get "/show/#{@user}/#{@name}/#{resource}"
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
else
|
142
|
-
result
|
134
|
+
tagged_shas = result[resource.to_s]
|
135
|
+
return result unless tagged_shas
|
136
|
+
|
137
|
+
tagged_commits = tagged_shas.map do |tag, sha|
|
138
|
+
[tag, Commit.find(:user=>@user, :repo=>@name, :sha=>sha)]
|
143
139
|
end
|
140
|
+
Hash[*tagged_commits.flatten]
|
144
141
|
end
|
145
142
|
|
146
143
|
# repos/show/:user/:repo/languages
|
data/lib/git_hub/user.rb
CHANGED
@@ -15,7 +15,7 @@ module GitHub
|
|
15
15
|
|
16
16
|
aliases_for :homepage => :blog, :name => [:user, :username], :created => :created_at
|
17
17
|
|
18
|
-
def initialize(opts)
|
18
|
+
def initialize( opts )
|
19
19
|
@public_repo_count = opts.delete('repos') # TODO: find better way without modifying opts?
|
20
20
|
@followers_count = opts.delete('followers')
|
21
21
|
super
|
@@ -29,7 +29,7 @@ module GitHub
|
|
29
29
|
@type ||= "user"
|
30
30
|
end
|
31
31
|
|
32
|
-
def url
|
32
|
+
def url; "http://github.com/#{@name}" end
|
33
33
|
|
34
34
|
class << self
|
35
35
|
|
@@ -37,8 +37,8 @@ module GitHub
|
|
37
37
|
# :user/:username:: Github user name
|
38
38
|
# :repo/:repository/:project/:name:: Repo name
|
39
39
|
# :query/:search:: Array of search terms as Strings or Symbols
|
40
|
-
def find(
|
41
|
-
user, query = extract
|
40
|
+
def find( *args )
|
41
|
+
user, query = extract args, :user, :query
|
42
42
|
path = if query
|
43
43
|
"/search/#{query.map(&:to_s).join('+')}"
|
44
44
|
elsif user
|
@@ -59,11 +59,13 @@ module GitHub
|
|
59
59
|
get("/show/#{@name}/following")['users'].map {|user| User.find(:user => user )}
|
60
60
|
end
|
61
61
|
|
62
|
-
def follow user
|
62
|
+
def follow!( user )
|
63
|
+
API.ensure_auth
|
63
64
|
post("/follow/#{user}")['users'].map {|user| User.find(:user => user )}
|
64
65
|
end
|
65
66
|
|
66
|
-
def unfollow user # api /user/unfollow/:user is not working properly atm, using http
|
67
|
+
def unfollow!( user )# api /user/unfollow/:user is not working properly atm, using http
|
68
|
+
API.ensure_auth
|
67
69
|
res = get 'http://github.com/users/follow', 'target' => user
|
68
70
|
raise "User Not Found #{user}" unless res.code == 302.to_s
|
69
71
|
following
|
data/spec/git_hub/api_spec.rb
CHANGED
@@ -2,6 +2,27 @@ require File.expand_path(
|
|
2
2
|
File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
3
3
|
|
4
4
|
module GitHubTest
|
5
|
+
# Stubs github server, with options:
|
6
|
+
# :host:: Host name - default 'github.com'
|
7
|
+
# :port:: Port - default 80
|
8
|
+
def stub_server(options={})
|
9
|
+
server = Net::HTTP.new(options[:host] ||'github.com', options[:port] || 80)
|
10
|
+
Net::HTTP.stub!(:new).and_return(server)
|
11
|
+
server
|
12
|
+
end
|
13
|
+
|
14
|
+
# Stubs http request, with options:
|
15
|
+
# :path:: Request path - default '/api/v2/yaml/repos/create'
|
16
|
+
# :get:: Indicates that request is get, otherwise post
|
17
|
+
def stub_req(options={})
|
18
|
+
path = options[:path] || '/api/v2/yaml/repos/create'
|
19
|
+
options[:get] ? Net::HTTP::Get.new(path) : Net::HTTP::Post.new(path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def stub_server_and_req(options = {})
|
23
|
+
[stub_server(options), stub_req(options)]
|
24
|
+
end
|
25
|
+
|
5
26
|
describe GitHub::Api do
|
6
27
|
after(:each) do
|
7
28
|
GitHub::Api.instance.auth.clear
|
data/spec/git_hub/base_spec.rb
CHANGED
@@ -4,17 +4,17 @@ require File.expand_path(
|
|
4
4
|
module GitHubTest
|
5
5
|
describe GitHub::Base do
|
6
6
|
after(:each) do
|
7
|
-
|
7
|
+
clear_auth
|
8
8
|
end
|
9
9
|
|
10
10
|
context 'requests' do
|
11
11
|
it 'submits appropriate requests to api as get/post methods (both class and instance)' do
|
12
12
|
base = described_class.new
|
13
|
-
|
13
|
+
API.should_receive(:request).with(:get, '/blah', anything()).twice
|
14
14
|
base.get ('/blah')
|
15
15
|
described_class.get ('/blah')
|
16
16
|
|
17
|
-
|
17
|
+
API.should_receive(:request).with(:post, '/blah', anything()).twice
|
18
18
|
base.post ('/blah')
|
19
19
|
described_class.post ('/blah')
|
20
20
|
end
|
@@ -22,11 +22,11 @@ module GitHubTest
|
|
22
22
|
it 'prepends get/post calls by content of @base_uri variable' do
|
23
23
|
base = described_class.new
|
24
24
|
described_class.class_eval { @base_uri = 'http://base1.com' }
|
25
|
-
|
25
|
+
API.should_receive(:request).with(:get, 'http://base1.com/blah', anything()).twice
|
26
26
|
base.get ('/blah')
|
27
27
|
described_class.get ('/blah')
|
28
28
|
|
29
|
-
|
29
|
+
API.should_receive(:request).with(:post, 'http://base1.com/blah', anything()).twice
|
30
30
|
base.post ('/blah')
|
31
31
|
described_class.post ('/blah')
|
32
32
|
end
|
data/spec/git_hub/commit_spec.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(
|
2
|
+
File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
3
|
+
|
4
|
+
module GitHubTest
|
5
|
+
module A
|
6
|
+
class B
|
7
|
+
class C
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe String do
|
13
|
+
context '#to_class' do
|
14
|
+
it 'converts string into appropriate Class constant' do
|
15
|
+
"Fixnum".to_class.should == Fixnum
|
16
|
+
"GitHubTest::A::B::C".to_class.should == GitHubTest::A::B::C
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns nil if string is not convertible into class' do
|
20
|
+
"Math".to_class.should == nil
|
21
|
+
"Math::PI".to_class.should == nil
|
22
|
+
"Something".to_class.should == nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'deals with leading colons' do
|
26
|
+
"::GitHubTest::A::B::C".to_class.should == GitHubTest::A::B::C
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Array do
|
32
|
+
context '#args_and_opts' do
|
33
|
+
it 'splits array into two components: enum with args and options hash' do
|
34
|
+
args, opts = [1, 2, {3=>4}].args_and_opts
|
35
|
+
args.should be_an Enumerator
|
36
|
+
args.to_a.should == [1, 2]
|
37
|
+
opts.should == {3=>4}
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'correctly splits options if 2 Hashes are last' do
|
41
|
+
args, opts = [1, 2, {3=>4}, {5=>6}].args_and_opts
|
42
|
+
args.should be_an Enumerator
|
43
|
+
args.to_a.should == [1, 2, {3=>4}]
|
44
|
+
opts.should == {5=>6}
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns empty options if last component is not a Hash' do
|
48
|
+
args, opts = [1, 2, {3=>4}, 5].args_and_opts
|
49
|
+
args.should be_an Enumerator
|
50
|
+
args.to_a.should == [1, 2, {3=>4}, 5]
|
51
|
+
opts.should == {}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/git_hub/repo_spec.rb
CHANGED
@@ -12,7 +12,7 @@ module GitHubTest
|
|
12
12
|
repo.type.should == 'repo'
|
13
13
|
repo.name.should == name.to_s
|
14
14
|
repo.url.should == "http://github.com/joe007/#{name.to_s}"
|
15
|
-
repo.clone_url.should == if
|
15
|
+
repo.clone_url.should == if API.authenticated?
|
16
16
|
"git@github.com:joe007/#{name.to_s}.git"
|
17
17
|
else
|
18
18
|
"git://github.com/joe007/#{name.to_s}.git"
|
@@ -46,7 +46,7 @@ module GitHubTest
|
|
46
46
|
repo.homepage.should == nil
|
47
47
|
repo.open_issues.should == nil
|
48
48
|
end
|
49
|
-
when
|
49
|
+
when "#{new_repo}"
|
50
50
|
repo.watchers.should == 1
|
51
51
|
repo.followers.should == 1
|
52
52
|
repo.open_issues.should == 0
|
@@ -57,7 +57,7 @@ module GitHubTest
|
|
57
57
|
repo.homepage.should == nil
|
58
58
|
when 'with_attributes'
|
59
59
|
repo.description.should == 'New repo'
|
60
|
-
repo.homepage.should ==
|
60
|
+
repo.homepage.should == "http://joe.org/new_repo"
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -67,18 +67,25 @@ module GitHubTest
|
|
67
67
|
FakeWeb.allow_net_connect = false if TEST_FAKE_WEB
|
68
68
|
end
|
69
69
|
after(:each) do
|
70
|
-
FakeWeb.clean_registry
|
71
|
-
|
70
|
+
FakeWeb.clean_registry if TEST_FAKE_WEB
|
71
|
+
clear_auth
|
72
72
|
end
|
73
73
|
|
74
74
|
context '.find as /show/:user/:repo' do
|
75
|
-
it 'finds repo of a (valid) github user' do
|
75
|
+
it 'finds repo of a (valid) github user given options Hash' do
|
76
76
|
expect(:get, "#{github_yaml}/repos/show/joe007/fine_repo") do
|
77
77
|
repo = GitHub::Repo.find(:user=>'joe007', :repo=>'fine_repo')
|
78
78
|
should_be_repo repo
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
it 'finds repo of a (valid) github user given simple arguments' do
|
83
|
+
expect(:get, "#{github_yaml}/repos/show/joe007/fine_repo") do
|
84
|
+
repo = GitHub::Repo.find('joe007', 'fine_repo')
|
85
|
+
should_be_repo repo
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
82
89
|
it 'finds repo if user object is given instead of username' do
|
83
90
|
expect(:get, "#{github_yaml}/repos/show/joe007/fine_repo") do
|
84
91
|
repo = GitHub::Repo.find(:user=>joe, :repo=>'fine_repo')
|
@@ -94,6 +101,15 @@ module GitHubTest
|
|
94
101
|
res['error'].first.should have_key 'error'
|
95
102
|
end
|
96
103
|
end
|
104
|
+
|
105
|
+
it 'fails returning error object if user is invalid' do
|
106
|
+
expect(:get, "#{github_yaml}/repos/show/invalid_github_user/err_repo") do
|
107
|
+
res = GitHub::Repo.find('invalid_github_user', 'err_repo')
|
108
|
+
res.should have_key 'error' # res = {"error"=>[{"error"=>"repository not found"}]}
|
109
|
+
res['error'].should be_kind_of Array
|
110
|
+
res['error'].first.should have_key 'error'
|
111
|
+
end
|
112
|
+
end
|
97
113
|
end
|
98
114
|
|
99
115
|
context '.find as /show/:user)' do
|
@@ -122,38 +138,46 @@ module GitHubTest
|
|
122
138
|
end
|
123
139
|
end
|
124
140
|
|
125
|
-
context '.create' do
|
141
|
+
context '.create!' do
|
142
|
+
before(:each) {wait}
|
126
143
|
after(:each) do
|
127
|
-
|
128
|
-
|
144
|
+
authenticate_as_joe
|
145
|
+
expect(:post, "http://github.com/api/v2/yaml/repos/delete/#{new_repo}", 1)
|
146
|
+
@repo.delete! if @repo.is_a? GitHub::Repo
|
129
147
|
wait
|
130
148
|
end
|
131
149
|
|
132
150
|
it 'creates new repo for authenticated github user' do
|
133
151
|
authenticate_as_joe
|
134
|
-
# keys = {:name =>
|
152
|
+
# keys = {:name => "#{new_repo}", :public => 1}.merge joe_auth # Fake_Web doesn't support key expectations yet
|
135
153
|
expect(:post, "#{github_yaml}/repos/create", 1) do
|
136
|
-
@repo = GitHub::Repo.create(:repo=>
|
137
|
-
should_be_repo @repo,
|
154
|
+
@repo = GitHub::Repo.create!(:repo=>"#{new_repo}")
|
155
|
+
should_be_repo @repo, "#{new_repo}", :simple
|
138
156
|
end
|
139
157
|
end
|
140
158
|
|
141
159
|
it 'creates new repo with extended attributes' do
|
142
|
-
wait
|
143
160
|
authenticate_as_joe
|
144
|
-
# keys = {:name =>
|
145
|
-
# :homepage =>
|
161
|
+
# keys = {:name => "#{new_repo}", :description => 'New repo', # Fake_Web doesn't support key expectations yet
|
162
|
+
# :homepage => "http://joe.org/#{new_repo}", :public => 1}.merge joe_auth
|
146
163
|
expect(:post, "#{github_yaml}/repos/create", 2)
|
147
|
-
@repo = GitHub::Repo.create(:name=>
|
164
|
+
@repo = GitHub::Repo.create!(:name=>"#{new_repo}", :description => 'New repo',
|
148
165
|
:homepage => 'http://joe.org/new_repo', :private => false)
|
149
|
-
should_be_repo @repo,
|
166
|
+
should_be_repo @repo, "#{new_repo}", :with_attributes
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'creates new repo without options' do
|
170
|
+
authenticate_as_joe
|
171
|
+
expect(:post, "#{github_yaml}/repos/create", 2)
|
172
|
+
@repo = GitHub::Repo.create!("#{new_repo}", 'New repo', 'http://joe.org/new_repo', false)
|
173
|
+
should_be_repo @repo, "#{new_repo}", :with_attributes
|
150
174
|
end
|
151
175
|
|
152
176
|
it 'fails if repo with the same name already exists' do
|
153
177
|
authenticate_as_joe
|
154
178
|
# keys = {:name => 'fine_repo', :public => 1}.merge joe_auth # Fake_Web doesn't support key expectations yet
|
155
179
|
expect(:post, "#{github_yaml}/repos/create", 4)
|
156
|
-
res = GitHub::Repo.create(:name=>'fine_repo')
|
180
|
+
res = GitHub::Repo.create!(:name=>'fine_repo')
|
157
181
|
res.should have_key 'error' # res = {"error"=>[{"error"=>"repository not found"}]}
|
158
182
|
res['error'].should be_kind_of Array
|
159
183
|
res['error'].first.should have_key 'error'
|
@@ -161,21 +185,23 @@ module GitHubTest
|
|
161
185
|
end
|
162
186
|
end
|
163
187
|
|
164
|
-
context '#delete' do
|
188
|
+
context '#delete!' do
|
165
189
|
before(:each) do
|
166
190
|
authenticate_as_joe
|
167
191
|
expect(:post, "#{github_yaml}/repos/create", 1)
|
168
|
-
@repo = GitHub::Repo.create(:user=>'joe007', :repo=>
|
169
|
-
|
192
|
+
@repo = GitHub::Repo.create!(:user=>'joe007', :repo=>"#{new_repo}")
|
193
|
+
raise 'Repo creation failed' unless @repo.is_a?(GitHub::Repo)
|
194
|
+
clear_auth
|
170
195
|
end
|
171
196
|
|
172
197
|
it 'deletes new repo for authenticated github user' do
|
173
198
|
# post1 = { :expected_keys => joe_auth, # Fake_Web doesn't support key expectations yet
|
174
|
-
# :body => body_from_file('/repos/delete/new_repo.1') }
|
199
|
+
# :body => body_from_file('/repos/delete/"#{new_repo}".1') }
|
175
200
|
# post2 = { :expected_keys => {:delete_token => :any}.merge(joe_auth),
|
176
|
-
# :body => body_from_file('/repos/delete/new_repo.2') }
|
177
|
-
|
178
|
-
|
201
|
+
# :body => body_from_file('/repos/delete/"#{new_repo}".2') }
|
202
|
+
authenticate_as_joe
|
203
|
+
expect(:post, "#{github_yaml}/repos/delete/#{new_repo}", [1, 2])
|
204
|
+
res = @repo.delete!
|
179
205
|
res['status'].should == 'deleted'
|
180
206
|
end
|
181
207
|
end
|
@@ -245,21 +271,6 @@ module GitHubTest
|
|
245
271
|
end
|
246
272
|
end
|
247
273
|
|
248
|
-
it 'tests' do
|
249
|
-
pending
|
250
|
-
authenticate_as_joe
|
251
|
-
expect(:get, "#{github_yaml}/repos/showp/joe007/new_repo")
|
252
|
-
repos = GitHub::Repo.show('arvicco')
|
253
|
-
p repos
|
254
|
-
p repos.map(&:url)
|
255
|
-
repos.should be_an Array
|
256
|
-
repos.should_not be_empty
|
257
|
-
if repos.last.name == 'new_repo'
|
258
|
-
repos.last.delete
|
259
|
-
end
|
260
|
-
true.should == false
|
261
|
-
end
|
262
|
-
|
263
274
|
end # describe GitHub::Repo
|
264
275
|
end # module GithubTest
|
265
276
|
|
data/spec/git_hub/user_spec.rb
CHANGED
@@ -24,7 +24,7 @@ module GitHubTest
|
|
24
24
|
user.language.should == ''
|
25
25
|
user.pushed.should == Time.parse('2009-12-30T14:15:16.972Z')
|
26
26
|
user.score.should be_close 4.18, 0.2
|
27
|
-
when :show
|
27
|
+
when :show
|
28
28
|
# attributes differs between /show and /search
|
29
29
|
user.public_repo_count.should == 3
|
30
30
|
user.followers_count.should == 1
|
@@ -37,15 +37,6 @@ module GitHubTest
|
|
37
37
|
user.following_count.should == 1
|
38
38
|
user.public_gist_count.should == 0
|
39
39
|
user.blog.should == 'http://www.joe007.org'
|
40
|
-
if type == :show_auth
|
41
|
-
# additional attributes for athenticated user
|
42
|
-
user.plan.should == {'name' => 'free', 'collaborators' => 0, 'space' => 307200, 'private_repos' => 0}
|
43
|
-
user.collaborators.should == 0
|
44
|
-
user.disk_usage.should == 76
|
45
|
-
user.private_gist_count.should == 0
|
46
|
-
user.owned_private_repo_count.should == 0
|
47
|
-
user.total_private_repo_count.should == 0
|
48
|
-
end
|
49
40
|
end
|
50
41
|
when :arvicco
|
51
42
|
user.id.should == 'user-39557'
|
@@ -61,8 +52,8 @@ module GitHubTest
|
|
61
52
|
FakeWeb.allow_net_connect = false if TEST_FAKE_WEB
|
62
53
|
end
|
63
54
|
after(:each) do
|
64
|
-
FakeWeb.clean_registry
|
65
|
-
|
55
|
+
FakeWeb.clean_registry if TEST_FAKE_WEB
|
56
|
+
clear_auth
|
66
57
|
wait
|
67
58
|
end
|
68
59
|
|
@@ -74,17 +65,31 @@ module GitHubTest
|
|
74
65
|
end
|
75
66
|
end
|
76
67
|
|
68
|
+
it 'finds valid github user by name' do
|
69
|
+
expect(:get, "#{github_yaml}/user/show/joe007") do
|
70
|
+
user = GitHub::User.find('joe007')
|
71
|
+
should_be_user user, :joe007
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
77
75
|
it 'finds authenticated github user with additional attributes set' do
|
78
76
|
expect(:get, "#{github_yaml}/user/show/joe007", :auth) do
|
79
|
-
|
77
|
+
authenticate_as_joe
|
80
78
|
user = GitHub::User.find(:user=>'joe007')
|
81
|
-
should_be_user user, :joe007
|
79
|
+
should_be_user user, :joe007
|
80
|
+
# additional attributes for athenticated user
|
81
|
+
user.plan.should == {'name' => 'free', 'collaborators' => 0, 'space' => 307200, 'private_repos' => 0}
|
82
|
+
user.collaborators.should == 0
|
83
|
+
user.disk_usage.should == 76
|
84
|
+
user.private_gist_count.should == 0
|
85
|
+
user.owned_private_repo_count.should == 0
|
86
|
+
user.total_private_repo_count.should == 0
|
82
87
|
end
|
83
88
|
end
|
84
89
|
|
85
90
|
it 'fails to find invalid github user' do
|
86
|
-
expect(:get, "#{github_yaml}/user/show/
|
87
|
-
res = GitHub::User.find(:user=>'
|
91
|
+
expect(:get, "#{github_yaml}/user/show/invalid_github_user") do
|
92
|
+
res = GitHub::User.find(:user=>'invalid_github_user')
|
88
93
|
res.code.should == 404.to_s
|
89
94
|
res.message.should == 'Not Found'
|
90
95
|
end
|
@@ -126,6 +131,7 @@ module GitHubTest
|
|
126
131
|
end
|
127
132
|
end
|
128
133
|
end
|
134
|
+
|
129
135
|
context 'actions' do
|
130
136
|
before(:each) do
|
131
137
|
expect(:get, "http://github.com/users/follow")
|
@@ -136,14 +142,14 @@ module GitHubTest
|
|
136
142
|
# after - normal state is for joe to follow arvicco
|
137
143
|
authenticate_as_joe
|
138
144
|
expect(:post, "#{github_yaml}/user/follow/arvicco")
|
139
|
-
joe.follow :arvicco
|
145
|
+
joe.follow! :arvicco
|
140
146
|
wait
|
141
147
|
end
|
142
148
|
|
143
149
|
it 'stops following previously followed user (if authenticated)' do
|
144
150
|
expect(:get, "http://github.com/users/follow") do
|
145
151
|
expect(:get, "#{github_yaml}/user/show/joe007/following", :empty)
|
146
|
-
following = joe.unfollow :arvicco
|
152
|
+
following = joe.unfollow! :arvicco
|
147
153
|
following.should be_kind_of Array
|
148
154
|
following.should be_empty
|
149
155
|
end
|
@@ -152,11 +158,11 @@ module GitHubTest
|
|
152
158
|
it 'starts following new user (if authenticated)' do
|
153
159
|
# before - normal state is for joe to follow arvicco
|
154
160
|
expect(:get, "#{github_yaml}/user/show/joe007/following")
|
155
|
-
joe.unfollow :arvicco
|
161
|
+
joe.unfollow! :arvicco
|
156
162
|
wait
|
157
163
|
|
158
164
|
expect(:post, "#{github_yaml}/user/follow/arvicco") do
|
159
|
-
following = joe.follow :arvicco
|
165
|
+
following = joe.follow! :arvicco
|
160
166
|
following.should be_kind_of Array
|
161
167
|
following.should have(1).user
|
162
168
|
following.each {|user| user.should be_a GitHub::User}
|