aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-11-13 16:09:20 +0100
committercedricnjanga2017-11-13 17:52:54 +0100
commit5dd6b2f963d3ae732c6f56112e5f5ac56b6c2764 (patch)
tree2dd1d52c9bba62d69f5216323acce139fa137a3f
parent32d8376cd407c24a6eca5ebf2adfca3c7d9d776f (diff)
downloadchouette-core-5dd6b2f963d3ae732c6f56112e5f5ac56b6c2764.tar.bz2
ComplianceCheckSet#update_status: Handle resources with "IGNORED" status
If any associated resources have the "IGNORED" status, this shouldn't affect the outcome of a "successful" status. Allow the `ComplianceCheckSet` to be "successful" even if some `Resource`s are "IGNORED". Refs #4757
-rw-r--r--app/models/compliance_check_set.rb17
-rw-r--r--spec/models/compliance_check_set_spec.rb18
2 files changed, 32 insertions, 3 deletions
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb
index a133230f8..006d14bef 100644
--- a/app/models/compliance_check_set.rb
+++ b/app/models/compliance_check_set.rb
@@ -30,15 +30,26 @@ class ComplianceCheckSet < ActiveRecord::Base
end
end
- if all_statuses_ok?(statuses)
+ if statuses_ok_or_ignored?(statuses)
return update(status: 'successful')
end
end
private
- def all_statuses_ok?(statuses)
+ def statuses_ok_or_ignored?(statuses)
uniform_statuses = statuses.uniq
- uniform_statuses.length == 1 && uniform_statuses.first == 'OK'
+
+ (
+ # All statuses OK
+ uniform_statuses.length == 1 &&
+ uniform_statuses.first == 'OK'
+ ) ||
+ (
+ # Statuses OK or IGNORED
+ uniform_statuses.length == 2 &&
+ uniform_statuses.include?('OK') &&
+ uniform_statuses.include?('IGNORED')
+ )
end
end
diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb
index d3a5e941e..d09a9cc95 100644
--- a/spec/models/compliance_check_set_spec.rb
+++ b/spec/models/compliance_check_set_spec.rb
@@ -64,5 +64,23 @@ RSpec.describe ComplianceCheckSet, type: :model do
expect(check_set.status).to eq('warning')
end
+
+ it "updates :status to successful when resources are IGNORED" do
+ check_set = create(:compliance_check_set)
+ create(
+ :compliance_check_resource,
+ compliance_check_set: check_set,
+ status: 'IGNORED'
+ )
+ create(
+ :compliance_check_resource,
+ compliance_check_set: check_set,
+ status: 'OK'
+ )
+
+ check_set.update_status
+
+ expect(check_set.status).to eq('successful')
+ end
end
end