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
  <<~SQL.gsub(/\s+/, ' ').freeze
    select final_requests.*
    from (
        select uncounted_requests.request_id request_id
        from (
                select r.id request_id, t.id tag_id from requests r
                inner join requests_tags rt on r."index" = rt.requests_id
                inner join tags t on rt.tags_id = t.id
                where r.test_session_id = :test_session_id
                and r.result_id in (
                SELECT a.id FROM results a
                        WHERE a.test_session_id = r.test_session_id
                        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
                        )
                )
                and t.name in :tags
                group by r.id, t.id
            ) as uncounted_requests
            group by uncounted_requests.request_id
            having count(*) = :tag_count
        ) as matched_requests
    inner join requests final_requests on final_requests.id = matched_requests.request_id
    where final_requests.test_session_id = :test_session_id
    order by final_requests."index"
  SQL
end

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