Class: Inferno::Repositories::Results
Defined Under Namespace
Classes: Model
Instance Method Summary
collapse
Methods inherited from Repository
#add_non_db_entities, db, #db_params, #entity_class, #entity_class_name, #find, #handle_non_db_params, #non_db_params, table_name, #update
Instance Method Details
#build_entity(params) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/inferno/repositories/results.rb', line 55
def build_entity(params)
runnable =
if params[:test_id]
{ test: tests_repo.find(params[:test_id]) }
elsif params[:test_group_id]
{ test_group: groups_repo.find(params[:test_group_id]) }
elsif params[:test_suite_id]
{ test_suite: suites_repo.find(params[:test_suite_id]) }
else
{}
end
entity_class.new(params.merge(runnable))
end
|
#create(params) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/inferno/repositories/results.rb', line 14
def create(params)
messages = params.delete(:messages) || []
requests = params.delete(:requests) || []
super(params).tap do |result|
result_model = self.class::Model.find(id: result.id)
messages.each { |message| messages_repo.create(message.merge(result_id: result.id)) }
requests.each do |request|
request_id =
if request.id.present?
request.id
else
requests_repo.create(request.to_hash.merge(result_id: result.id)).id
end
request_model = requests_repo.class::Model.find(id: request_id)
result_model.add_request(request_model)
end
end
end
|
#current_results_for_test_session(test_session_id) ⇒ Object
Get all of the current results for a test session
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/inferno/repositories/results.rb', line 110
def current_results_for_test_session(test_session_id)
self.class::Model
.current_results_for_test_session(test_session_id)
.eager(:messages)
.eager(requests: proc { |requests| requests.select(*Entities::Request::SUMMARY_FIELDS) })
.all
.map! do |result_hash|
build_entity(
result_hash
.to_json_data(json_serializer_options)
.deep_symbolize_keys!
)
end
end
|
#current_results_for_test_session_and_runnables(test_session_id, runnables) ⇒ Object
Get the current results for a list of runnables
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/inferno/repositories/results.rb', line 126
def current_results_for_test_session_and_runnables(test_session_id, runnables)
self.class::Model
.current_results_for_test_session_and_runnables(test_session_id, runnables)
.all
.map! do |result_hash|
build_entity(
result_hash
.to_json_data(json_serializer_options)
.deep_symbolize_keys!
)
end
end
|
#find_waiting_result(test_run_id:) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/inferno/repositories/results.rb', line 94
def find_waiting_result(test_run_id:)
result_hash =
Model
.where(test_run_id:, result: 'wait')
.where { test_id !~ nil }
.limit(1)
.to_a
.first
&.to_hash
return nil if result_hash.nil?
build_entity(result_hash)
end
|
#json_serializer_options ⇒ Object
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/inferno/repositories/results.rb', line 143
def json_serializer_options
{
include: {
messages: {},
requests: {
only: Entities::Request::SUMMARY_FIELDS
}
}
}
end
|
#result_for_test_run(params) ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/inferno/repositories/results.rb', line 69
def result_for_test_run(params)
result_hash =
self.class::Model
.find(params)
&.to_hash
return nil if result_hash.nil?
build_entity(result_hash)
end
|
#test_run_results_after(test_run_id:, after:) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/inferno/repositories/results.rb', line 80
def test_run_results_after(test_run_id:, after:)
Model
.where(test_run_id:)
.where { updated_at >= after }
.to_a
.map! do |result_hash|
build_entity(
result_hash
.to_json_data(json_serializer_options)
.deep_symbolize_keys!
)
end
end
|
#update_result(result_id, result, result_message = nil) ⇒ Object
139
140
141
|
# File 'lib/inferno/repositories/results.rb', line 139
def update_result(result_id, result, result_message = nil)
update(result_id, result:, result_message:)
end
|