diff options
| author | Luc Donnet | 2018-03-08 15:03:34 +0100 | 
|---|---|---|
| committer | Luc Donnet | 2018-03-08 15:03:34 +0100 | 
| commit | d79abf1d6c63004da9f1d969e8edee4d9cd52393 (patch) | |
| tree | 3bcf66a8f8e280698aadf3c4847bf106a51cf3c6 | |
| parent | a53eb22c144b12cf7b662db38ddbbba20af89d3a (diff) | |
| download | chouette-core-d79abf1d6c63004da9f1d969e8edee4d9cd52393.tar.bz2 | |
Fix compliance_check_resource and compliance_check_set status Refs #5989 @15989-fix_compliance_check_resource_status
| -rw-r--r-- | app/helpers/compliance_check_resources_helper.rb | 4 | ||||
| -rw-r--r-- | app/models/compliance_check_resource.rb | 2 | ||||
| -rw-r--r-- | app/models/compliance_check_set.rb | 44 | ||||
| -rw-r--r-- | spec/models/compliance_check_set_spec.rb | 7 | 
4 files changed, 19 insertions, 38 deletions
| diff --git a/app/helpers/compliance_check_resources_helper.rb b/app/helpers/compliance_check_resources_helper.rb index 95cabed88..19b152e8d 100644 --- a/app/helpers/compliance_check_resources_helper.rb +++ b/app/helpers/compliance_check_resources_helper.rb @@ -4,8 +4,8 @@ module ComplianceCheckResourcesHelper    def compliance_check_resource_status(status)        cls = ''        cls = 'success' if status == 'OK' -      cls = 'warning' if status == 'WARNING' -      cls = 'danger' if %w[ERROR IGNORED].include? status +      cls = 'warning' if %w[WARNING IGNORED].include? status +      cls = 'danger' if status == 'ERROR'        content_tag :span, '', class: "fa fa-circle text-#{cls}"    end diff --git a/app/models/compliance_check_resource.rb b/app/models/compliance_check_resource.rb index 2989bf3cf..777254aaf 100644 --- a/app/models/compliance_check_resource.rb +++ b/app/models/compliance_check_resource.rb @@ -3,7 +3,7 @@ class ComplianceCheckResource < ActiveRecord::Base    belongs_to :compliance_check_set -  enumerize :status, in: %i(OK ERROR WARNING IGNORED), scope: true +  enumerize :status, in: %i(OK ERROR WARNING IGNORED)    validates_presence_of :compliance_check_set  end diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 289fc134f..49d324c53 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -49,39 +49,25 @@ class ComplianceCheckSet < ActiveRecord::Base    end    def update_status -    statuses = compliance_check_resources.map do |resource| -      case resource.status -      when 'ERROR' -        return update(status: 'failed') -      when 'WARNING' -        return update(status: 'warning') -      else -        resource.status +    status = +      if compliance_check_resources.where(status: 'ERROR').count > 0 +        'failed' +      elsif compliance_check_resources.where(status: ["WARNING", "IGNORED"]).count > 0 +        'warning' +      elsif compliance_check_resources.where(status: "OK").count == compliance_check_resources.count +        'successful'        end -    end -    if statuses_ok_or_ignored?(statuses) -      return update(status: 'successful') +    attributes = { +      status: status +    } + +    if self.class.finished_statuses.include?(status) +      attributes[:ended_at] = Time.now      end -    true +    update attributes    end -  private - -  def statuses_ok_or_ignored?(statuses) -    uniform_statuses = statuses.uniq - -    ( -      # 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 b981a68bb..61421287a 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -81,14 +81,9 @@ RSpec.describe ComplianceCheckSet, type: :model do        check_set.update_status -      expect(check_set.status).to eq('successful') +      expect(check_set.status).to eq('warning')      end -    it "returns true when the status did not get updated" do -      check_set = create(:compliance_check_set) - -      expect(check_set.update_status).to be true -    end    end    describe 'possibility to delete the associated compliance_control_set' do | 
