Commit 856a511b authored by James Lopez's avatar James Lopez

refactor code based on feedback

parent f15466bd
......@@ -11,7 +11,7 @@ module Projects
end
def propagate
return unless @template&.active?
return unless @template.active?
Rails.logger.info("Propagating services for template #{@template.id}")
......@@ -32,11 +32,11 @@ module Projects
def bulk_create_from_template(batch)
service_list = batch.map do |project_id|
service_hash.merge('project_id' => project_id).values
service_hash.values << project_id
end
Project.transaction do
bulk_insert_services(service_hash.keys + ['project_id'], service_list)
bulk_insert_services(service_hash.keys << 'project_id', service_list)
run_callbacks(batch)
end
end
......@@ -75,9 +75,9 @@ module Projects
template_hash.each_with_object({}) do |(key, value), service_hash|
value = value.is_a?(Hash) ? value.to_json : value
key = Gitlab::Database.postgresql? ? "\"#{key}\"" : "`#{key}`"
service_hash[key] = ActiveRecord::Base.sanitize(value)
service_hash[ActiveRecord::Base.connection.quote_column_name(key)] =
ActiveRecord::Base.sanitize(value)
end
end
end
......@@ -93,7 +93,7 @@ module Projects
end
def active_external_issue_tracker?
@template.category == :issue_tracker && !@template.default
@template.issue_tracker? && !@template.default
end
def active_external_wiki?
......
......@@ -3,8 +3,6 @@ class PropagateServiceTemplateWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
sidekiq_options retry: 3
LEASE_TIMEOUT = 4.hours.to_i
def perform(template_id)
......
......@@ -18,8 +18,11 @@ describe Projects::PropagateServiceTemplate, services: true do
let!(:project) { create(:empty_project) }
it 'creates services for projects' do
expect { described_class.propagate(service_template) }.
to change { Service.count }.by(1)
expect(project.pushover_service).to be_nil
described_class.propagate(service_template)
expect(project.reload.pushover_service).to be_present
end
it 'creates services for a project that has another service' do
......@@ -35,8 +38,11 @@ describe Projects::PropagateServiceTemplate, services: true do
}
)
expect { described_class.propagate(service_template) }.
to change { Service.count }.by(1)
expect(project.pushover_service).to be_nil
described_class.propagate(service_template)
expect(project.reload.pushover_service).to be_present
end
it 'does not create the service if it exists already' do
......@@ -61,9 +67,7 @@ describe Projects::PropagateServiceTemplate, services: true do
it 'creates the service containing the template attributes' do
described_class.propagate(service_template)
service = Service.find_by!(type: service_template.type, template: false)
expect(service.properties).to eq(service_template.properties)
expect(project.pushover_service.properties).to eq(service_template.properties)
end
describe 'bulk update' do
......
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