spec/spec_helper.rb in deferring-0.2.1 vs spec/spec_helper.rb in deferring-0.3.0
- old
+ new
@@ -3,11 +3,10 @@
require 'support/models/person'
require 'support/models/team'
require 'support/models/issue'
require 'support/models/address'
require 'support/models/non_validated_issue'
-require 'support/rails_versions'
RSpec.configure do |config|
config.disable_monkey_patching!
config.run_all_when_everything_filtered = true
@@ -25,7 +24,19 @@
ActiveRecord::Base.transaction do
example.run
raise ActiveRecord::Rollback
end
end
+end
+# Catch queries executed within the &block
+def catch_queries(&block)
+ queries = []
+ callback = lambda { |name, start, finish, id, payload|
+ queries << payload[:sql] if payload[:sql] =~ /^SELECT|UPDATE|INSERT/
+ }
+
+ result = ActiveSupport::Notifications.subscribed(callback, 'sql.active_record') do
+ yield
+ end
+ [result, queries]
end