Class: ActiveRecord::Assertions::QueryAssertions::SQLCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/testing/query_assertions.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSQLCounter

Returns a new instance of SQLCounter.



94
95
96
97
# File 'lib/active_record/testing/query_assertions.rb', line 94

def initialize
  @log_full = []
  @log_all = []
end

Instance Attribute Details

#log_allObject (readonly)

Returns the value of attribute log_all.



92
93
94
# File 'lib/active_record/testing/query_assertions.rb', line 92

def log_all
  @log_all
end

#log_fullObject (readonly)

Returns the value of attribute log_full.



92
93
94
# File 'lib/active_record/testing/query_assertions.rb', line 92

def log_full
  @log_full
end

Instance Method Details

#call(payload) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/active_record/testing/query_assertions.rb', line 103

def call(*, payload)
  return if payload[:cached]

  sql = payload[:sql]
  @log_all << sql

  unless payload[:name] == "SCHEMA"
    bound_values = (payload[:binds] || []).map do |value|
      value = value.value_for_database if value.respond_to?(:value_for_database)
      value
    end

    @log_full << [sql, bound_values]
  end
end

#logObject



99
100
101
# File 'lib/active_record/testing/query_assertions.rb', line 99

def log
  @log_full.map(&:first)
end