Skip to content

Commit

Permalink
Merge pull request #17677 from agrare/validate_name_is_unique_transfo…
Browse files Browse the repository at this point in the history
…rmation_plan

Validate name uniqueness for Transformation Plans
(cherry picked from commit 6586413)

https://bugzilla.redhat.com/show_bug.cgi?id=1608768
  • Loading branch information
gmcculloug authored and simaishi committed Jul 26, 2018
1 parent 9624ca3 commit 80edeaa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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 @@ -8,7 +8,9 @@
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 @@ -71,5 +71,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

0 comments on commit 80edeaa

Please sign in to comment.