Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # FABRICATION_SEQUENCE
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/fabrication-2.15.2/lib/fabrication/generator/base.rb:100:in `persist'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/fabrication-2.15.2/lib/fabrication/generator/base.rb:25:in `create'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/fabrication-2.15.2/lib/fabrication/schematic/definition.rb:78:in `block in fabricate'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/fabrication-2.15.2/lib/fabrication/schematic/definition.rb:77:in `instance_eval'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/fabrication-2.15.2/lib/fabrication/schematic/definition.rb:77:in `fabricate'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/fabrication-2.15.2/lib/fabricate.rb:33:in `create'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/fabrication-2.15.2/lib/fabrication.rb:65:in `Fabricate'
- # DATABASE_CLEANER_SEQUENCE
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/database_cleaner-1.5.3/lib/database_cleaner/active_record/transaction.rb:12:in `start'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/database_cleaner-1.5.3/lib/database_cleaner/base.rb:88:in `start'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:75:in `block in start'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:75:in `each'
- # /Users/larry1mbp/.rvm/gems/ruby-2.3.3@headmaster/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:75:in `start'
- # /Users/larry1mbp/605/headmaster-164/spec/support/database_cleaner_configuration.rb:22:in `block (2 levels) in <top (required)>'
- if ENV['DEBUG_QUERIES']
- BLACKLIST = %w(
- gems/actionpack
- gems/activemodel
- gems/activerecord
- gems/activesupport
- gems/capybara
- gems/delayed_job
- gems/grant
- gems/rack
- gems/rack-test
- gems/railties
- gems/rspec-rails
- gems/strongbolt
- headmaster/bin/
- headmaster/gems/rspec-core)
- @sequences = {
- fabrication: {
- text: 'FABRICATION SEQUENCE',
- lines: [
- 'fabrication/generator/base.rb:100',
- 'fabrication/generator/base.rb:25',
- 'fabrication/schematic/definition.rb:78',
- "fabrication/schematic/definition.rb:77:in `instance_eval'",
- "fabrication/schematic/definition.rb:77:in `fabricate'",
- 'fabricate.rb:33',
- 'fabrication.rb:65'
- ]
- },
- database_cleaner: {
- text: 'DATABASE CLEANER SEQUENCE',
- lines: [ 'database_cleaner/active_record/transaction.rb:12',
- 'database_cleaner/base.rb:88',
- "database_cleaner/configuration.rb:75:in `block in start'",
- "database_cleaner/configuration.rb:75:in `each'",
- "database_cleaner/configuration.rb:75:in `start'",
- 'support/database_cleaner_configuration.rb:22'
- ]
- }
- }
- @blacklist_re = []
- BLACKLIST.each do |token|
- @blacklist_re << Regexp.new(token)
- end
- # seq is @sequences[:some_symbol] so it is a hash
- # @seq_flag is :fabrication or :database_cleaner or nil
- @seq_flag = nil
- seq = {}
- line_just_rec = 99
- printed_suppression_indicator = false
- query_regex = /#{ENV['QUERY_TO_DEBUG']}/
- ActiveSupport::Notifications.subscribe('sql.active_record') do |_, _, _, _, details|
- # details[:sql] is the SQL statement
- # details[:binds] are the values substituted in
- # caller is the backtrace
- if details[:sql] =~ query_regex
- puts '*' * 50
- puts details[:sql]
- puts details[:binds].map {|bind| bind[1]}.join(', ')
- caller.each do |line|
- unless not_wanted(line)
- printed_suppression_indicator = false
- if @seq_flag # if we are in a sequence
- if this_is_next_line(seq, line_just_rec, line)
- line_just_rec += 1
- if this_is_last_line(seq, line_just_rec)
- puts sequence_text(seq)
- set_seq_flag(seq, false)
- end
- else # not next line
- flush_lines(seq, line_just_rec)
- puts "#{line}\n" # puts line as is (we thought sequence but no)
- end
- else # not in sequence
- # detect if a sequence is beginning
- seq_sym = first_line_of_sequence(line)
- if seq_sym
- seq = @sequences[seq_sym]
- set_seq_flag(seq, true)
- line_just_rec = 0
- else
- puts "#{line}\n" # 'normal' line
- end
- end
- else # not wanted
- unless printed_suppression_indicator
- puts "...."
- printed_suppression_indicator = true
- end
- end
- end
- end
- end
- def not_wanted(string)
- @blacklist_re.each do |re|
- if string =~ re
- return true
- end
- end
- false
- end
- def set_seq_flag(seq, tf)
- if tf
- @seq_flag = seq.keys.first
- else
- @seq_flag = nil
- end
- end
- def this_is_next_line(seq, line_just_rec, line)
- return line.include? seq[:lines][line_just_rec + 1]
- end
- def this_is_last_line(seq, line_just_rec)
- return (seq[:lines].length == line_just_rec + 1)
- end
- def flush_lines(seq, line_just_rec)
- puts "FLUSHING LINES"
- seq[:lines][0..line_just_rec].each do |line|
- puts "#{line}\n"
- end
- end
- def sequence_text(seq)
- seq[:text]
- end
- # returns which sequence it is the first line of
- # or false if it isn't one
- def first_line_of_sequence(line)
- @sequences.each do |k, v|
- if line.include? v[:lines][0]
- return k
- end
- end
- return false
- end
- end # if ENV DEBUG_QUERIES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement