Class: RSpec::ActiveRecord::Expectations::QueryInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/activerecord/expectations/query_inspector.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.valid_query_typesObject



3
4
5
6
7
# File 'lib/rspec/activerecord/expectations/query_inspector.rb', line 3

def self.valid_query_types
  [:queries, :schema_queries, :insert_queries, :load_queries,
   :destroy_queries, :exists_queries,
   :transaction_queries, :commit_queries, :rollback_queries]
end

Instance Method Details

#categorize(query) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rspec/activerecord/expectations/query_inspector.rb', line 9

def categorize(query)
  if query[:name] == "SCHEMA"
    [:schema_queries]
  elsif query[:sql] =~ /^commit/i
    [:commit_queries]
  elsif query[:sql] =~ /^rollback/i
    [:rollback_queries]
  elsif query[:name] == "TRANSACTION"
    [:transaction_queries]
  elsif query[:name] =~ /Create$/
    [:queries, :insert_queries]
  elsif query[:name] =~ /Load$/
    [:queries, :load_queries]
  elsif query[:name] =~ /Destroy$/
    [:queries, :destroy_queries]
  elsif query[:name] =~ /Delete All$/
    [:queries, :destroy_queries]
  elsif query[:name] =~ /Exists\??$/
    [:queries, :exists_queries]
  else
    [:queries]
  end
end