Commit 9d2aac82 authored by James Lopez's avatar James Lopez

fix and refactor spec

parent 58c1c493
......@@ -23,19 +23,19 @@ describe RemoteMirror do
describe 'encrypting credentials' do
context 'when setting URL for a first time' do
it 'should store the URL without credentials' do
mirror = create_mirror_with_url('http://foo:bar@test.com')
mirror = create_mirror(url: 'http://foo:bar@test.com')
expect(mirror.read_attribute(:url)).to eq('http://test.com')
end
it 'should store the credentials on a separate field' do
mirror = create_mirror_with_url('http://foo:bar@test.com')
mirror = create_mirror(url: 'http://foo:bar@test.com')
expect(mirror.credentials).to eq({ user: 'foo', password: 'bar' })
end
it 'should handle credentials with large content' do
mirror = create_mirror_with_url('http://bxnhm8dote33ct932r3xavslj81wxmr7o8yux8do10oozckkif:9ne7fuvjn40qjt35dgt8v86q9m9g9essryxj76sumg2ccl2fg26c0krtz2gzfpyq4hf22h328uhq6npuiq6h53tpagtsj7vsrz75@test.com')
mirror = create_mirror(url: 'http://bxnhm8dote33ct932r3xavslj81wxmr7o8yux8do10oozckkif:9ne7fuvjn40qjt35dgt8v86q9m9g9essryxj76sumg2ccl2fg26c0krtz2gzfpyq4hf22h328uhq6npuiq6h53tpagtsj7vsrz75@test.com')
expect(mirror.credentials).to eq({
user: 'bxnhm8dote33ct932r3xavslj81wxmr7o8yux8do10oozckkif',
......@@ -46,7 +46,7 @@ describe RemoteMirror do
context 'when updating the URL' do
it 'should allow a new URL without credentials' do
mirror = create_mirror_with_url('http://foo:bar@test.com')
mirror = create_mirror(url: 'http://foo:bar@test.com')
mirror.update_attribute(:url, 'http://test.com')
......@@ -55,7 +55,7 @@ describe RemoteMirror do
end
it 'should allow a new URL with credentials' do
mirror = create_mirror_with_url('http://test.com')
mirror = create_mirror(url: 'http://test.com')
mirror.update_attribute(:url, 'http://foo:bar@test.com')
......@@ -64,7 +64,7 @@ describe RemoteMirror do
end
it 'should update the remote config if credentials changed' do
mirror = create_mirror_with_url('http://foo:bar@test.com')
mirror = create_mirror(url: 'http://foo:bar@test.com')
repo = mirror.project.repository
mirror.update_attribute(:url, 'http://foo:baz@test.com')
......@@ -73,11 +73,10 @@ describe RemoteMirror do
end
it 'should still be picked up by the worker if is stuck' do
mirror = create_mirror_with_url('http://test.com')
mirror.update_attribute(:update_status, 'started')
# this will reset some of the updated_at fields
mirror.update_attribute(:url, 'http://foo:bar@test.com')
mirror = create_mirror(url: 'http://cantbeblank',
update_status: 'started',
last_update_at: nil,
updated_at: 25.hours.ago)
expect(RemoteMirror.stuck.last).to eq(mirror)
end
......@@ -87,7 +86,7 @@ describe RemoteMirror do
describe '#safe_url' do
context 'when URL contains credentials' do
it 'should mask the credentials' do
mirror = create_mirror_with_url('http://foo:bar@test.com')
mirror = create_mirror(url: 'http://foo:bar@test.com')
expect(mirror.safe_url).to eq('http://*****:*****@test.com')
end
......@@ -95,15 +94,15 @@ describe RemoteMirror do
context 'when URL does not contain credentials' do
it 'should show the full URL' do
mirror = create_mirror_with_url('http://test.com')
mirror = create_mirror(url: 'http://test.com')
expect(mirror.safe_url).to eq('http://test.com')
end
end
end
def create_mirror_with_url(url)
def create_mirror(params)
project = FactoryGirl.create(:project)
project.remote_mirrors.create!(url: url)
project.remote_mirrors.create!(params)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment