diff options
| author | Teddy Wing | 2017-11-09 11:44:28 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-11-13 17:52:54 +0100 |
| commit | 406726c7d9f1d98a36e263c57a1fa361003cface (patch) | |
| tree | 16b882fc4ef2e61d31166aa279f174ab604900ab | |
| parent | bde146b6ca9169c9724ed1406cfb6d1ec98f18f9 (diff) | |
| download | chouette-core-406726c7d9f1d98a36e263c57a1fa361003cface.tar.bz2 | |
ComplianceCheckSet#update_status: Should return a boolean
Ensure that `#update_status` always returns a boolean value. We'll be
using this to determine whether the updated status was 'successful' or
not. Hmmm. Wait. That's not right. We want to return true from the
update, we don't care about the status. The error case should be when
the `update` fails. Darn.
Refs #4757
| -rw-r--r-- | app/models/compliance_check_set.rb | 10 | ||||
| -rw-r--r-- | spec/models/compliance_check_set_spec.rb | 22 |
2 files changed, 30 insertions, 2 deletions
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 062c5f4a4..66ef6822e 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -23,10 +23,12 @@ class ComplianceCheckSet < ActiveRecord::Base case resource.status when 'ERROR' update(status: 'failed') - return + + return false when 'WARNING' update(status: 'warning') - return + + return false else resource.status end @@ -34,7 +36,11 @@ class ComplianceCheckSet < ActiveRecord::Base if all_statuses_are_ok(statuses) update(status: 'successful') + + return true end + + false end private diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb index 92b052b53..a77795a86 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -63,5 +63,27 @@ RSpec.describe ComplianceCheckSet, type: :model do expect(check_set.status).to eq('warning') end + + it "returns true when setting :status to successful" do + check_set = create(:compliance_check_set) + create( + :compliance_check_resource, + compliance_check_set: check_set, + status: 'OK' + ) + + expect(check_set.update_status).to be true + end + + it "returns false when setting :status to anything except successful" do + check_set = create(:compliance_check_set) + create( + :compliance_check_resource, + compliance_check_set: check_set, + status: 'ERROR' + ) + + expect(check_set.update_status).to be false + end end end |
