diff options
| author | Teddy Wing | 2017-11-09 11:37:35 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-11-13 17:52:54 +0100 |
| commit | bde146b6ca9169c9724ed1406cfb6d1ec98f18f9 (patch) | |
| tree | 11f38cf4badd0d5d63ca479309dd84fd8c3d0d81 | |
| parent | 3d6b5c8a3192d255fcec73803730d4d1a08c6586 (diff) | |
| download | chouette-core-bde146b6ca9169c9724ed1406cfb6d1ec98f18f9.tar.bz2 | |
ComplianceCheckSet#update_status: Only update 'successful' at the end
Previously we were updating to a 'successful' status prematurely, at the
first encounter with a successful `ComplianceCheckResource`. Here, we
wait until we've looked at all associated `ComplianceCheckResource`s
before setting 'successful'. Only if all associated
`ComplianceCheckResource`s are successful do we set this status on the
`ComplianceCheckSet`.
Refs #4757
| -rw-r--r-- | app/models/compliance_check_set.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index bd8123b25..062c5f4a4 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -19,15 +19,28 @@ class ComplianceCheckSet < ActiveRecord::Base end def update_status - compliance_check_resources.each do |resource| + statuses = compliance_check_resources.map do |resource| case resource.status - when 'OK' - update(status: 'successful') when 'ERROR' update(status: 'failed') + return when 'WARNING' update(status: 'warning') + return + else + resource.status end end + + if all_statuses_are_ok(statuses) + update(status: 'successful') + end + end + + private + + def all_statuses_are_ok(statuses) + uniform_statuses = statuses.uniq + uniform_statuses.length == 1 && uniform_statuses.first == 'OK' end end |
