Skip to content
Browse files

stop adding singleton methods to the PG connection

  • Loading branch information...
1 parent ffbefc7 commit cc04a4a9037cc91684a99a69d031c04bad1a1467 @tenderlove tenderlove committed Oct 4, 2013
Showing with 26 additions and 11 deletions.
  1. +26 −11 activerecord/test/cases/adapters/postgresql/connection_test.rb
View
37 activerecord/test/cases/adapters/postgresql/connection_test.rb
@@ -5,16 +5,31 @@ class PostgresqlConnectionTest < ActiveRecord::TestCase
class NonExistentTable < ActiveRecord::Base
end
+ class SQLSubscriber
+ attr_reader :logged
+
+ def initialize
+ @logged = []
+ end
+
+ def start(name, id, payload)
+ @logged << [payload[:sql], payload[:name], payload[:binds]]
+ end
+
+ def finish(name, id, payload)
+ end
+ end
+
def setup
super
+ @subscriber = SQLSubscriber.new
+ ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
@connection = ActiveRecord::Base.connection
- @connection.extend(LogIntercepter)
- @connection.intercepted = true
end
def teardown
- @connection.intercepted = false
- @connection.logged = []
+ ActiveSupport::Notifications.unsubscribe(@subscriber)
+ super
end
def test_encoding
@@ -47,38 +62,38 @@ def test_connection_options
def test_tables_logs_name
@connection.tables('hello')
- assert_equal 'SCHEMA', @connection.logged[0][1]
+ assert_equal 'SCHEMA', @subscriber.logged[0][1]
end
def test_indexes_logs_name
@connection.indexes('items', 'hello')
- assert_equal 'SCHEMA', @connection.logged[0][1]
+ assert_equal 'SCHEMA', @subscriber.logged[0][1]
end
def test_table_exists_logs_name
@connection.table_exists?('items')
- assert_equal 'SCHEMA', @connection.logged[0][1]
+ assert_equal 'SCHEMA', @subscriber.logged[0][1]
end
def test_table_alias_length_logs_name
@connection.instance_variable_set("@table_alias_length", nil)
@connection.table_alias_length
- assert_equal 'SCHEMA', @connection.logged[0][1]
+ assert_equal 'SCHEMA', @subscriber.logged[0][1]
end
def test_current_database_logs_name
@connection.current_database
- assert_equal 'SCHEMA', @connection.logged[0][1]
+ assert_equal 'SCHEMA', @subscriber.logged[0][1]
end
def test_encoding_logs_name
@connection.encoding
- assert_equal 'SCHEMA', @connection.logged[0][1]
+ assert_equal 'SCHEMA', @subscriber.logged[0][1]
end
def test_schema_names_logs_name
@connection.schema_names
- assert_equal 'SCHEMA', @connection.logged[0][1]
+ assert_equal 'SCHEMA', @subscriber.logged[0][1]
end
# Must have with_manual_interventions set to true for this

0 comments on commit cc04a4a

Please sign in to comment.
Something went wrong with that request. Please try again.