class Inferno::Repositories::Results::Model

Public Class Methods

current_results_for_test_session(test_session_id) click to toggle source
# File lib/inferno/repositories/results.rb, line 200
def self.current_results_for_test_session(test_session_id)
  fetch(current_results_sql, test_session_id: test_session_id)
end
current_results_for_test_session_and_runnables(test_session_id, runnables) click to toggle source
# File lib/inferno/repositories/results.rb, line 204
def self.current_results_for_test_session_and_runnables(test_session_id, runnables)
  test_ids = runnables.select { |runnable| runnable < Entities::Test }.map!(&:id)
  test_group_ids = runnables.select { |runnable| runnable < Entities::TestGroup }.map!(&:id)
  test_suite_ids = runnables.select { |runnable| runnable < Entities::TestSuite }.map!(&:id)

  fetch(
    current_results_sql(with_runnables_filter: true),
    test_session_id: test_session_id,
    test_ids: test_ids,
    test_group_ids: test_group_ids,
    test_suite_ids: test_suite_ids
  )
end
current_results_sql(with_runnables_filter: false) click to toggle source
# File lib/inferno/repositories/results.rb, line 157
        def self.current_results_sql(with_runnables_filter: false)
          query = <<~SQL.gsub(/\s+/, ' ').freeze
            SELECT * FROM results a
            WHERE test_session_id = :test_session_id
          SQL
          runnables_filter = <<~SQL.gsub(/\s+/, ' ').freeze
            AND (test_id IN :test_ids OR test_group_id IN :test_group_ids OR test_suite_id IN :test_suite_ids)
          SQL
          subquery = <<~SQL.gsub(/\s+/, ' ').freeze
            AND a.id IN  (
              SELECT id
              FROM results b
              WHERE (b.test_session_id = a.test_session_id AND b.test_id = a.test_id) OR
                    (b.test_session_id = a.test_session_id AND b.test_group_id = a.test_group_id) OR
                    (b.test_session_id = a.test_session_id AND b.test_suite_id = a.test_suite_id)
              ORDER BY updated_at DESC
              LIMIT 1
            )
          SQL
          return "#{query} #{runnables_filter} #{subquery}" if with_runnables_filter

          "#{query} #{subquery}"
        end

Public Instance Methods

before_create() click to toggle source
Calls superclass method
# File lib/inferno/repositories/results.rb, line 187
def before_create
  self.id = SecureRandom.uuid
  time = Time.now
  self.created_at ||= time
  self.updated_at ||= time
  super
end
validate() click to toggle source
# File lib/inferno/repositories/results.rb, line 195
def validate
  super
  errors.add(:result, "'#{result}' is not valid") unless Entities::Result::RESULT_OPTIONS.include?(result)
end