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



203
204
205
# File 'lib/inferno/repositories/results.rb', line 203

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



207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/inferno/repositories/results.rb', line 207

def self.current_results_for_test_session_and_runnables(test_session_id, runnables)
  test_ids = runnables.select { |runnable| runnable < Entities::Test }.map!(&:database_id)
  test_group_ids = runnables.select { |runnable| runnable < Entities::TestGroup }.map!(&:database_id)
  test_suite_ids = runnables.select { |runnable| runnable < Entities::TestSuite }.map!(&:database_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



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/inferno/repositories/results.rb', line 160

def self.current_results_sql(with_runnables_filter: false)
  query = "    SELECT * FROM results a\n    WHERE test_session_id = :test_session_id\n  SQL\n  runnables_filter = <<~SQL.gsub(/\\s+/, ' ').freeze\n    AND (test_id IN :test_ids OR test_group_id IN :test_group_ids OR test_suite_id IN :test_suite_ids)\n  SQL\n  subquery = <<~SQL.gsub(/\\s+/, ' ').freeze\n    AND a.id IN  (\n      SELECT id\n      FROM results b\n      WHERE (b.test_session_id = a.test_session_id AND b.test_id = a.test_id) OR\n            (b.test_session_id = a.test_session_id AND b.test_group_id = a.test_group_id) OR\n            (b.test_session_id = a.test_session_id AND b.test_suite_id = a.test_suite_id)\n      ORDER BY updated_at DESC\n      LIMIT 1\n    )\n  SQL\n  return \"\#{query} \#{runnables_filter} \#{subquery}\" if with_runnables_filter\n\n  \"\#{query} \#{subquery}\"\nend\n".gsub(/\s+/, ' ').freeze

Instance Method Details

#before_createObject



190
191
192
193
194
195
196
# File 'lib/inferno/repositories/results.rb', line 190

def before_create
  self.id = SecureRandom.uuid
  time = Time.now
  self.created_at ||= time
  self.updated_at ||= time
  super
end

#validateObject



198
199
200
201
# File 'lib/inferno/repositories/results.rb', line 198

def validate
  super
  errors.add(:result, "'#{result}' is not valid") unless Entities::Result::RESULT_OPTIONS.include?(result)
end