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

Validate name uniqueness for Transformation Plans #17677

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/service_template_transformation_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def self.default_reconfiguration_entry_point
nil
end

validates :name, :presence => true, :uniqueness => {:scope => [:tenant_id]}

# create ServiceTemplate and supporting ServiceResources and ResourceActions
# options
# :name
Expand Down
4 changes: 3 additions & 1 deletion spec/factories/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
factory :service_template_orchestration, :class => 'ServiceTemplateOrchestration', :parent => :service_template
factory :service_template_ansible_playbook, :class => 'ServiceTemplateAnsiblePlaybook', :parent => :service_template
factory :service_template_container_template, :class => 'ServiceTemplateContainerTemplate', :parent => :service_template
factory :service_template_transformation_plan, :class => 'ServiceTemplateTransformationPlan', :parent => :service_template
factory :service_template_transformation_plan, :class => 'ServiceTemplateTransformationPlan', :parent => :service_template do
sequence(:name) { |n| "service_template_#{seq_padded_for_sorting(n)}" }
end

trait :with_provision_resource_action_and_dialog do
after(:create) do |x|
Expand Down
7 changes: 7 additions & 0 deletions spec/models/service_template_transformation_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,12 @@
described_class.create_catalog_item(catalog_item_options)
end.to raise_error(StandardError, 'Must select a list of valid vms')
end

it 'validates unique name' do
described_class.create_catalog_item(catalog_item_options)
expect { described_class.create_catalog_item(catalog_item_options) }.to raise_error(
ActiveRecord::RecordInvalid, 'Validation failed: Name has already been taken'
)
end
end
end