summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-03-20 10:56:43 +0100
committerRémy Coutable <remy@rymai.me>2017-03-20 16:24:01 +0100
commitbe25bbc4d2c7e3d5cf3da6f51cb7f7355295ef52 (patch)
tree4f89c264978be7e93ea7a189e8dbbdca3439babe /spec/lib
parentcd3e410110a5c6f33c5e873f8fb54883a8e11754 (diff)
downloadgitlab-ce-be25bbc4d2c7e3d5cf3da6f51cb7f7355295ef52.tar.gz
Fix ProjectWiki#http_url_to_repo signature
New Gitlab::UrlSanitizer.http_credentials_for_user method responsible for generating a credentials hash from a user. Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/url_sanitizer_spec.rb34
1 files changed, 28 insertions, 6 deletions
diff --git a/spec/lib/gitlab/url_sanitizer_spec.rb b/spec/lib/gitlab/url_sanitizer_spec.rb
index 3fd361de458..fc144a2556a 100644
--- a/spec/lib/gitlab/url_sanitizer_spec.rb
+++ b/spec/lib/gitlab/url_sanitizer_spec.rb
@@ -5,6 +5,7 @@ describe Gitlab::UrlSanitizer, lib: true do
let(:url_sanitizer) do
described_class.new("https://github.com/me/project.git", credentials: credentials)
end
+ let(:user) { double(:user, username: 'john.doe') }
describe '.sanitize' do
def sanitize_url(url)
@@ -53,12 +54,33 @@ describe Gitlab::UrlSanitizer, lib: true do
end
end
+ describe '.valid?' do
+ it 'validates url strings' do
+ expect(described_class.valid?(nil)).to be(false)
+ expect(described_class.valid?('valid@project:url.git')).to be(true)
+ expect(described_class.valid?('123://invalid:url')).to be(false)
+ end
+ end
+
+ describe '.http_credentials_for_user' do
+ it { expect(described_class.http_credentials_for_user(user)).to eq({ user: 'john.doe' }) }
+ it { expect(described_class.http_credentials_for_user('foo')).to eq({}) }
+ end
+
describe '#sanitized_url' do
it { expect(url_sanitizer.sanitized_url).to eq("https://github.com/me/project.git") }
end
describe '#credentials' do
it { expect(url_sanitizer.credentials).to eq(credentials) }
+
+ context 'when user is given to #initialize' do
+ let(:url_sanitizer) do
+ described_class.new("https://github.com/me/project.git", credentials: described_class.http_credentials_for_user(user))
+ end
+
+ it { expect(url_sanitizer.credentials).to eq({ user: 'john.doe' }) }
+ end
end
describe '#full_url' do
@@ -69,13 +91,13 @@ describe Gitlab::UrlSanitizer, lib: true do
expect(sanitizer.full_url).to eq('user@server:project.git')
end
- end
- describe '.valid?' do
- it 'validates url strings' do
- expect(described_class.valid?(nil)).to be(false)
- expect(described_class.valid?('valid@project:url.git')).to be(true)
- expect(described_class.valid?('123://invalid:url')).to be(false)
+ context 'when user is given to #initialize' do
+ let(:url_sanitizer) do
+ described_class.new("https://github.com/me/project.git", credentials: described_class.http_credentials_for_user(user))
+ end
+
+ it { expect(url_sanitizer.full_url).to eq("https://john.doe@github.com/me/project.git") }
end
end
end