Skip to content

Commit

Permalink
feat(API): RHINENG-16382 provide SSG ID for Test Result
Browse files Browse the repository at this point in the history
  • Loading branch information
romanblanco committed Mar 6, 2025
1 parent 0c1640d commit db5640f
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 428 deletions.
6 changes: 6 additions & 0 deletions app/models/v2/test_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module V2
# Database model representing latest results of compliance scans
# rubocop:disable Metrics/ClassLength
class TestResult < ApplicationRecord
# FIXME: clean up after the remodel
self.table_name = :v2_test_results
Expand Down Expand Up @@ -123,6 +124,10 @@ def compliant
!score.nil? && score >= threshold.to_f
end

def security_guide_id
attributes['security_guide__id'] || try(:security_guide)&.id
end

def security_guide_version
attributes['security_guide__version'] || try(:security_guide)&.version
end
Expand All @@ -143,4 +148,5 @@ def self.security_guide_versions
.uniq # using this instead of `.distinct` to properly handle sorting of versions. It should still perform fine.
end
end
# rubocop:enable Metrics/ClassLength
end
1 change: 1 addition & 0 deletions app/serializers/v2/test_result_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class TestResultSerializer < V2::ApplicationSerializer
derived_attribute :compliant, :score, report: [:compliance_threshold]
derived_attribute :system_id, :system_id
derived_attribute :security_guide_version, security_guide: [:version]
derived_attribute :security_guide_id, security_guide: [:id]
end
end
1 change: 1 addition & 0 deletions spec/controllers/v2/test_results_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
end_time: -> { end_time.as_json },
failed_rule_count: :failed_rule_count,
display_name: :display_name,
security_guide_id: :security_guide_id,
security_guide_version: :security_guide_version,
groups: :groups,
tags: -> { tags.map { |t| t.slice('key', 'namespace', 'value') } },
Expand Down
Loading

0 comments on commit db5640f

Please sign in to comment.