Created
October 14, 2015 13:45
-
-
Save wconrad/094c2adc97f88f8352d2 to your computer and use it in GitHub Desktop.
Monkey-patching an ActiveRecord connection to test a query optimization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "does only one query" do | |
connection = Dest::Base.connection | |
def connection.query_count | |
@query_count || 0 | |
end | |
def connection.exec_query(*args) | |
@query_count ||= 0 | |
@query_count += 1 | |
super | |
end | |
migration_tracker.unless_migrated(source_row_1) {} | |
migration_tracker.unless_migrated(source_row_2) {} | |
expect(connection.query_count).to eq 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment