Commit 6bdc9116c3a59737315a8812343cd54b73310ecf

Authored by Daniel Alves
Committed by Diego Camarinha
1 parent 15a14533

Created validation for weight in metric configuration form.

Signed off by: Diego Araújo <diegoamc90@gmail.com>
app/models/metric_configuration.rb
@@ -6,7 +6,7 @@ class MetricConfiguration &lt; KalibroGatekeeperClient::Entities::MetricConfigurati @@ -6,7 +6,7 @@ class MetricConfiguration &lt; KalibroGatekeeperClient::Entities::MetricConfigurati
6 attr_accessor :code, :weight, :aggregation_form 6 attr_accessor :code, :weight, :aggregation_form
7 7
8 validates :code, presence: true, code_uniqueness: true 8 validates :code, presence: true, code_uniqueness: true
9 - validates :weight, presence: true 9 + validates :weight, presence: true, numericality: { greater_than: 0 }
10 validates :aggregation_form, presence: true, unless: "metric.compound == true" 10 validates :aggregation_form, presence: true, unless: "metric.compound == true"
11 11
12 def mezuro_ranges 12 def mezuro_ranges
features/metric_configuration/edition.feature
@@ -36,4 +36,17 @@ Feature: Metric Configuration edition @@ -36,4 +36,17 @@ Feature: Metric Configuration edition
36 When I visit the sample metric configuration edit page 36 When I visit the sample metric configuration edit page
37 And I fill the Weight field with " " 37 And I fill the Weight field with " "
38 And I press the Save button 38 And I press the Save button
39 - Then I should see "Weight can't be blank"  
40 \ No newline at end of file 39 \ No newline at end of file
  40 + Then I should see "Weight can't be blank"
  41 +
  42 + @kalibro_restart
  43 + Scenario: Should not edit a metric configuration with invalid weight
  44 + Given I am a regular user
  45 + And I am signed in
  46 + And I own a sample configuration
  47 + And I have a sample reading group
  48 + And I have a sample metric configuration within the given mezuro configuration
  49 + When I visit the sample metric configuration edit page
  50 + And I fill the Weight field with "0"
  51 + And I set the select field "Aggregation Form" as "Median"
  52 + When I press the Save button
  53 + Then I should see "Weight must be greater than 0"
41 \ No newline at end of file 54 \ No newline at end of file
spec/models/metric_configuration_spec.rb
@@ -22,9 +22,10 @@ describe MetricConfiguration, :type =&gt; :model do @@ -22,9 +22,10 @@ describe MetricConfiguration, :type =&gt; :model do
22 before :each do 22 before :each do
23 MetricConfiguration.expects(:metric_configurations_of).at_least_once.returns([]) 23 MetricConfiguration.expects(:metric_configurations_of).at_least_once.returns([])
24 end 24 end
25 - 25 +
26 it { is_expected.to validate_presence_of(:code) } 26 it { is_expected.to validate_presence_of(:code) }
27 it { is_expected.to validate_presence_of(:weight) } 27 it { is_expected.to validate_presence_of(:weight) }
  28 + it { is_expected.to validate_numericality_of(:weight) }
28 it { is_expected.to validate_presence_of(:aggregation_form) } 29 it { is_expected.to validate_presence_of(:aggregation_form) }
29 end 30 end
30 31