Skip to content

Commit

Permalink
Merge pull request #19169 from d-m-u/fixing_custom_button_set_copy_ch…
Browse files Browse the repository at this point in the history
…ildren

Fix the custom button set set_data hash links to the original buttons on copy

(cherry picked from commit 68f281d)

https://bugzilla.redhat.com/show_bug.cgi?id=1745198
  • Loading branch information
bdunne authored and simaishi committed Sep 5, 2019
1 parent c30fdb0 commit 103f880
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/models/custom_button_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion spec/models/custom_button_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 103f880

Please sign in to comment.