Class: Inferno::Repositories::Results::Model

Inherits:
Object
  • Object
show all
Includes:
ValidateRunnableReference
Defined in:
lib/inferno/repositories/results.rb

Constant Summary

Constants included from ValidateRunnableReference

ValidateRunnableReference::REFERENCE_KEYS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ValidateRunnableReference

#check_runnable_reference, #runnable_reference_exists?

Class Method Details

.current_results_for_test_session(test_session_id) ⇒ Object



200
201
202
# 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:)
end

.current_results_for_test_session_and_runnables(test_session_id, runnables) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
# 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_ids:,
    test_group_ids:,
    test_suite_ids:
  )
end

.current_results_sql(with_runnables_filter: false) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# 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

Instance Method Details

#before_createObject



187
188
189
190
191
192
193
# 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

#validateObject



195
196
197
198
# 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