From 103f8808b91b7276587f473f031fb42f8f202e89 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Tue, 20 Aug 2019 13:15:40 -0400 Subject: [PATCH] Merge pull request #19169 from d-m-u/fixing_custom_button_set_copy_children Fix the custom button set set_data hash links to the original buttons on copy (cherry picked from commit 68f281d47fe19f84f0aacff9e8d764d69e315416) https://bugzilla.redhat.com/show_bug.cgi?id=1745198 --- app/models/custom_button_set.rb | 8 +++++++- spec/models/custom_button_set_spec.rb | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/custom_button_set.rb b/app/models/custom_button_set.rb index f3b5e4a00ac..e848fbcb769 100644 --- a/app/models/custom_button_set.rb +++ b/app/models/custom_button_set.rb @@ -92,8 +92,14 @@ def deep_copy(options) options.each_with_object(dup) { |(k, v), button_set| button_set.send("#{k}=", v) }.tap do |cbs| cbs.guid = SecureRandom.uuid cbs.name = "#{name}-#{cbs.guid}" + cbs.set_data[:button_order] = [] cbs.save! - custom_buttons.each { |cb| cbs.add_member(cb.copy(:applies_to => options[:owner])) } + custom_buttons.each do |cb| + cb_copy = cb.copy(:applies_to => options[:owner]) + cbs.add_member(cb_copy) + cbs.set_data[:button_order] << cb_copy.id + cbs.save! + end end end diff --git a/spec/models/custom_button_set_spec.rb b/spec/models/custom_button_set_spec.rb index 3b4b93e9cd0..6ed7b441669 100644 --- a/spec/models/custom_button_set_spec.rb +++ b/spec/models/custom_button_set_spec.rb @@ -71,7 +71,8 @@ service_template1 = FactoryGirl.create(:service_template) service_template2 = FactoryGirl.create(:service_template) custom_button = FactoryGirl.create(:custom_button, :applies_to => service_template1) - custom_button_set = FactoryGirl.create(:custom_button_set) + set_data = {:applies_to_class => "ServiceTemplate", :button_order => [custom_button.id]} + custom_button_set = FactoryBot.create(:custom_button_set, :set_data => set_data) custom_button_set.add_member(custom_button) custom_button_set.deep_copy(:owner => service_template2)