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

- old
+ new

@@ -1,49 +1,47 @@ require 'spec_helper' -describe "CRUD for hosts" do +describe "Applications" do before do - @hg = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1') - ensure_save(@hg) - - @h1 = Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@hg]) - ensure_save(@h1) - - @h2 = Rubix::Host.new(:name => 'rubix_spec_host_2', :host_groups => [@hg]) - ensure_save(@h2) + integration_test + @host_group = ensure_save(Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1')) + @host = ensure_save(Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@host_group])) end after do - ensure_destroy(@h1, @h2, @hg) + truncate_all_tables end - - it "should be able to create, update, and destroy a host" do - integration_test - - Rubix::Application.find(:name => 'rubix_spec_app_1', :host_id => @h1.id).should be_nil - - app1 = Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @h1.id) - app1.save.should be_true - id = app1.id - id.should_not be_nil - - ensure_destroy(app1) do - - app2 = Rubix::Application.find(:name => 'rubix_spec_app_1', :host_id => @h1.id) - app2.should_not be_nil - app2.id.should == app1.id - app2.host_id.should == @h1.id - - app1.name = 'rubix_spec_app_2' - app1.save.should be_true - - app2 = Rubix::Application.find(:id => id, :name => 'rubix_spec_app_2', :host_id => @h1.id) - app2.should_not be_nil - app2.name.should == 'rubix_spec_app_2' - - app1.destroy.should be_true - Rubix::Application.find(:id => id, :host_id => @h1.id).should be_nil - Rubix::Application.find(:id => id, :host_id => @h2.id).should be_nil + + describe "when not existing" do + + it "returns nil on find" do + Rubix::Application.find(:name => 'rubix_spec_app_1', :host_id => @host.id).should be_nil end + + it "can be created" do + app = Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @host.id) + app.save.should be_true + end + + end + + describe "when existing" do + + before do + @app = ensure_save(Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @host.id)) + end + + it "can have its name changed" do + @app.name = 'rubix_spec_app_2' + @app.save + Rubix::Application.find(:name => 'rubix_spec_app_1', :host_id => @host.id).should be_nil + Rubix::Application.find(:name => 'rubix_spec_app_2', :host_id => @host.id).should_not be_nil + end + + it "can be destroyed" do + @app.destroy + Rubix::Application.find(:name => 'rubix_spec_app_1', :host_id => @host.id).should be_nil + end + end end