Skip to content

Commit

Permalink
Adds tests for unique_within_region per ManageIQ#16739
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jan 9, 2018
1 parent bb58882 commit 1941c57
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec/models/customization_template_spec.rb
Original file line number Diff line number Diff line change
@@ -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 => "foo") }.to_not raise_error
expect { FactoryGirl.create(:customization_template, :name => "foo") }
.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 => "foo") }.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 => "foo") }.to_not raise_error
expect { FactoryGirl.create(:customization_template, :name => "foo", :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 => "foo", :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 => "foo", :system => true) }.to_not raise_error
expect { FactoryGirl.create(:customization_template_cloud_init, :name => "foo", :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 => "foo", :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

0 comments on commit 1941c57

Please sign in to comment.