Class: RSpec::Sql::QuerySummary

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sql/query_summary.rb

Overview

Converts a list of queries into a summary hash.

Constant Summary collapse

QUERY_TYPES =
%i[delete insert select update].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queries) ⇒ QuerySummary

Returns a new instance of QuerySummary.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rspec/sql/query_summary.rb', line 11

def initialize(queries)
  @summary = {}
  queries.each do |payload|
    type = get_type(payload[:sql])
    next if QUERY_TYPES.exclude?(type) || pg_query?(payload[:sql])

    table = get_table(payload[:sql])
    @summary[type] ||= {}
    @summary[type][table] ||= 0
    @summary[type][table] += 1
  end
end

Instance Attribute Details

#summaryObject (readonly)

Returns the value of attribute summary.



9
10
11
# File 'lib/rspec/sql/query_summary.rb', line 9

def summary
  @summary
end