Commit 6bdc9116c3a59737315a8812343cd54b73310ecf
Committed by
Diego Camarinha
1 parent
15a14533
Exists in
colab
and in
4 other branches
Created validation for weight in metric configuration form.
Signed off by: Diego Araújo <diegoamc90@gmail.com>
Showing
3 changed files
with
17 additions
and
3 deletions
Show diff stats
app/models/metric_configuration.rb
... | ... | @@ -6,7 +6,7 @@ class MetricConfiguration < KalibroGatekeeperClient::Entities::MetricConfigurati |
6 | 6 | attr_accessor :code, :weight, :aggregation_form |
7 | 7 | |
8 | 8 | validates :code, presence: true, code_uniqueness: true |
9 | - validates :weight, presence: true | |
9 | + validates :weight, presence: true, numericality: { greater_than: 0 } | |
10 | 10 | validates :aggregation_form, presence: true, unless: "metric.compound == true" |
11 | 11 | |
12 | 12 | def mezuro_ranges | ... | ... |
features/metric_configuration/edition.feature
... | ... | @@ -36,4 +36,17 @@ Feature: Metric Configuration edition |
36 | 36 | When I visit the sample metric configuration edit page |
37 | 37 | And I fill the Weight field with " " |
38 | 38 | And I press the Save button |
39 | - Then I should see "Weight can't be blank" | |
40 | 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 | 54 | \ No newline at end of file | ... | ... |
spec/models/metric_configuration_spec.rb
... | ... | @@ -22,9 +22,10 @@ describe MetricConfiguration, :type => :model do |
22 | 22 | before :each do |
23 | 23 | MetricConfiguration.expects(:metric_configurations_of).at_least_once.returns([]) |
24 | 24 | end |
25 | - | |
25 | + | |
26 | 26 | it { is_expected.to validate_presence_of(:code) } |
27 | 27 | it { is_expected.to validate_presence_of(:weight) } |
28 | + it { is_expected.to validate_numericality_of(:weight) } | |
28 | 29 | it { is_expected.to validate_presence_of(:aggregation_form) } |
29 | 30 | end |
30 | 31 | ... | ... |