Skip to content

Commit

Permalink
Update the button order on copy
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Aug 29, 2019
1 parent 4c54666 commit eea42b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/models/service_template/copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions spec/models/service_template/copy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit eea42b8

Please sign in to comment.