Class: Inferno::Repositories::Requests::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/inferno/repositories/requests.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tagged_requests(test_session_id, tags) ⇒ Object



170
171
172
# File 'lib/inferno/repositories/requests.rb', line 170

def self.tagged_requests(test_session_id, tags)
  fetch(tagged_requests_sql, test_session_id:, tags:, tag_count: tags.length)
end

.tagged_requests_sqlObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/inferno/repositories/requests.rb', line 132

def self.tagged_requests_sql
  # Find all the requests for the current session which:
  # - match all supplied tags
  # - are the from the most recent test run for each runnable
  "    select final_requests.*\n    from (\n        select uncounted_requests.request_id request_id\n        from (\n                select r.id request_id, t.id tag_id from requests r\n                inner join requests_tags rt on r.\"index\" = rt.requests_id\n                inner join tags t on rt.tags_id = t.id\n                where r.test_session_id = :test_session_id\n                and r.result_id in (\n                SELECT a.id FROM results a\n                        WHERE a.test_session_id = r.test_session_id\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                )\n                and t.name in :tags\n                group by r.id, t.id\n            ) as uncounted_requests\n            group by uncounted_requests.request_id\n            having count(*) = :tag_count\n        ) as matched_requests\n    inner join requests final_requests on final_requests.id = matched_requests.request_id\n    where final_requests.test_session_id = :test_session_id\n    order by final_requests.\"index\"\n  SQL\nend\n".gsub(/\s+/, ' ').freeze

Instance Method Details

#add_tag(tag_name) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/inferno/repositories/requests.rb', line 123

def add_tag(tag_name)
  tag = Tags::Model.find_or_create(name: tag_name)

  Inferno::Application['db.connection'][:requests_tags].insert(
    tags_id: tag.id,
    requests_id: index
  )
end

#before_createObject



115
116
117
118
119
120
121
# File 'lib/inferno/repositories/requests.rb', line 115

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