On 01/19/2012 05:51 PM, jzigmund(a)redhat.com wrote:
From: Jozef Zigmund<jzigmund(a)redhat.com>
---
src/features/deployables.feature | 13 +--
.../controllers/deployables_controller_spec.rb | 104 +++++++++++++++++---
2 files changed, 96 insertions(+), 21 deletions(-)
diff --git a/src/features/deployables.feature b/src/features/deployables.feature
index 64dbece..5663ffa 100644
--- a/src/features/deployables.feature
+++ b/src/features/deployables.feature
@@ -60,10 +60,9 @@ Feature: Manage Catalog Entries
When I check "testdepl1" catalog entry
And I check "testdepl2" catalog entry
And I press "delete_button"
- Then there should be only 0 catalog entries for "default" catalog
- And I should be on the "default" catalog page
- And I should not see "testdepl1"
- And I should not see "testdepl2"
+ Then I should be on the "default" catalog page
+ And there should be only 0 catalog entries for "default" catalog
+ And I should see "2 deployables testdepl1, testdepl2 were deleted!"
Scenario: Delete deployable
Given there is a "default" catalog
@@ -71,9 +70,9 @@ Feature: Manage Catalog Entries
And I am on the "default" catalog page
When I follow "testdepl1"
And I press "delete"
- Then there should be only 0 catalog entries for "default" catalog
- And I should be on the "default" catalog page
- And I should not see "testdepl1"
+ Then I should be on the "default" catalog page
+ And there should be only 0 catalog entries for "default" catalog
+ And I should see "Deployable testdepl1 delete successfully!"
#Scenario: Search Catalog Entries
# Given there is a "testcatalog" catalog
diff --git a/src/spec/controllers/deployables_controller_spec.rb
b/src/spec/controllers/deployables_controller_spec.rb
index 9861cc4..96ee69b 100644
--- a/src/spec/controllers/deployables_controller_spec.rb
+++ b/src/spec/controllers/deployables_controller_spec.rb
@@ -19,26 +19,102 @@ require 'spec_helper'
describe DeployablesController do
fixtures :all
- before(:each) do
+ before do
@admin_permission = FactoryGirl.create :admin_permission
@admin = @admin_permission.user
- @image = mock(Aeolus::Image::Warehouse::Image, :id =>
'3c58e0d6-d11a-4e68-8b12-233783e56d35', :name => 'image1', :uuid =>
'3c58e0d6-d11a-4e68-8b12-233783e56d35')
- Aeolus::Image::Warehouse::Image.stub(:find).and_return(@image)
+ mock_warden(@admin)
end
- it "should provide ui to create new catalog entry from image" do
- mock_warden(@admin)
- get :new, :create_from_image => @image.id
- response.should be_success
- response.should render_template("new")
+ describe "#create" do
+ before(:each) do
+ @image = mock(Aeolus::Image::Warehouse::Image, :id =>
'3c58e0d6-d11a-4e68-8b12-233783e56d35', :name => 'image1', :uuid =>
'3c58e0d6-d11a-4e68-8b12-233783e56d35')
+ Aeolus::Image::Warehouse::Image.stub(:find).and_return(@image)
+ end
+
+ it "creates new deployable from image via UI" do
+ get :new, :create_from_image => @image.id
+ response.should be_success
+ response.should render_template("new")
+ end
+
+ it "creates new deployable from image via POST" do
+ hw_profile = FactoryGirl.create(:front_hwp1)
+ catalog = FactoryGirl.create(:catalog)
+ post(:create, :create_from_image => @image.id, :deployable => {:name =>
@image.name}, :hardware_profile => hw_profile.id, :catalog_id => catalog.id)
+ response.should redirect_to(catalog_url(catalog.id))
+ end
end
- it "should create new catalog entry from image" do
- hw_profile = FactoryGirl.create(:front_hwp1)
- catalog = FactoryGirl.create(:catalog)
- mock_warden(@admin)
- post(:create, :create_from_image => @image.id, :deployable => {:name =>
@image.name}, :hardware_profile => hw_profile.id, :catalog_id => catalog.id)
- response.should redirect_to(catalog_url(catalog.id))
+ describe "#destroy" do
+ before do
+ @deployable = stub_model(Deployable, :name => "test_delete", :id
=> 1)
+ Deployable.stub(:find).and_return(@deployable)
+ end
+
+
+ context "deletion successfully" do
+ before do
+ Deployable.any_instance.stub(:destroy).and_return(true)
+ end
+
+ it "deletes a deployable and redirect to deployables#index" do
+ delete :destroy, :id => @deployable.id
+ response.should redirect_to deployables_path
+ end
+
+ it "deletes a deployable and appears flash notice" do
+ delete :destroy, :id => @deployable.id
+ flash[:notice].should eql("Deployable test_delete delete
successfully!")
+ end
+ end
+
+ context "deletion fails" do
+ before do
+ Deployable.any_instance.stub(:destroy).and_return(false)
+ end
+
+ it "not delete a deployable and redirect to deployables#show" do
+ delete :destroy, :id => @deployable.id
+ response.should redirect_to deployables_path
+ end
+
+ it "not delete a deployable and shows flash error" do
+ delete :destroy, :id => @deployable.id
+ flash[:error].should eql("Deployable test_delete delete failed!")
+ end
+ end
+ end
+
+ describe "#multi_destroy" do
+ it "redirects to deployables#index" do
+ delete :multi_destroy
+ response.should redirect_to deployables_path
+ end
+
+ context "with params[:deployables_selected]" do
+ before do
+ @deployable1 = Factory :deployable, :name => "test_delete"
+ @deployable2 = Factory :deployable, :name => "test_delete2"
+ end
+
+ it "deletes both deployables and shows flash notice" do
+ delete :multi_destroy, :deployables_selected => [@deployable1.id,
@deployable2.id]
+ flash[:notice].should eql("2 deployables #{(a)deployable1.name},
#{(a)deployable2.name} were deleted!")
+ end
+
+ it "not delete deployable1 but not deployable2 and shows flash notice and
error" do
+ Deployable.any_instance.stub(:destroy).and_return(false)
+ delete :multi_destroy, :deployables_selected => [@deployable1.id,
@deployable2.id]
+ flash[:error].should eql("2 deployables #{(a)deployable1.name},
#{(a)deployable2.name} were not deleted!")
+ end
+ end
+
+ context "without params[:deployables_selected]" do
+ it "not delete a deployable and shows flash error" do
+ delete :multi_destroy
+ flash[:error].should eql("Any deployable was not selected!")
I
think here should be something like "No deployable was not selected!"
+ end
+ end
end
end
Ack to patch set. Nicely done with the tests! Thanks for that. One nit
inline.