From eea42b807fb226339a5f8ab7d0d38dc787adca51 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Thu, 29 Aug 2019 14:59:47 -0400 Subject: [PATCH] Update the button order on copy --- app/models/service_template/copy.rb | 8 +++++--- spec/models/service_template/copy_spec.rb | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/service_template/copy.rb b/app/models/service_template/copy.rb index 21ee8390ac8b..25d704ac892f 100644 --- a/app/models/service_template/copy.rb +++ b/app/models/service_template/copy.rb @@ -5,7 +5,7 @@ def template_copy(new_name = "Copy of " + name + Time.zone.now.to_s) if template_valid? && type != 'ServiceTemplateAnsiblePlaybook' ActiveRecord::Base.transaction do dup.tap do |template| - template.update_attributes(:name => new_name, :display => false) + template.update!(:name => new_name, :display => false, :options => {:button_order => []}) service_resources.each { |service_resource| resource_copy(service_resource, template) } resource_action_copy(template) additional_tenant_copy(template) @@ -26,11 +26,13 @@ def additional_tenant_copy(template) end def custom_button_copy(custom_button, template) - custom_button.copy(:applies_to => template) + new_cb = custom_button.copy(:applies_to => template) + template[:options][:button_order] << ["cb-#{new_cb.id}"] end def custom_button_set_copy(custom_button_set, template) - custom_button_set.deep_copy(:owner => template) + new_cbs = custom_button_set.deep_copy(:owner => template) + template[:options][:button_order] << ["cbs-#{new_cbs.id}"] end def picture_copy(template) diff --git a/spec/models/service_template/copy_spec.rb b/spec/models/service_template/copy_spec.rb index 6c646675d178..045990093fc9 100644 --- a/spec/models/service_template/copy_spec.rb +++ b/spec/models/service_template/copy_spec.rb @@ -42,6 +42,7 @@ def copy_template(template, name = nil) end it "with custom button set" do + service_template.update!(:options => {:button_order => ["cbs-#{custom_button_set.id}"]}) custom_button_set.add_member(custom_button) expect(service_template.custom_button_sets.count).to eq(1) expect(service_template.custom_button_sets.first.custom_buttons.count).to eq(1) @@ -51,6 +52,7 @@ def copy_template(template, name = nil) expect(new_service_template.custom_button_sets.count).to eq(1) expect(new_service_template.custom_button_sets.first.set_data).not_to eq(set_data) expect(new_service_template.custom_button_sets.first.custom_buttons.count).to eq(1) + expect(new_service_template[:options][:button_order]).not_to eq(["cbs-#{custom_button_set.id}"]) expect(new_service_template.custom_button_sets.first.children).not_to eq([custom_button]) expect(new_service_template.custom_button_sets.first.children).to eq(new_service_template.custom_button_sets.first.custom_buttons) end