Skip to content

Commit

Permalink
Merge pull request #14524 from tgxworld/fix_unsubscribe_from_notifica…
Browse files Browse the repository at this point in the history
…tions

Fix tests not unsubscribing from Notifications.
  • Loading branch information
senny committed Mar 29, 2014
2 parents 66b42a6 + 0212a41 commit 0b33c06
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions activerecord/test/cases/adapters/mysql2/connection_test.rb
Expand Up @@ -4,12 +4,12 @@ class MysqlConnectionTest < ActiveRecord::TestCase
def setup
super
@subscriber = SQLSubscriber.new
ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
@subscription = ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
@connection = ActiveRecord::Base.connection
end

def teardown
ActiveSupport::Notifications.unsubscribe(@subscriber)
ActiveSupport::Notifications.unsubscribe(@subscription)
super
end

Expand Down
Expand Up @@ -8,12 +8,12 @@ class NonExistentTable < ActiveRecord::Base
def setup
super
@subscriber = SQLSubscriber.new
ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
@subscription = ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
@connection = ActiveRecord::Base.connection
end

def teardown
ActiveSupport::Notifications.unsubscribe(@subscriber)
ActiveSupport::Notifications.unsubscribe(@subscription)
super
end

Expand Down
Expand Up @@ -23,7 +23,7 @@ def setup
eosql

@subscriber = SQLSubscriber.new
ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
@subscription = ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
end

def test_bad_connection
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_invalid_column
end

def teardown
ActiveSupport::Notifications.unsubscribe(@subscriber)
ActiveSupport::Notifications.unsubscribe(@subscription)
super
end

Expand Down
12 changes: 6 additions & 6 deletions activerecord/test/cases/bind_parameter_test.rb
Expand Up @@ -20,13 +20,13 @@ def call(*args)
def setup
super
@connection = ActiveRecord::Base.connection
@listener = LogListener.new
@subscriber = LogListener.new
@pk = Topic.columns.find { |c| c.primary }
ActiveSupport::Notifications.subscribe('sql.active_record', @listener)
@subscription = ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
end

teardown do
ActiveSupport::Notifications.unsubscribe(@listener)
ActiveSupport::Notifications.unsubscribe(@subscription)
end

if ActiveRecord::Base.connection.supports_statement_cache?
Expand All @@ -37,7 +37,7 @@ def test_binds_are_logged

@connection.exec_query(sql, 'SQL', binds)

message = @listener.calls.find { |args| args[4][:sql] == sql }
message = @subscriber.calls.find { |args| args[4][:sql] == sql }
assert_equal binds, message[4][:binds]
end

Expand All @@ -48,14 +48,14 @@ def test_binds_are_logged_after_type_cast

@connection.exec_query(sql, 'SQL', binds)

message = @listener.calls.find { |args| args[4][:sql] == sql }
message = @subscriber.calls.find { |args| args[4][:sql] == sql }
assert_equal [[@pk, 3]], message[4][:binds]
end

def test_find_one_uses_binds
Topic.find(1)
binds = [[@pk, 1]]
message = @listener.calls.find { |args| args[4][:binds] == binds }
message = @subscriber.calls.find { |args| args[4][:binds] == binds }
assert message, 'expected a message with binds'
end

Expand Down

0 comments on commit 0b33c06

Please sign in to comment.