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



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

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

Instance Attribute Details

#log_allObject (readonly)

Returns the value of attribute log_all.



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

def log_all
  @log_all
end

#log_fullObject (readonly)

Returns the value of attribute log_full.



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

def log_full
  @log_full
end

Instance Method Details

#call(payload) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/active_record/testing/query_assertions.rb', line 109

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



105
106
107
# File 'lib/active_record/testing/query_assertions.rb', line 105

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