On Thu, May 06, 2010 at 03:26:03PM -0400, Mohammed Morsi wrote:
> ---
>  .../controllers/cloud_accounts_controller_spec.rb  |   51 
> ++++++++++++++++++++
>  src/spec/factories/cloud_account.rb                |    8 +++-
>  src/spec/factories/provider.rb                     |    2 +-
>  src/spec/models/cloud_account_spec.rb              |   21 ++++++++
>  4 files changed, 80 insertions(+), 2 deletions(-)
>  create mode 100644 src/spec/controllers/cloud_accounts_controller_spec.rb
>  create mode 100644 src/spec/models/cloud_account_spec.rb
> 
> diff --git a/src/spec/controllers/cloud_accounts_controller_spec.rb 
> b/src/spec/controllers/cloud_accounts_controller_spec.rb
> new file mode 100644
> index 0000000..f1d4a0d
> --- /dev/null
> +++ b/src/spec/controllers/cloud_accounts_controller_spec.rb
> @@ -0,0 +1,51 @@
> +require 'spec_helper'
> +
> +describe CloudAccountsController do
> +
> +  fixtures :all
> +  before(:each) do
> +    @cloud_account = Factory :mock_cloud_account
> +    @provider = @cloud_account.provider
> +
> +    @admin_permission = Permission.create :role => Role.find(:first, 
> :conditions => ['name = ?', 'Provider Administrator']),
> +                                          :permission_object => @provider,
> +                                          :user => 
> Factory(:provider_admin_user)
> +    @admin = @admin_permission.user
> +    activate_authlogic
> +  end
> +
> +  it "should permit users with account modify permission to access edit 
> cloud account interface" do
> +    UserSession.create(@admin)
> +    get :edit, :id => @cloud_account.id
> +    response.should be_success
> +    response.should render_template("edit")
> +  end
> +
> +  it "should allow users with account modify permission to update a cloud 
> account" do
> +    UserSession.create(@admin)
> +    post :update, :cloud_account => { :id => @cloud_account.id, :password => 
> 'foobar' }
> +    response.should 
> redirect_to("http://test.host/provider/accounts/#[email protected]}";)
> +    CloudAccount.find(@cloud_account.id).password.should == "foobar"
> +  end
> +
> +  it "should allow users with account modify permission to delete a cloud 
> account" do
> +    UserSession.create(@admin)
> +    lambda do
> +      post :destroy, :id => @cloud_account.id
> +    end.should change(CloudAccount, :count).by(-1)
> +    response.should 
> redirect_to("http://test.host/provider/accounts/#[email protected]}";)
> +    CloudAccount.find(:first, :conditions => ['id = ?', 
> @cloud_account.id]).should be_nil
> +  end
> +
> +  it "should deny access to users without account modify permission" do
> +    get :edit, :id => @cloud_account.id
> +    response.should_not be_success
> +
> +    post :update, :id => @cloud_account.id, :cloud_account => { :password => 
> 'foobar' }
> +    response.should_not be_success
> +
> +    post :destroy, :id => @cloud_account.id
> +    response.should_not be_success
> +  end
> +
> +end
> diff --git a/src/spec/factories/cloud_account.rb 
> b/src/spec/factories/cloud_account.rb
> index b1e4cc4..f494b52 100644
> --- a/src/spec/factories/cloud_account.rb
> +++ b/src/spec/factories/cloud_account.rb
> @@ -2,4 +2,10 @@ Factory.define :cloud_account do |f|
>    f.sequence(:username) { |n| "testUser#(n)" }
>    f.password "testPassword"
>    f.association :provider
> -end
> \ No newline at end of file
> +end
> +
> +Factory.define :mock_cloud_account, :parent => :cloud_account do |f|
> +  f.sequence(:username) { |n| "testMockUser#(n)" }
> +  f.password "testMockPassword"
> +  f.provider { |p| p.association(:mock_provider) }
> +end
> diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb
> index 1d3e3b7..d53fc67 100644
> --- a/src/spec/factories/provider.rb
> +++ b/src/spec/factories/provider.rb
> @@ -16,4 +16,4 @@ Factory.define :mock_provider2, :parent => :provider do |p|
>    p.cloud_type 'mock'
>    p.url 'http://localhost:3001/api'
>    p.after_create { |p| p.realms << Factory(:realm3, :provider => p) }
> -end
> \ No newline at end of file
> +end
> diff --git a/src/spec/models/cloud_account_spec.rb 
> b/src/spec/models/cloud_account_spec.rb
> new file mode 100644
> index 0000000..0afe5a3
> --- /dev/null
> +++ b/src/spec/models/cloud_account_spec.rb
> @@ -0,0 +1,21 @@
> +require 'spec_helper'
> +
> +describe CloudAccount do
> +  fixtures :all
> +  before(:each) do
> +    @cloud_account = Factory :mock_cloud_account
> +  end
> +
> +  it "should not be destroyable if it has instances" do
> +    @cloud_account.instances << Instance.new
> +    @cloud_account.destroyable?.should_not be_true
> +    @cloud_account.destroy
> +    CloudAccount.find(@cloud_account.id).should_not be_nil
> +
> +
> +    @cloud_account.instances.clear
> +    @cloud_account.destroyable?.should be_true
> +    @cloud_account.destroy
> +    CloudAccount.find(:first, :conditions => ['id = ?', 
> @cloud_account.id]).should be_nil
> +  end
> +end
> -- 
> 1.6.2.5
> 
> _______________________________________________
> deltacloud-devel mailing list
> [email protected]
> https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Applied & works for me. Thank you!

ACK.

s
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to