Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/services/namespaces/projects/assign_runtimes_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def execute
end

namespace_project.runtimes = runtimes
namespace_project.primary_runtime = runtimes.first if runtimes.size == 1

unless namespace_project.save
t.rollback_and_return! ServiceResponse.error(
message: 'Failed to assign runtimes to project',
Expand Down
9 changes: 7 additions & 2 deletions app/services/namespaces/projects/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ def execute
params[:primary_runtime_id] = params.delete(:primary_runtime)&.id if params.key?(:primary_runtime)

transactional do |t|
success = namespace_project.update(params)
unless success
namespace_project.assign_attributes(params)

if namespace_project.primary_runtime_changed?
UpdateRuntimeCompatibilityJob.perform_later({ namespace_project_id: namespace_project.id })
end

unless namespace_project.save
t.rollback_and_return! ServiceResponse.error(
message: 'Failed to update namespace project',
error_code: :invalid_namespace_project,
Expand Down
42 changes: 40 additions & 2 deletions spec/services/namespaces/projects/assign_runtimes_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,27 @@
target_type: 'NamespaceProject'
)
end

it 'queues job to update runtimes' do
allow(UpdateRuntimeCompatibilityJob).to receive(:perform_later)

service_response

expect(UpdateRuntimeCompatibilityJob).to have_received(:perform_later).with(
{ namespace_project_id: project.id }
)
end

it { expect { service_response }.to change { project.reload.primary_runtime }.to(runtimes.first) }

context 'when adding multiple runtimes' do
let(:runtimes) { 2.times.map { create(:runtime, namespace: project.namespace) } }

it { expect { service_response }.not_to change { project.reload.primary_runtime } }
end
end

context 'when removing a project' do
context 'when removing a runtime' do
let(:runtime) { create(:runtime, namespace: project.namespace) }
let!(:namespace_project_runtime_assignment) do
create(:namespace_project_runtime_assignment, namespace_project: project, runtime: runtime)
Expand Down Expand Up @@ -88,9 +106,19 @@
target_type: 'NamespaceProject'
)
end

it 'queues job to update runtimes' do
allow(UpdateRuntimeCompatibilityJob).to receive(:perform_later)

service_response

expect(UpdateRuntimeCompatibilityJob).to have_received(:perform_later).with(
{ namespace_project_id: project.id }
)
end
end

context 'when adding and removing a project' do
context 'when adding and removing a runtime' do
let(:runtime) { create(:runtime, namespace: project.namespace) }
let!(:namespace_project_runtime_assignment) do
create(:namespace_project_runtime_assignment, namespace_project: project, runtime: runtime)
Expand Down Expand Up @@ -119,6 +147,16 @@
target_type: 'NamespaceProject'
)
end

it 'queues job to update runtimes' do
allow(UpdateRuntimeCompatibilityJob).to receive(:perform_later)

service_response

expect(UpdateRuntimeCompatibilityJob).to have_received(:perform_later).with(
{ namespace_project_id: project.id }
)
end
end
end
end
22 changes: 22 additions & 0 deletions spec/services/namespaces/projects/update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,27 @@
target_type: 'NamespaceProject'
)
end

it 'queues job to update runtimes' do
allow(UpdateRuntimeCompatibilityJob).to receive(:perform_later)

service_response

expect(UpdateRuntimeCompatibilityJob).to have_received(:perform_later).with(
{ namespace_project_id: namespace_project.id }
)
end

context 'without changing the primary runtime' do
let(:params) { { name: namespace_project_name } }

it 'does not queue job to update runtimes' do
allow(UpdateRuntimeCompatibilityJob).to receive(:perform_later)

service_response

expect(UpdateRuntimeCompatibilityJob).not_to have_received(:perform_later)
end
end
end
end