Commit b56e4038 authored by Tiago Botelho's avatar Tiago Botelho

Removes irrelevant unit tests for remote mirror and mirrors with the same URL

parent a5accabe
...@@ -63,7 +63,8 @@ module EE ...@@ -63,7 +63,8 @@ module EE
end end
def valid_mirror_user?(mirror_params) def valid_mirror_user?(mirror_params)
return true unless mirror_params[:mirror_user_id].present? return true unless mirror_params[:mirror]
return false unless mirror_params[:mirror_user_id].present?
default_mirror_users.map(&:id).include?(mirror_params[:mirror_user_id].to_i) default_mirror_users.map(&:id).include?(mirror_params[:mirror_user_id].to_i)
end end
......
...@@ -19,22 +19,6 @@ describe Projects::MirrorsController do ...@@ -19,22 +19,6 @@ describe Projects::MirrorsController do
do_put(project, remote_mirrors_attributes: { '0' => { 'enabled' => 1, 'url' => url } }) do_put(project, remote_mirrors_attributes: { '0' => { 'enabled' => 1, 'url' => url } })
end.to change { RemoteMirror.count }.to(1) end.to change { RemoteMirror.count }.to(1)
end end
context 'when remote mirror has the same URL' do
it 'does not allow to create the remote mirror' do
expect do
do_put(project, remote_mirrors_attributes: { '0' => { 'enabled' => 1, 'url' => project.import_url } })
end.not_to change { RemoteMirror.count }
end
context 'with disabled local mirror' do
it 'allows to create a remote mirror' do
expect do
do_put(project, mirror: 0, remote_mirrors_attributes: { '0' => { 'enabled' => 1, 'url' => project.import_url } })
end.to change { RemoteMirror.count }.to(1)
end
end
end
end end
context 'when the current project has a remote mirror' do context 'when the current project has a remote mirror' do
...@@ -55,8 +39,6 @@ describe Projects::MirrorsController do ...@@ -55,8 +39,6 @@ describe Projects::MirrorsController do
context 'when trying to create a mirror with a different URL' do context 'when trying to create a mirror with a different URL' do
it 'should setup the mirror' do it 'should setup the mirror' do
expect_any_instance_of(EE::Project).to receive(:force_import_job!)
do_put(project, mirror: true, mirror_user_id: project.owner.id, import_url: 'http://local.dev') do_put(project, mirror: true, mirror_user_id: project.owner.id, import_url: 'http://local.dev')
expect(project.reload.mirror).to eq(true) expect(project.reload.mirror).to eq(true)
...@@ -65,8 +47,6 @@ describe Projects::MirrorsController do ...@@ -65,8 +47,6 @@ describe Projects::MirrorsController do
context 'mirror user is not the current user' do context 'mirror user is not the current user' do
it 'should only assign the current user' do it 'should only assign the current user' do
expect_any_instance_of(EE::Project).to receive(:force_import_job!)
new_user = create(:user) new_user = create(:user)
project.add_maintainer(new_user) project.add_maintainer(new_user)
...@@ -94,7 +74,6 @@ describe Projects::MirrorsController do ...@@ -94,7 +74,6 @@ describe Projects::MirrorsController do
it 'creates a new mirror' do it 'creates a new mirror' do
sign_in(admin) sign_in(admin)
expect_any_instance_of(EE::Project).to receive(:force_import_job!)
expect do expect do
do_put(project, mirror: true, mirror_user_id: admin.id, import_url: url) do_put(project, mirror: true, mirror_user_id: admin.id, import_url: url)
...@@ -120,8 +99,6 @@ describe Projects::MirrorsController do ...@@ -120,8 +99,6 @@ describe Projects::MirrorsController do
context 'when project does not have a mirror' do context 'when project does not have a mirror' do
it 'allows to create a mirror' do it 'allows to create a mirror' do
expect_any_instance_of(EE::Project).to receive(:force_import_job!)
expect do expect do
do_put(project, mirror: true, mirror_user_id: project.owner.id, import_url: url) do_put(project, mirror: true, mirror_user_id: project.owner.id, import_url: url)
end.to change { Project.mirror.count }.to(1) end.to change { Project.mirror.count }.to(1)
......
...@@ -144,8 +144,6 @@ describe ProjectsController do ...@@ -144,8 +144,6 @@ describe ProjectsController do
end end
it 'updates repository mirror attributes' do it 'updates repository mirror attributes' do
expect_any_instance_of(EE::Project).to receive(:force_import_job!)
put :update, put :update,
namespace_id: project.namespace, namespace_id: project.namespace,
id: project, id: project,
......
...@@ -31,6 +31,12 @@ describe Projects::UpdateService, '#execute' do ...@@ -31,6 +31,12 @@ describe Projects::UpdateService, '#execute' do
expect(updated_project.mirror_user_id).to eq(user.id) expect(updated_project.mirror_user_id).to eq(user.id)
expect(updated_project.mirror_trigger_builds).to be true expect(updated_project.mirror_trigger_builds).to be true
end end
it 'forces an import job' do
expect(project).to receive(:force_import_job!).once
update_project(project, user, opts)
end
end end
context 'when unlicensed' do context 'when unlicensed' do
...@@ -47,6 +53,12 @@ describe Projects::UpdateService, '#execute' do ...@@ -47,6 +53,12 @@ describe Projects::UpdateService, '#execute' do
expect(updated_project.mirror_user_id).to be_nil expect(updated_project.mirror_user_id).to be_nil
expect(updated_project.mirror_trigger_builds).to be false expect(updated_project.mirror_trigger_builds).to be false
end end
it 'does not force an import job' do
expect(project).not_to receive(:force_import_job!)
update_project(project, user, opts)
end
end end
end end
......
...@@ -140,7 +140,7 @@ module API ...@@ -140,7 +140,7 @@ module API
post do post do
attrs = declared_params(include_missing: false) attrs = declared_params(include_missing: false)
attrs = translate_params_for_compatibility(attrs) attrs = translate_params_for_compatibility(attrs)
attrs[:mirror_user_id] = current_user.id if attrs[:import_url].present? attrs[:mirror_user_id] = current_user.id if attrs[:mirror]
project = ::Projects::CreateService.new(current_user, attrs).execute project = ::Projects::CreateService.new(current_user, attrs).execute
...@@ -174,7 +174,7 @@ module API ...@@ -174,7 +174,7 @@ module API
attrs = declared_params(include_missing: false) attrs = declared_params(include_missing: false)
attrs = translate_params_for_compatibility(attrs) attrs = translate_params_for_compatibility(attrs)
attrs[:mirror_user_id] = user.id if attrs[:import_url].present? attrs[:mirror_user_id] = user.id if attrs[:mirror]
project = ::Projects::CreateService.new(user, attrs).execute project = ::Projects::CreateService.new(user, attrs).execute
......
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