Skip to content

Commit ea6ea90

Browse files
committed
More tests
1 parent 8d37428 commit ea6ea90

File tree

6 files changed

+106
-9
lines changed

6 files changed

+106
-9
lines changed

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
source "http://rubygems.org"
22

3-
gem 'rspec'
3+
group :development do
4+
gem 'rspec'
5+
gem 'guard'
6+
gem 'guard-rspec'
7+
end

Gemfile.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
GEM
22
remote: http://rubygems.org/
33
specs:
4+
coderay (1.0.8)
45
diff-lcs (1.1.3)
6+
guard (1.5.4)
7+
listen (>= 0.4.2)
8+
lumberjack (>= 1.0.2)
9+
pry (>= 0.9.10)
10+
thor (>= 0.14.6)
11+
guard-rspec (2.1.2)
12+
guard (>= 1.1)
13+
rspec (~> 2.11)
14+
listen (0.5.3)
15+
lumberjack (1.0.2)
16+
method_source (0.8.1)
17+
pry (0.9.10)
18+
coderay (~> 1.0.5)
19+
method_source (~> 0.8)
20+
slop (~> 3.3.1)
521
rspec (2.12.0)
622
rspec-core (~> 2.12.0)
723
rspec-expectations (~> 2.12.0)
@@ -10,9 +26,13 @@ GEM
1026
rspec-expectations (2.12.1)
1127
diff-lcs (~> 1.1.3)
1228
rspec-mocks (2.12.2)
29+
slop (3.3.3)
30+
thor (0.16.0)
1331

1432
PLATFORMS
1533
ruby
1634

1735
DEPENDENCIES
36+
guard
37+
guard-rspec
1838
rspec

Guardfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
guard 'rspec' do
5+
watch(%r{^spec/.+_spec\.rb$})
6+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7+
watch('spec/spec_helper.rb') { "spec" }
8+
9+
# Rails example
10+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14+
watch('config/routes.rb') { "spec/routing" }
15+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
16+
17+
# Capybara features specs
18+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19+
20+
# Turnip features and steps
21+
watch(%r{^spec/acceptance/(.+)\.feature$})
22+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23+
end
24+

lib/gitlab_keys.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def exec
1515
case @command
1616
when 'add-key'; add_key
1717
when 'rm-key'; rm_key
18-
when 'rm-user'; rm_user
1918
else
2019
puts 'not allowed'
2120
end
@@ -33,9 +32,4 @@ def rm_key
3332
cmd = "sed '/#{@key}/d' #{auth_file}"
3433
system(cmd)
3534
end
36-
37-
def rm_user
38-
cmd = "sed -i '/gitlab-shell #{@username},/d' #{auth_file}"
39-
system(cmd)
40-
end
4135
end

lib/gitlab_shell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require_relative 'gitlab_config'
55

66
class GitlabShell
7-
attr_accessor :username, :repo_name, :git_cmd, :repos_path
7+
attr_accessor :username, :repo_name, :git_cmd, :repos_path, :repo_name
88

99
def initialize
1010
@username = ARGV.shift

spec/gitlab_shell_spec.rb

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,67 @@
55

66
describe :initialize do
77
before do
8-
ENV['SSH_ORIGINAL_COMMAND'] = 'git-receive-pack'
8+
ssh_cmd 'git-receive-pack'
99
ARGV[0] = 'dzaporozhets'
1010
@shell = GitlabShell.new
1111
end
1212

1313
it { @shell.username.should == 'dzaporozhets' }
1414
it { @shell.repos_path.should == "/home/git/repositories" }
1515
end
16+
17+
describe :parse_cmd do
18+
context 'w/o namespace' do
19+
before do
20+
ssh_cmd 'git-upload-pack gitlab-ci.git'
21+
@shell = GitlabShell.new
22+
@shell.send :parse_cmd
23+
end
24+
25+
it { @shell.repo_name.should == 'gitlab-ci.git' }
26+
it { @shell.git_cmd.should == 'git-upload-pack' }
27+
end
28+
29+
context 'namespace' do
30+
before do
31+
ssh_cmd 'git-upload-pack dmitriy.zaporozhets/gitlab-ci.git'
32+
@shell = GitlabShell.new
33+
@shell.send :parse_cmd
34+
end
35+
36+
it { @shell.repo_name.should == 'dmitriy.zaporozhets/gitlab-ci.git' }
37+
it { @shell.git_cmd.should == 'git-upload-pack' }
38+
end
39+
end
40+
41+
describe :exec do
42+
context 'git-upload-pack' do
43+
before do
44+
ssh_cmd 'git-upload-pack gitlab-ci.git'
45+
stubbed_shell
46+
end
47+
48+
it { @shell.exec.should be_true }
49+
end
50+
51+
context 'git-receive-pack' do
52+
before do
53+
ssh_cmd 'git-receive-pack gitlab-ci.git'
54+
stubbed_shell
55+
end
56+
57+
it { @shell.exec.should be_true }
58+
end
59+
end
60+
61+
def ssh_cmd(cmd)
62+
ENV['SSH_ORIGINAL_COMMAND'] = cmd
63+
end
64+
65+
def stubbed_shell
66+
ARGV[0] = 'dzaporozhets'
67+
@shell = GitlabShell.new
68+
@shell.stub(validate_access: true)
69+
@shell.stub(process_cmd: true)
70+
end
1671
end

0 commit comments

Comments
 (0)