Class: QueryMatchers::QueryCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/query_matchers/query_counter.rb

Constant Summary collapse

OPERATIONS =
%w(SELECT INSERT UPDATE DELETE)

Instance Method Summary collapse

Constructor Details

#initializeQueryCounter

Returns a new instance of QueryCounter.



5
6
7
# File 'lib/query_matchers/query_counter.rb', line 5

def initialize
  @events = []
end

Instance Method Details

#execute!(target) ⇒ Object



9
10
11
# File 'lib/query_matchers/query_counter.rb', line 9

def execute!(target)
  ActiveSupport::Notifications.subscribed(subscriber, 'sql.active_record', &target)
end

#queriesObject



17
18
19
# File 'lib/query_matchers/query_counter.rb', line 17

def queries
  @events.map {|event| event.payload[:sql] }
end

#query_countObject



13
14
15
# File 'lib/query_matchers/query_counter.rb', line 13

def query_count
  @events.size
end