Skip to content

Commit a94d899

Browse files
committed
test GitlabNet allowed method
1 parent 238fd9b commit a94d899

File tree

8 files changed

+191
-0
lines changed

8 files changed

+191
-0
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ source "http://rubygems.org"
33
group :development do
44
gem 'coveralls', require: false
55
gem 'rspec'
6+
gem 'webmock'
67
gem 'guard'
78
gem 'guard-rspec'
9+
gem 'vcr'
810
end

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
GEM
22
remote: http://rubygems.org/
33
specs:
4+
addressable (2.3.2)
45
coderay (1.0.8)
56
colorize (0.5.8)
67
coveralls (0.6.2)
@@ -9,6 +10,7 @@ GEM
910
rest-client
1011
simplecov (>= 0.7)
1112
thor
13+
crack (0.3.1)
1214
diff-lcs (1.1.3)
1315
guard (1.5.4)
1416
listen (>= 0.4.2)
@@ -43,6 +45,10 @@ GEM
4345
simplecov-html (0.7.1)
4446
slop (3.3.3)
4547
thor (0.16.0)
48+
vcr (2.4.0)
49+
webmock (1.9.0)
50+
addressable (>= 2.2.7)
51+
crack (>= 0.1.7)
4652

4753
PLATFORMS
4854
ruby
@@ -52,3 +58,5 @@ DEPENDENCIES
5258
guard
5359
guard-rspec
5460
rspec
61+
vcr
62+
webmock

lib/gitlab_net.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def host
3535
end
3636

3737
def get(url)
38+
puts url.inspect
3839
url = URI.parse(url)
3940
http = Net::HTTP.new(url.host, url.port)
4041
http.use_ssl = (url.port == 443)

spec/gitlab_net_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require_relative 'spec_helper'
2+
require_relative '../lib/gitlab_net'
3+
4+
5+
describe GitlabNet do
6+
describe :allowed? do
7+
let(:gitlab_net) { GitlabNet.new }
8+
9+
before do
10+
gitlab_net.stub!(:host).and_return('https://dev.gitlab.org/api/v3/internal')
11+
end
12+
13+
it 'should allow pull access for dev.gitlab.org', vcr: true do
14+
VCR.use_cassette("allowed-pull") do
15+
access = gitlab_net.allowed?('git-receive-pack', 'gitlab/gitlabhq.git', 'key-1', 'master')
16+
access.should be_true
17+
end
18+
end
19+
20+
it 'should allow push access for dev.gitlab.org', vcr: true do
21+
VCR.use_cassette("allowed-push") do
22+
access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'key-1', 'master')
23+
access.should be_true
24+
end
25+
end
26+
end
27+
end

spec/spec_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@
44
require 'coveralls'
55
Coveralls.wear!
66
end
7+
8+
require 'vcr'
9+
require 'webmock'
10+
11+
VCR.configure do |c|
12+
c.cassette_library_dir = 'spec/vcr_cassettes'
13+
c.hook_into :webmock
14+
c.configure_rspec_metadata!
15+
end

spec/vcr_cassettes/allowed-pull.yml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/allowed-push.yml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/dev_gitlab_org.yml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)