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

fix and refactor spec

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