From 9e28f415f5aa52a3179d7cbef2594a0d0c03bcce Mon Sep 17 00:00:00 2001 From: Sam Davies Date: Thu, 5 Nov 2015 17:44:47 -0300 Subject: Make tests a bit more beautiful --- activerecord/test/cases/hot_compatibility_test.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/hot_compatibility_test.rb b/activerecord/test/cases/hot_compatibility_test.rb index e97be4a2fc..9fc75b7377 100644 --- a/activerecord/test/cases/hot_compatibility_test.rb +++ b/activerecord/test/cases/hot_compatibility_test.rb @@ -64,6 +64,9 @@ class HotCompatibilityTest < ActiveRecord::TestCase record.reload end + assert get_prepared_statement_cache(@klass.connection).any?, + "expected prepared statement cache to have something in it" + # add a new column ddl_connection.add_column :hot_compatibilities, :baz, :string @@ -73,11 +76,7 @@ class HotCompatibilityTest < ActiveRecord::TestCase end end - prepared_statement_cache = @klass.connection - .instance_variable_get(:@statements) - .instance_variable_get(:@cache)[Process.pid] - - assert_empty prepared_statement_cache, + assert_empty get_prepared_statement_cache(@klass.connection), "expected prepared statement cache to be empty but it wasn't" end end @@ -91,6 +90,9 @@ class HotCompatibilityTest < ActiveRecord::TestCase record.reload end + assert get_prepared_statement_cache(@klass.connection).any?, + "expected prepared statement cache to have something in it" + # add a new column ddl_connection.add_column :hot_compatibilities, :baz, :string @@ -104,11 +106,7 @@ class HotCompatibilityTest < ActiveRecord::TestCase end end - prepared_statement_cache = @klass.connection - .instance_variable_get(:@statements) - .instance_variable_get(:@cache)[Process.pid] - - assert_empty prepared_statement_cache, + assert_empty get_prepared_statement_cache(@klass.connection), "expected prepared statement cache to be empty but it wasn't" end end @@ -116,6 +114,11 @@ class HotCompatibilityTest < ActiveRecord::TestCase private + def get_prepared_statement_cache(connection) + connection.instance_variable_get(:@statements) + .instance_variable_get(:@cache)[Process.pid] + end + # Rails will automatically clear the prepared statements on the connection # that runs the migration, so we use two connections to simulate what would # actually happen on a production system; we'd have one connection running the -- cgit v1.2.3