On 04/13/2011 02:29 PM, jtomasek(a)redhat.com wrote:
From: Jiri Tomasek<jtomasek(a)redhat.com>
---
src/app/controllers/resources/pools_controller.rb | 18 +++++++++---
src/app/models/pool.rb | 2 +-
src/app/views/resources/pools/edit.haml | 29 +++++++++++++++++---
src/app/views/resources/pools/new.haml | 27 ++++++++++++++-----
src/features/pool.feature | 6 ++++
src/spec/controllers/pools_controller_spec.rb | 6 +++-
6 files changed, 68 insertions(+), 20 deletions(-)
diff --git a/src/app/controllers/resources/pools_controller.rb
b/src/app/controllers/resources/pools_controller.rb
index 337a1b8..cd4840a 100644
--- a/src/app/controllers/resources/pools_controller.rb
+++ b/src/app/controllers/resources/pools_controller.rb
@@ -36,38 +36,46 @@ class Resources::PoolsController< ApplicationController
def new
require_privilege(Privilege::CREATE, Pool)
@pool = Pool.new
+ @quota = Quota.new
end
def create
require_privilege(Privilege::CREATE, Pool)
@pool = Pool.new(params[:pool])
- quota = Quota.new
- quota.save!
+ @pool.quota = @quota = Quota.new
+
+ limit = params[:quota][:maximum_running_instances] if params[:quota]
+ @pool.quota.set_maximum_running_instances(limit)
- @pool.quota_id = quota.id
- @pool.pool_family = PoolFamily.default
if @pool.save
@pool.assign_owner_roles(current_user)
flash[:notice] = "Pool added."
redirect_to :action => 'show', :id => @pool.id
else
- render :action => :new
+ flash.now[:warning] = "Pool creation failed."
+ render :new and return
end
end
def edit
@pool = Pool.find(params[:id])
require_privilege(Privilege::MODIFY, @pool)
+ @quota = @pool.quota
end
def update
@pool = Pool.find(params[:id])
require_privilege(Privilege::MODIFY, @pool)
+ @quota = @pool.quota
+
+ limit = params[:quota][:maximum_running_instances] if params[:quota]
+ @pool.quota.set_maximum_running_instances(limit)
if @pool.update_attributes(params[:pool])
flash[:notice] = "Pool updated."
redirect_to :action => 'show', :id => @pool.id
else
+ flash[:error] = "Pool wasn't updated!"
render :action => :edit
end
end
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index ebee420..c158403 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -41,7 +41,7 @@ class Pool< ActiveRecord::Base
text :name, :as => :code_substring
end
has_many :instances, :dependent => :destroy
- belongs_to :quota
+ belongs_to :quota, :autosave => true, :dependent => :destroy
belongs_to :pool_family
# NOTE: Commented out because images table doesn't have pool_id foreign key?!
diff --git a/src/app/views/resources/pools/edit.haml
b/src/app/views/resources/pools/edit.haml
index 43bb6d0..cc00233 100644
--- a/src/app/views/resources/pools/edit.haml
+++ b/src/app/views/resources/pools/edit.haml
@@ -1,8 +1,27 @@
-%h3
- Editing pool
+= error_messages_for :pool
+%h1
+ Edit pool
= @pool.name
- form_for [:resources, @pool] do |form|
- = form.text_field :name
- = form.error_message_on :name, 'Name '
- = form.submit 'Save'
+ %fieldset
+ = form.label :name, "Name:", :class => "grid_2 alpha"
+ = form.text_field :name
+ %fieldset
+ = form.label :pool_family_id, "Pool Family:", :class => "grid_2
alpha"
+ = form.collection_select :pool_family_id, PoolFamily.all, :id, :name
+ %fieldset
+ = label_tag "Quota"
+ = text_field :quota, :maximum_running_instances, :title =>
t('provider_accounts.form.quota_instances'), :value =>
@quota.maximum_running_instances || "unlimited", :id =>
"quota_instances", :class => "grid_3 omega"
+ (
+ %button.linkbutton.nospace{ :type => 'button', :onclick =>
"set_unlimited_quota(\"quota_instances\");" }<>
+ = t('provider_accounts.form.unlimited_quota')
+ )
+ %fieldset.clear
+
+ = form.submit "Save"
+
+:javascript
+ function set_unlimited_quota(elem_id) {
+ $("#" + elem_id)[0].value = "unlimited";
+ }
diff --git a/src/app/views/resources/pools/new.haml
b/src/app/views/resources/pools/new.haml
index 032f0ac..dde52c9 100644
--- a/src/app/views/resources/pools/new.haml
+++ b/src/app/views/resources/pools/new.haml
@@ -1,11 +1,24 @@
-= error_messages_for 'account'
+= error_messages_for :pool
%h1 Create a new Pool
- form_for @pool, :url => resources_pools_path do |form|
- %h2 Pool
%fieldset
- %label.grid_2.alpha Name:
- = form.text_field :name, :class => "grid_5"
- = form.error_message_on :name, 'Name '
- .clear.grid_14.prefix_2.alpha Provide a descriptive name for this pool.
+ = form.label :name, "Name:", :class => "grid_2 alpha"
+ = form.text_field :name
+ %fieldset
+ = form.label :pool_family_id, "Pool Family:", :class => "grid_2
alpha"
+ = form.collection_select :pool_family_id, PoolFamily.all, :id, :name
+ %fieldset
+ = label_tag "Quota"
+ = text_field :quota, :maximum_running_instances, :title =>
t('provider_accounts.form.quota_instances'), :value =>
@quota.maximum_running_instances || "unlimited", :id =>
"quota_instances", :class => "grid_3 omega"
+ (
+ %button.linkbutton.nospace{ :type => 'button', :onclick =>
"set_unlimited_quota(\"quota_instances\");" }<>
+ = t('provider_accounts.form.unlimited_quota')
+ )
+ %fieldset.clear
+
+ = form.submit "Save"
- = submit_tag "Save", :class => "submit formbutton"
+:javascript
+ function set_unlimited_quota(elem_id) {
+ $("#" + elem_id)[0].value = "unlimited";
+ }
diff --git a/src/features/pool.feature b/src/features/pool.feature
index 7f1a00b..04652a6 100644
--- a/src/features/pool.feature
+++ b/src/features/pool.feature
@@ -14,10 +14,14 @@ Feature: Manage Pools
Then I should be on the new resources pool page
And I should see "Create a new Pool"
When I fill in "pool_name" with "mockpool"
+ And I select "default" from "pool_pool_family_id"
+ And I fill in "quota_instances" with "unlimited"
And I press "Save"
Then I should be on the resources pool page
And I should see "Pool added"
And I should see "mockpool"
+ And I should see "default"
+ And I should see "unlimited"
And I should have a pool named "mockpool"
@tag
@@ -62,6 +66,7 @@ Feature: Manage Pools
Then I should be on the new resources pool page
And I should see "Create a new Pool"
When I fill in "pool_name" with "mockpool"
+ And I select "default" from "pool_pool_family_id"
And I press "Save"
Then I should be on the resources pool page
And I should see "Pool added"
@@ -71,6 +76,7 @@ Feature: Manage Pools
Then I should be on the new resources pool page
And I should see "Create a new Pool"
When I fill in "pool_name" with "foopool"
+ And I select "default" from "pool_pool_family_id"
And I press "Save"
Then I should be on the resources pool page
And I should see "Pool added"
diff --git a/src/spec/controllers/pools_controller_spec.rb
b/src/spec/controllers/pools_controller_spec.rb
index bc3488d..ae84666 100644
--- a/src/spec/controllers/pools_controller_spec.rb
+++ b/src/spec/controllers/pools_controller_spec.rb
@@ -23,11 +23,13 @@ describe Resources::PoolsController do
it "should provider means to create new pool" do
UserSession.create(@admin)
lambda do
- post :create, :pool => { :name => 'foopool' }
+ post :create, :pool => {
+ :name => 'foopool',
+ :pool_family_id => PoolFamily.find_by_name('default').id
+ }
end.should change(Pool, :count).by(1)
id = Pool.find(:first, :conditions => ['name = ?',
'foopool']).id
response.should redirect_to(resources_pool_path(id))
end
-
end
Hey Jirka,
the patch looks very good. Unfortunately, running cucumber tests gives
me an error. Please fix it and resend, I'll push it once all the tests pass.
Thomas
(::) failed steps (::)
undefined method `maximum_running_instances' for nil:NilClass
(ActionView::TemplateError)
On line #18 of app/views/resources/pools/_list.haml
15: %input{:name => "pools_selected[]", :type =>
"checkbox", :value => pool.id, :id =>
"pool_checkbox_#{pool.id}",
:checked => selected }
16: = link_to pool.name, resources_pool_path(pool)
17: %td
18: = pool.quota.maximum_running_instances or 'unlimited'
19: %td
20: = pool.quota.percentage_used
21: ='%'
app/views/resources/pools/_list.haml:18:in
`_run_haml_app47views47resources47pools47_list46haml_locals_list_object'
app/views/resources/pools/_list.haml:11:in `each'
app/views/resources/pools/_list.haml:11:in
`_run_haml_app47views47resources47pools47_list46haml_locals_list_object'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:202:in
`call'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:202:in
`form_tag'
haml (3.0.18) lib/haml/helpers.rb:588:in `call'
haml (3.0.18) lib/haml/helpers.rb:588:in `haml_bind_proc'
haml (3.0.18) lib/haml/helpers.rb:343:in `call'
haml (3.0.18) lib/haml/helpers.rb:343:in `capture_haml'
haml (3.0.18) lib/haml/helpers.rb:566:in `with_haml_buffer'
haml (3.0.18) lib/haml/helpers.rb:339:in `capture_haml'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:88:in
`capture'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:208:in
`form_tag'
app/views/resources/pools/_list.haml:1:in
`_run_haml_app47views47resources47pools47_list46haml_locals_list_object'
/usr/lib/ruby/gems/1.8/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action_view/base.rb:17:in
`render_partial'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:11:in
`render_without_mock_proxy'
haml (3.0.18) lib/haml/helpers.rb:90:in `non_haml'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:11:in
`render_without_mock_proxy'
/usr/lib/ruby/gems/1.8/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action_view/base.rb:27:in
`render'
app/views/resources/pools/index.haml:2:in
`_run_haml_app47views47resources47pools47index46haml'
haml (3.0.18) lib/haml/helpers.rb:343:in `call'
haml (3.0.18) lib/haml/helpers.rb:343:in `capture_haml'
haml (3.0.18) lib/haml/helpers.rb:566:in `with_haml_buffer'
haml (3.0.18) lib/haml/helpers.rb:339:in `capture_haml'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:88:in
`capture'
app/views/resources/pools/index.haml:1:in
`_run_haml_app47views47resources47pools47index46haml'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:13:in
`render_without_mock_proxy'
/usr/lib/ruby/gems/1.8/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action_view/base.rb:27:in
`render'
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:13:in
`render_without_mock_proxy'
/usr/lib/ruby/gems/1.8/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action_view/base.rb:27:in
`render'
compass (0.10.4)
lib/compass/app_integration/rails/actionpack2/action_controller.rb:7:in
`process'
haml (3.0.18) rails/./lib/sass/plugin/rack.rb:41:in `call'
haml (3.0.18) rails/./lib/sass/plugin/rack.rb:41:in `call'
webrat (0.7.3) lib/webrat/adapters/rails.rb:50:in `send'
webrat (0.7.3) lib/webrat/adapters/rails.rb:50:in `do_request'
webrat (0.7.3) lib/webrat/adapters/rails.rb:15:in `get'
(__FORWARDABLE__):3:in `__send__'
(__FORWARDABLE__):3:in `get'
webrat (0.7.3) lib/webrat/core/session.rb:280:in `send'
webrat (0.7.3) lib/webrat/core/session.rb:280:in `process_request'
webrat (0.7.3) lib/webrat/core/session.rb:119:in `request_page'
webrat (0.7.3) lib/webrat/core/session.rb:132:in `request_page'
webrat (0.7.3) lib/webrat/core/elements/form.rb:20:in `submit'
webrat (0.7.3) lib/webrat/core/elements/field.rb:193:in `click'
webrat (0.7.3) lib/webrat/core/scope.rb:291:in `click_button'
(__FORWARDABLE__):3:in `__send__'
(__FORWARDABLE__):3:in `click_button'
webrat (0.7.3) lib/webrat/core/methods.rb:7:in `click_button'
features/step_definitions/web_steps.rb:24
cucumber (0.9.4) bin/./lib/cucumber/core_ext/instance_exec.rb:48:in
`instance_exec'
cucumber (0.9.4) bin/./lib/cucumber/core_ext/instance_exec.rb:48:in
`cucumber_instance_exec'
cucumber (0.9.4) bin/./lib/cucumber/core_ext/instance_exec.rb:69:in
`cucumber_run_with_backtrace_filtering'
cucumber (0.9.4) bin/./lib/cucumber/core_ext/instance_exec.rb:36:in
`cucumber_instance_exec'
cucumber (0.9.4)
bin/./lib/cucumber/rb_support/rb_step_definition.rb:62:in `invoke'
cucumber (0.9.4) bin/./lib/cucumber/step_match.rb:26:in `invoke'
cucumber (0.9.4) bin/./lib/cucumber/ast/step_invocation.rb:63:in
`invoke'
cucumber (0.9.4) bin/./lib/cucumber/ast/step_invocation.rb:42:in
`accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:99:in
`visit_step'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:164:in
`broadcast'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:98:in
`visit_step'
cucumber (0.9.4) bin/./lib/cucumber/ast/step_collection.rb:15:in
`accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/step_collection.rb:14:in `each'
cucumber (0.9.4) bin/./lib/cucumber/ast/step_collection.rb:14:in
`accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:93:in
`visit_steps'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:164:in
`broadcast'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:92:in
`visit_steps'
cucumber (0.9.4) bin/./lib/cucumber/ast/scenario.rb:53:in `accept'
cucumber (0.9.4) bin/./lib/cucumber/runtime.rb:79:in `with_hooks'
cucumber (0.9.4) bin/./lib/cucumber/runtime.rb:95:in `before_and_after'
cucumber (0.9.4) bin/./lib/cucumber/runtime.rb:78:in `with_hooks'
cucumber (0.9.4) bin/./lib/cucumber/runtime/support_code.rb:115:in
`call'
cucumber (0.9.4) bin/./lib/cucumber/runtime/support_code.rb:115:in
`around'
cucumber (0.9.4)
bin/./lib/cucumber/language_support/language_methods.rb:13:in `around'
cucumber (0.9.4)
bin/./lib/cucumber/language_support/language_methods.rb:95:in `call'
cucumber (0.9.4)
bin/./lib/cucumber/language_support/language_methods.rb:95:in
`execute_around'
cucumber (0.9.4)
bin/./lib/cucumber/language_support/language_methods.rb:12:in `around'
cucumber (0.9.4) bin/./lib/cucumber/runtime/support_code.rb:114:in
`around'
cucumber (0.9.4) bin/./lib/cucumber/runtime/support_code.rb:112:in
`call'
cucumber (0.9.4) bin/./lib/cucumber/runtime/support_code.rb:112:in
`around'
cucumber (0.9.4) bin/./lib/cucumber/runtime.rb:90:in `around'
cucumber (0.9.4) bin/./lib/cucumber/runtime.rb:77:in `with_hooks'
cucumber (0.9.4) bin/./lib/cucumber/ast/scenario.rb:51:in `accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/scenario.rb:106:in
`with_visitor'
cucumber (0.9.4) bin/./lib/cucumber/ast/scenario.rb:45:in `accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:51:in
`visit_feature_element'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:164:in
`broadcast'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:50:in
`visit_feature_element'
cucumber (0.9.4) bin/./lib/cucumber/ast/feature.rb:35:in `accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/feature.rb:34:in `each'
cucumber (0.9.4) bin/./lib/cucumber/ast/feature.rb:34:in `accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:20:in
`visit_feature'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:164:in
`broadcast'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:19:in
`visit_feature'
cucumber (0.9.4) bin/./lib/cucumber/ast/features.rb:29:in `accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/features.rb:17:in `each'
cucumber (0.9.4) bin/./lib/cucumber/ast/features.rb:17:in `each'
cucumber (0.9.4) bin/./lib/cucumber/ast/features.rb:28:in `accept'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:14:in
`visit_features'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:164:in
`broadcast'
cucumber (0.9.4) bin/./lib/cucumber/ast/tree_walker.rb:13:in
`visit_features'
cucumber (0.9.4) bin/./lib/cucumber/runtime.rb:45:in `run!'
cucumber (0.9.4) bin/./lib/cucumber/cli/main.rb:48:in `execute!'
cucumber (0.9.4) bin/./lib/cucumber/cli/main.rb:21:in `execute'
cucumber (0.9.4) bin/cucumber:8
features/pool.feature:55:in `And I press "Destroy"'
Failing Scenarios:
cucumber features/pool.feature:47 # Scenario: Delete pools
100 scenarios (1 failed, 99 passed)
1168 steps (1 failed, 4 skipped, 1163 passed)