From 61df58fcf8add9f3c7a93160d9114fa1058049c8 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Wed, 3 Jan 2018 16:26:58 -0500 Subject: [PATCH] Adds tests for unique_within_region per https://github.com/ManageIQ/manageiq/issues/16739 --- spec/models/customization_template_spec.rb | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/models/customization_template_spec.rb diff --git a/spec/models/customization_template_spec.rb b/spec/models/customization_template_spec.rb new file mode 100644 index 000000000000..2caee8292333 --- /dev/null +++ b/spec/models/customization_template_spec.rb @@ -0,0 +1,43 @@ +describe CustomizationTemplate do + context "#name" do + context "two pxe templates" do + it "raises error with non-unique names" do + expect { FactoryGirl.create(:customization_template, :name => "template") }.to_not raise_error + expect { FactoryGirl.create(:customization_template, :name => "template") } + .to raise_error(ActiveRecord::RecordInvalid, /Name has already been taken/) + end + + it "doesn't raise error with unique names" do + expect { FactoryGirl.create(:customization_template, :name => "template") }.to_not raise_error + expect { FactoryGirl.create(:customization_template, :name => "something else", :pxe_image_type => PxeImageType.new(:name => "image1")) }.to_not raise_error + end + end + + context "pxe template and a non pxe template" do + it "raises error with non-unique names" do + expect { FactoryGirl.create(:customization_template_cloud_init, :name => "template") }.to_not raise_error + expect { FactoryGirl.create(:customization_template, :name => "template", :system => true, :pxe_image_type => nil) } + .to raise_error(ActiveRecord::RecordInvalid, /Name has already been taken/) + end + + it "doesn't raise error with unique names" do + expect { FactoryGirl.create(:customization_template_cloud_init, :name => "template4", :system => true, :pxe_image_type => nil) }.to_not raise_error + expect { FactoryGirl.create(:customization_template, :name => "something else", :pxe_image_type => PxeImageType.new(:name => "image1")) } + .to_not raise_error + end + end + + context "two non pxe templates" do + it "raises error with non-unique names" do + expect { FactoryGirl.create(:customization_template_cloud_init, :name => "template", :system => true) }.to_not raise_error + expect { FactoryGirl.create(:customization_template_cloud_init, :name => :name => "template", :system => true) } + .to raise_error(ActiveRecord::RecordInvalid, /Name has already been taken/) + end + + it "doesn't raise error with unique names" do + expect { FactoryGirl.create(:customization_template_cloud_init, :name => "template6", :system => true, :pxe_image_type => PxeImageType.new(:name => "image1")) }.to_not raise_error + expect { FactoryGirl.create(:customization_template_cloud_init, :name => "other", :system => true, :pxe_image_type => PxeImageType.new(:name => "image2")) }.to_not raise_error + end + end + end +end