On Tue, Jan 31, 2012 at 02:41:17PM +0000, mtaylor(a)redhat.com wrote:
From: Martyn Taylor <mtaylor(a)redhat.com>
---
.../controllers/provider_accounts_controller.rb | 1 +
src/app/models/provider_account.rb | 5 +++++
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/app/controllers/provider_accounts_controller.rb
b/src/app/controllers/provider_accounts_controller.rb
index 9b5517d..b78ee52 100644
--- a/src/app/controllers/provider_accounts_controller.rb
+++ b/src/app/controllers/provider_accounts_controller.rb
@@ -79,6 +79,7 @@ class ProviderAccountsController < ApplicationController
params[:provider_account][:provider_id] = @provider.id
@providers = Provider.all
@provider_account = ProviderAccount.new(params[:provider_account])
+ @provider_account.credentials_hash = params[:provider_account][:credentials_hash]
@provider_account.quota = @quota = Quota.new
limit = params[:quota][:maximum_running_instances] if params[:quota]
@provider_account.quota.set_maximum_running_instances(limit)
diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb
index e772f52..ce4fb81 100644
--- a/src/app/models/provider_account.rb
+++ b/src/app/models/provider_account.rb
@@ -74,6 +74,11 @@ class ProviderAccount < ActiveRecord::Base
scope :enabled, lambda { where(:provider_id => Provider.enabled) }
+ # We set credentials hash as protected so that it is not set during mass assign on
new
+ # This is to avoid the scenario where the credentials are set before provider which
+ # will result in an exception.
+ attr_protected :credentials_hash
+
def validate_presence_of_credentials
provider.provider_type.credential_definitions.each do |cd|
errors.add(:base, "#{cd.label} can't be blank") if
credentials_hash[cd.name].blank?
--
Conditional ACK. I get two failing rspec tests with this. If you can get
the tests passing, go ahead and push, because this is an actual problem
I've run into in the past and your fix looks ideal.
Failures:
1) ProviderAccountsController doesn't allow to save provider's account
if not valid credentials
Failure/Error: response.should render_template("new")
expecting <"new"> but rendering with
<"layouts/application,
layouts/error">
# ./spec/controllers/provider_accounts_controller_spec.rb:47
2) ProviderAccountsController should allow users with account modify
password to update a cloud account
Failure/Error: response.should redirect_to
edit_provider_path((a)provider_account.provider_id, :details_tab =>
'accounts')
Expected response to be a <:redirect>, but was <200>
# ./spec/controllers/provider_accounts_controller_spec.rb:65
Finished in 412.16 seconds
670 examples, 2 failures
Failed examples:
rspec ./spec/controllers/provider_accounts_controller_spec.rb:43 #
ProviderAccountsController doesn't allow to save provider's account if
not valid credentials
rspec ./spec/controllers/provider_accounts_controller_spec.rb:58 #
ProviderAccountsController should allow users with account modify
password to update a cloud account