aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Florisson2014-02-03 14:27:45 +0100
committerMarc Florisson2014-02-03 14:27:45 +0100
commit5f22f2e49594813d67428d34db590a769a78686b (patch)
treead718a1ad08c93975f91bdcc0266e8b29417469a
parent6a4b1db7cc5b45a036dd3e8d37fc5baac663fc67 (diff)
downloadchouette-core-5f22f2e49594813d67428d34db590a769a78686b.tar.bz2
add any_error_severity_failure? to ComplianceCheckTask
-rw-r--r--app/models/compliance_check_result.rb6
-rw-r--r--app/models/compliance_check_task.rb6
-rw-r--r--spec/models/compliance_check_task_spec.rb31
3 files changed, 42 insertions, 1 deletions
diff --git a/app/models/compliance_check_result.rb b/app/models/compliance_check_result.rb
index 6d4509676..72cb4f13e 100644
--- a/app/models/compliance_check_result.rb
+++ b/app/models/compliance_check_result.rb
@@ -5,7 +5,7 @@ class ComplianceCheckResult < ActiveRecord::Base
scope :ok, -> { where status: 'ok' }
scope :nok, -> { where status: 'nok' }
- scope :na, -> { where status: 'na' }
+ scope :na, -> { where status: 'na' }
attr_accessible :violation_count
belongs_to :compliance_check_task
@@ -16,6 +16,10 @@ class ComplianceCheckResult < ActiveRecord::Base
serialize :detail, JSON
+ def error_severity_failure?
+ severity == "error" && status == "nok"
+ end
+
def indice
return nil unless rule_code
diff --git a/app/models/compliance_check_task.rb b/app/models/compliance_check_task.rb
index 756f4ba13..2c1fb1bc5 100644
--- a/app/models/compliance_check_task.rb
+++ b/app/models/compliance_check_task.rb
@@ -15,6 +15,12 @@ class ComplianceCheckTask < ActiveRecord::Base
include ::TypeIdsModelable
+ def any_error_severity_failure?
+ return false if compliance_check_results.empty? || compliance_check_results.nil?
+
+ compliance_check_results.any? { |r| r.error_severity_failure? }
+ end
+
def chouette_command
Chouette::Command.new(:schema => referential.slug)
end
diff --git a/spec/models/compliance_check_task_spec.rb b/spec/models/compliance_check_task_spec.rb
index e06554fe4..475926a7c 100644
--- a/spec/models/compliance_check_task_spec.rb
+++ b/spec/models/compliance_check_task_spec.rb
@@ -10,6 +10,37 @@ describe ComplianceCheckTask do
end
end
+
+ describe "#any_error_severity_failure?" do
+ context "when compliance_check_results empty" do
+ before(:each) do
+ subject.compliance_check_results = []
+ end
+ it "does return false" do
+ subject.any_error_severity_failure?.should be_false
+ end
+ end
+ context "when compliance_check_results contains a error_severity_failure" do
+ let( :valid_result){ Factory.build( :compliance_check_result) }
+ let( :invalid_result){ Factory.build( :compliance_check_result, :severity => "error", :status => "nok") }
+ before(:each) do
+ subject.compliance_check_results = [ valid_result, invalid_result]
+ end
+ it "does return true" do
+ subject.any_error_severity_failure?.should be_true
+ end
+ end
+ context "when compliance_check_results contains no error_severity_failure" do
+ let( :valid_result){ Factory.build( :compliance_check_result) }
+ before(:each) do
+ subject.compliance_check_results = [ valid_result]
+ end
+ it "does return false" do
+ subject.any_error_severity_failure?.should be_false
+ end
+ end
+ end
+
describe "#destroy" do
let(:import_task){ Factory( :import_task )}
context "with an import_task" do