spec/requests/template_request_spec.rb in rubix-0.0.8 vs spec/requests/template_request_spec.rb in rubix-0.0.9

- old
+ new

@@ -1,52 +1,52 @@ require 'spec_helper' -describe "CRUD for templates" do +describe "Templates" do before do - @hg1 = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1') - ensure_save(@hg1) - - @hg2 = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_2') - ensure_save(@hg2) + integration_test + @host_group_1 = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1')) + @host_group_2 = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_2')) end after do - ensure_destroy(@hg1, @hg2) + truncate_all_tables end - it "should be able to create, update, and destroy a template" do - integration_test + describe "when not existing" do + + it "returns nil on find" do + Rubix::Template.find(:name => 'rubix_spec_template_1').should be_nil + end + + it "can be created" do + template = Rubix::Template.new(:name => 'rubix_spec_template_1', :host_groups => [@host_group_1]) + template.save.should be_true + end - Rubix::Template.find(:name => 'rubix_spec_template_1').should be_nil - - t1 = Rubix::Template.new(:name => 'rubix_spec_template_1', :host_groups => [@hg1]) - t1.save.should be_true - id = t1.id - id.should_not be_nil + end - ensure_destroy(t1) do - t2 = Rubix::Template.find(:name => 'rubix_spec_template_1') - t2.should_not be_nil - t2.id.should == id - t2.host_group_ids.should include(@hg1.id) - - t1.name = 'rubix_spec_template_2' - t1.host_groups = [@hg2] - t1.save.should be_true + describe "when existing" do - t2 = Rubix::Template.find(:id => id) - t2.name.should == 'rubix_spec_template_2' - t2.host_group_ids.should_not include(@hg1.id) - t2.host_group_ids.should include(@hg2.id) - - t1.destroy - Rubix::Template.find(:id => id).should be_nil + before do + @template = ensure_save(Rubix::Template.new(:name => 'rubix_spec_template_1', :host_groups => [@host_group_1])) end + + it "can have its name changed" do + @template.name = 'rubix_spec_template_2' + @template.save + Rubix::Template.find(:name => 'rubix_spec_template_1').should be_nil + Rubix::Template.find(:name => 'rubix_spec_template_2').should_not be_nil + end + + it "can be destroyed" do + @template.destroy + Rubix::Template.find(:name => 'rubix_spec_template_1').should be_nil + end + end it "should be able to import and export a template" do - integration_test pending "Learning how to import/export XML via the API" end end