diff --git a/spec/models/customization_template_spec.rb b/spec/models/customization_template_spec.rb index ee8bca85a25..ae00006c515 100644 --- a/spec/models/customization_template_spec.rb +++ b/spec/models/customization_template_spec.rb @@ -1,42 +1,40 @@ describe CustomizationTemplate do context "#name" do + before do + FactoryGirl.create(:customization_template, :name => "template") + FactoryGirl.create(:customization_template_cloud_init, :name => "template1") + end + 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/) + expect { FactoryGirl.create(:customization_template, :name => "template") } + .to raise_error(ActiveRecord::RecordInvalid, / Name is not unique within region/) 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 + expect { FactoryGirl.create(:customization_template) }.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/) + expect { FactoryGirl.create(:customization_template, :name => "template1") } + .to raise_error(ActiveRecord::RecordInvalid, / Name is not unique within region/) 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 + expect { FactoryGirl.create(:customization_template) }.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/) + expect { FactoryGirl.create(:customization_template_sysprep, :name => "template1") } + .to raise_error(ActiveRecord::RecordInvalid, / Name is not unique within region/) 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 + expect { FactoryGirl.create(:customization_template_sysprep) }.to_not raise_error end end end