Skip to content

Commit 79adb87

Browse files
committed
Migrate applicable actionview tests to use NotificationAssertions
1 parent 6a62eed commit 79adb87

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

actionview/test/activerecord/partial_rendering_query_test.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,16 @@ def setup
77
@view = ActionView::Base
88
.with_empty_template_cache
99
.with_view_paths(ActionController::Base.view_paths, {})
10-
11-
@queries = []
12-
13-
@subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*, payload|
14-
@queries << payload[:sql] unless %w[ SCHEMA TRANSACTION ].include?(payload[:name])
15-
end
16-
end
17-
18-
def teardown
19-
ActiveSupport::Notifications.unsubscribe(@subscriber)
2010
end
2111

2212
def test_render_with_relation_collection
23-
@view.render partial: "topics/topic", collection: Topic.all
13+
notifications = capture_notifications("sql.active_record") do
14+
@view.render partial: "topics/topic", collection: Topic.all
15+
end
16+
17+
queries = notifications.filter_map { _1.payload[:sql] unless %w[ SCHEMA TRANSACTION ].include?(_1.payload[:name]) }
2418

25-
assert_equal 1, @queries.size
26-
assert_equal 'SELECT "topics".* FROM "topics"', @queries[0]
19+
assert_equal 1, queries.size
20+
assert_equal 'SELECT "topics".* FROM "topics"', queries[0]
2721
end
2822
end

0 commit comments

Comments
 (0)