Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When copying ServiceTemplate copy only direct_custom_buttons #18960

Merged
merged 1 commit into from
Jul 11, 2019

Conversation

ZitaNemeckova
Copy link
Contributor

Fixes #18954

Based on #18494 (comment)

Steps to reproduce:

st = ServiceTemplate.create(:name => "ServiceTemplate")
cb = CustomButton.create(:name => "CustomButton", :applies_to => st)
service = Service.create(:name => "Service", :service_template_id => st.id)
service.save!
service_cb = CustomButton.create(:name => "CustomButton", :applies_to => service)
st.template_copy("Copy")
copy = ServiceTemplate.find_by(:name => "Copy")
copy_of_copy = copy.template_copy

Before:

       16: from app/models/service_template/copy.rb:10:in `block (2 levels) in template_copy'
       15: from app/models/service_template/copy.rb:10:in `each'
       14: from app/models/service_template/copy.rb:10:in `block (3 levels) in template_copy'
       13: from app/models/service_template/copy.rb:23:in `custom_button_copy'
       12: from app/models/custom_button.rb:233:in `copy'
       11: from app/models/custom_button.rb:233:in `tap'
       10: from activerecord (5.1.7) lib/active_record/suppressor.rb:46:in `save!'
        9: from activerecord (5.1.7) lib/active_record/transactions.rb:313:in `save!'
        8: from activerecord (5.1.7) lib/active_record/transactions.rb:381:in `with_transaction_returning_status'
        7: from activerecord (5.1.7) lib/active_record/transactions.rb:210:in `transaction'
        6: from activerecord (5.1.7) lib/active_record/connection_adapters/abstract/database_statements.rb:233:in `transaction'
        5: from activerecord (5.1.7) lib/active_record/transactions.rb:384:in `block in with_transaction_returning_status'
        4: from activerecord (5.1.7) lib/active_record/transactions.rb:313:in `block in save!'
        3: from activerecord (5.1.7) lib/active_record/attribute_methods/dirty.rb:43:in `save!'
        2: from activerecord (5.1.7) lib/active_record/validations.rb:50:in `save!'
        1: from activerecord (5.1.7) lib/active_record/validations.rb:78:in `raise_validation_error'
ActiveRecord::RecordInvalid (Validation failed: CustomButton: Name has already been taken, CustomButton: Description has already been taken)

After:
It works and copy_of_copy is created :)

@gmcculloug Please have look, thanks :)

cc @d-m-u

@d-m-u
Copy link
Contributor

d-m-u commented Jul 11, 2019

Can you put a test in for copy of copy, as well, please?

@@ -7,7 +7,7 @@ def template_copy(new_name = "Copy of " + name + Time.zone.now.to_s)
dup.tap do |template|
template.update_attributes(:name => new_name, :display => false)
service_resources.each { |service_resource| resource_copy(service_resource, template) }
custom_buttons.each { |custom_button| custom_button_copy(custom_button, template) }
direct_custom_buttons.each { |custom_button| custom_button_copy(custom_button, template) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good. Thanks @ZitaNemeckova and @himdel

@ZitaNemeckova
Copy link
Contributor Author

@d-m-u Added :)

Copy link
Contributor

@d-m-u d-m-u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@miq-bot
Copy link
Member

miq-bot commented Jul 11, 2019

Checked commit ZitaNemeckova@bb47290 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@gmcculloug gmcculloug merged commit 36ce57a into ManageIQ:master Jul 11, 2019
@gmcculloug gmcculloug added this to the Sprint 116 Ending Jul 22, 2019 milestone Jul 11, 2019
@ZitaNemeckova ZitaNemeckova deleted the use_direct_cb branch July 11, 2019 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ServiceTemplate copy_template duplicates buttons
4 participants