From 0ecc0bf198643bfeca561d6d0232555bfb01884d Mon Sep 17 00:00:00 2001 From: d-m-u Date: Tue, 16 Jul 2019 18:42:20 -0400 Subject: [PATCH] Add additional_tenant info to copy --- app/models/service_template/copy.rb | 5 ++++- spec/models/service_template/copy_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/service_template/copy.rb b/app/models/service_template/copy.rb index daac94856323..42e7361b15a1 100644 --- a/app/models/service_template/copy.rb +++ b/app/models/service_template/copy.rb @@ -22,7 +22,10 @@ def template_copy(new_name = "Copy of " + name + Time.zone.now.to_s) private def additional_tenant_copy(template) - template.class.with_additional_tenants.deep_clone + template.additional_tenants << additional_tenants.each do |tenant| + tenant.name = "Copy of " + tenant.name + Time.zone.now.to_s + tenant.subdomain = "Copy of " + tenant.subdomain + Time.zone.now.to_s + end end def custom_button_copy(custom_button, template) diff --git a/spec/models/service_template/copy_spec.rb b/spec/models/service_template/copy_spec.rb index 54cfd8ccff48..d8a6e5261938 100644 --- a/spec/models/service_template/copy_spec.rb +++ b/spec/models/service_template/copy_spec.rb @@ -261,5 +261,17 @@ expect(new_template.resource_actions.pluck(:action)).to match_array(%w[Provision Retire]) end end + + context "additional tenants" do + it "duplicates additional tenants" do + @st1.additional_tenants << [ + FactoryBot.create(:tenant), + FactoryBot.create(:tenant) + ] + expect(@st1.additional_tenants.count).to eq(2) + new_template = @st1.template_copy + expect(new_template.additional_tenants.count).to eq(2) + end + end end end