Skip to content

Commit

Permalink
Merge pull request #18990 from d-m-u/adding_tenant_stuff_to_service_t…
Browse files Browse the repository at this point in the history
…emplate_copy

Adding tenant stuff to service template copy
  • Loading branch information
h-kataria authored Jul 17, 2019
2 parents c9a6d97 + d025294 commit 1e01a97
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
19 changes: 12 additions & 7 deletions app/models/service_template/copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def template_copy(new_name = "Copy of " + name + Time.zone.now.to_s)
template.update_attributes(:name => new_name, :display => false)
service_resources.each { |service_resource| resource_copy(service_resource, template) }
resource_action_copy(template)
additional_tenant_copy(template)
picture_copy(template) if picture

direct_custom_buttons.each { |custom_button| custom_button_copy(custom_button, template) }
Expand All @@ -20,9 +21,8 @@ def template_copy(new_name = "Copy of " + name + Time.zone.now.to_s)

private

def resource_copy(service_resource, template)
resource = service_resource.resource.respond_to?(:service_template_resource_copy) ? service_resource.resource.service_template_resource_copy : service_resource.resource
template.add_resource(resource, service_resource)
def additional_tenant_copy(template)
template.additional_tenants << additional_tenants.dup
end

def custom_button_copy(custom_button, template)
Expand All @@ -33,11 +33,16 @@ def custom_button_set_copy(custom_button_set, template)
custom_button_set.deep_copy(:owner => template)
end

def resource_action_copy(template)
template.resource_actions << resource_actions.collect(&:dup)
end

def picture_copy(template)
template.picture = picture.dup
end

def resource_copy(service_resource, template)
resource = service_resource.resource.respond_to?(:service_template_resource_copy) ? service_resource.resource.service_template_resource_copy : service_resource.resource
template.add_resource(resource, service_resource)
end

def resource_action_copy(template)
template.resource_actions << resource_actions.collect(&:dup)
end
end
24 changes: 18 additions & 6 deletions spec/models/service_template/copy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
expect(MiqProvisionRequestTemplate.count).to eq(2)
expect(new_service_template.guid).not_to eq(@st1.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(@st1.service_resources.first.resource).not_to be(nil)
end

Expand Down Expand Up @@ -143,7 +143,7 @@
expect(MiqProvisionRequestTemplate.count).to eq(2)
expect(new_service_template.guid).not_to eq(service_template_ansible_tower.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(service_template_ansible_tower.service_resources.first.resource).not_to be(nil)
end

Expand All @@ -159,7 +159,7 @@
expect(MiqProvisionRequestTemplate.count).to eq(2)
expect(new_service_template.guid).not_to eq(service_template_orchestration.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(service_template_orchestration.service_resources.first.resource).not_to be(nil)
end
end
Expand Down Expand Up @@ -198,7 +198,7 @@
expect(ExtManagementSystem.count).to eq(1)
expect(new_service_template.guid).not_to eq(@st1.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(@st1.service_resources.first.resource).not_to be(nil)
end

Expand All @@ -212,7 +212,7 @@
expect(OrchestrationTemplate.count).to eq(1)
expect(new_service_template.guid).not_to eq(@st1.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(@st1.service_resources.first.resource).not_to be(nil)
end

Expand All @@ -228,7 +228,7 @@
expect(MiqProvisionRequestTemplate.count).to eq(2)
expect(new_service_template.guid).not_to eq(@st1.guid)
expect(new_service_template.display).to be(false)
expect(new_service_template.service_resources).not_to be(nil)
expect(new_service_template.service_resources.count).not_to be(0)
expect(@st1.service_resources.first.resource).not_to be(nil)
end
end
Expand Down Expand Up @@ -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, :subdomain => nil)
]
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

0 comments on commit 1e01a97

Please sign in to comment.