From: Jiri Tomasek jtomasek@redhat.com
--- .../controllers/hardware_profiles_controller.rb | 6 +++--- src/app/models/hardware_profile.rb | 12 ++++++++---- src/app/views/hardware_profiles/_form.haml | 3 ++- src/app/views/hardware_profiles/edit.haml | 2 +- src/app/views/hardware_profiles/new.haml | 2 +- src/features/hardware_profile.feature | 14 ++++++++++++++ 6 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/src/app/controllers/hardware_profiles_controller.rb b/src/app/controllers/hardware_profiles_controller.rb index 0929758..2734552 100644 --- a/src/app/controllers/hardware_profiles_controller.rb +++ b/src/app/controllers/hardware_profiles_controller.rb @@ -65,11 +65,11 @@ class HardwareProfilesController < ApplicationController def create build_hardware_profile(params[:hardware_profile]) if params[:commit] == 'Save' - if @hardware_profile.save! + if @hardware_profile.save redirect_to hardware_profiles_path else params.delete :commit - render :action => 'create' + render :action => 'new' end else matching_provider_hardware_profiles @@ -108,7 +108,7 @@ class HardwareProfilesController < ApplicationController render :edit and return end
- unless @hardware_profile.save! + unless @hardware_profile.save render :action => 'edit' and return else flash[:notice] = "Hardware Profile updated!" diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb index 836717e..65d1ae7 100644 --- a/src/app/models/hardware_profile.rb +++ b/src/app/models/hardware_profile.rb @@ -58,16 +58,20 @@ class HardwareProfile < ActiveRecord::Base belongs_to :provider
belongs_to :memory, :class_name => "HardwareProfileProperty", - :dependent => :destroy + :dependent => :destroy, + :validate => false
belongs_to :storage, :class_name => "HardwareProfileProperty", - :dependent => :destroy + :dependent => :destroy, + :validate => false
belongs_to :cpu, :class_name => "HardwareProfileProperty", - :dependent => :destroy + :dependent => :destroy, + :validate => false
belongs_to :architecture, :class_name => "HardwareProfileProperty", - :dependent => :destroy + :dependent => :destroy, + :validate => false
accepts_nested_attributes_for :memory, :cpu, :storage, :architecture
diff --git a/src/app/views/hardware_profiles/_form.haml b/src/app/views/hardware_profiles/_form.haml index a17894d..6c4409d 100644 --- a/src/app/views/hardware_profiles/_form.haml +++ b/src/app/views/hardware_profiles/_form.haml @@ -1,3 +1,4 @@ += error_messages_for :hardware_profile =hwp_form.label :name =hwp_form.text_field :name %table @@ -15,4 +16,4 @@ -else =hwpp_form.text_field(:value) = hwp_form.submit 'Check Matches', :class => "submit button" -= hwp_form.submit 'Save', :class => 'submit button' \ No newline at end of file += hwp_form.submit 'Save', :class => 'submit button' diff --git a/src/app/views/hardware_profiles/edit.haml b/src/app/views/hardware_profiles/edit.haml index 7990a4e..68350e8 100644 --- a/src/app/views/hardware_profiles/edit.haml +++ b/src/app/views/hardware_profiles/edit.haml @@ -17,4 +17,4 @@ -form_for @hardware_profile, :url => hardware_profile_path(@hardware_profile), :html => { :multipart => true } do |hwp_form| = render :partial => "form", :locals => { :hwp_form => hwp_form }
- = render :partial => 'matching_provider_hardware_profiles' + = render :partial => 'matching_provider_hardware_profiles' if params[:commit] == 'Check Matches' diff --git a/src/app/views/hardware_profiles/new.haml b/src/app/views/hardware_profiles/new.haml index 7f12554..fc08757 100644 --- a/src/app/views/hardware_profiles/new.haml +++ b/src/app/views/hardware_profiles/new.haml @@ -9,4 +9,4 @@ -form_for @hardware_profile, :url => hardware_profiles_path, :html => { :multipart => true } do |hwp_form| = render :partial => "form", :locals => { :hwp_form => hwp_form }
- = render :partial => 'matching_provider_hardware_profiles' + = render :partial => 'matching_provider_hardware_profiles' if params[:commit] == 'Check Matches' diff --git a/src/features/hardware_profile.feature b/src/features/hardware_profile.feature index ea0c353..d1f1130 100644 --- a/src/features/hardware_profile.feature +++ b/src/features/hardware_profile.feature @@ -145,3 +145,17 @@ Feature: Manage Pools Then I should see the following: | Name | Memory | CPU | Storage | Architecture | | m1-small | 1740 | 2 | 250 | i386 | + + Scenario: validate hwp inputs + Given I am on the hardware profiles page + When I follow "New Hardware Profile" + Then I should be on the new hardware profile page + When I fill in "name" with "Test Hardware Profile" + And I enter the following details for the Hardware Profile Properties + | name | value | unit | + | memory | | MB | + | cpu | | count | + | storage | | GB | + | architecture | | label | + And I press "Save" + Then I should see "errors prohibited this hardware profile from being saved"