Commit ea47850f authored by Rubén Dávila's avatar Rubén Dávila

Delete ProjectImportData record only if Project is not a mirror.

* This fix ensure we always use the full import URL when syncing the
mirror.
* Refactor method name.
parent 5867dd0c
......@@ -269,7 +269,7 @@ class Project < ActiveRecord::Base
state :failed
after_transition any => :started, do: :schedule_add_import_job
after_transition any => :finished, do: :clear_import_data
after_transition any => :finished, do: :reset_cache_and_import_attrs
after_transition started: :finished do |project, transaction|
if project.mirror?
......@@ -453,12 +453,12 @@ class Project < ActiveRecord::Base
end
end
def clear_import_data
def reset_cache_and_import_attrs
update(import_error: nil)
ProjectCacheWorker.perform_async(self.id)
self.import_data.destroy if self.import_data
self.import_data.destroy if !mirror? && import_data
end
def import_url=(value)
......
......@@ -894,4 +894,27 @@ describe Project, models: true do
end
end
end
describe 'handling import URL' do
context 'when project is a mirror' do
it 'returns the full URL' do
project = create(:project, :mirror, import_url: 'http://user:pass@test.com')
project.import_finish
expect(project.reload.import_url).to eq('http://user:pass@test.com')
end
end
context 'when project is not a mirror' do
it 'returns the sanitized URL' do
project = create(:project, import_status: 'started', import_url: 'http://user:pass@test.com')
project.import_finish
expect(project.reload.import_url).to eq('http://test.com')
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