Skip to content

Commit 93de878

Browse files
authored
Merge pull request rails#54084 from larouxn/clean_up_notif_assert_tests
Clean up and improve a few notification asserting tests
2 parents decc5b5 + a0a9d98 commit 93de878

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

activerecord/test/cases/associations/eager_test.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,12 +1147,8 @@ def test_association_loading_notification
11471147
end
11481148

11491149
def test_base_messages
1150-
payload = capture_notifications("instantiation.active_record") do
1151-
Developer.all.to_a
1152-
end.first.payload
1153-
1154-
assert_equal Developer.all.to_a.count, payload[:record_count]
1155-
assert_equal Developer.name, payload[:class_name]
1150+
expected_payload = { record_count: Developer.all.to_a.count, class_name: Developer.name }
1151+
assert_notification("instantiation.active_record", expected_payload) { Developer.all.to_a }
11561152
end
11571153

11581154
def test_load_with_sti_sharing_association

activestorage/test/analyzer/audio_analyzer_test.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ class ActiveStorage::Analyzer::AudioAnalyzerTest < ActiveSupport::TestCase
1818
end
1919

2020
test "instrumenting analysis" do
21-
events = capture_notifications("analyze.active_storage") do
22-
assert_notifications_count("analyze.active_storage", 1) do
23-
blob = create_file_blob(filename: "audio.mp3", content_type: "audio/mp3")
21+
blob = create_file_blob(filename: "audio.mp3", content_type: "audio/mp3")
22+
23+
assert_notifications_count("analyze.active_storage", 1) do
24+
assert_notification("analyze.active_storage", analyzer: "ffprobe") do
2425
blob.analyze
2526
end
2627
end
27-
28-
assert_equal({ analyzer: "ffprobe" }, events.first.payload)
2928
end
3029
end

activestorage/test/analyzer/image_analyzer/image_magick_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ class ActiveStorage::Analyzer::ImageAnalyzer::ImageMagickTest < ActiveSupport::T
4747
end
4848

4949
test "instrumenting analysis" do
50-
analyze_with_image_magick do
51-
events = capture_notifications("analyze.active_storage") do
52-
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
53-
blob.analyze
54-
end
50+
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
5551

56-
assert_equal 1, events.size
57-
assert_equal({ analyzer: "mini_magick" }, events.first.payload)
52+
assert_notifications_count("analyze.active_storage", 1) do
53+
assert_notification("analyze.active_storage", analyzer: "mini_magick") do
54+
analyze_with_image_magick do
55+
blob.analyze
56+
end
57+
end
5858
end
5959
end
6060

activestorage/test/analyzer/video_analyzer_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ class ActiveStorage::Analyzer::VideoAnalyzerTest < ActiveSupport::TestCase
8787
end
8888

8989
test "instrumenting analysis" do
90-
events = capture_notifications("analyze.active_storage") do
91-
blob = create_file_blob(filename: "video_without_audio_stream.mp4", content_type: "video/mp4")
92-
blob.analyze
93-
end
90+
blob = create_file_blob(filename: "video.mp4", content_type: "video/mp4")
9491

95-
assert_equal 1, events.size
96-
assert_equal({ analyzer: "ffprobe" }, events.first.payload)
92+
assert_notifications_count("analyze.active_storage", 1) do
93+
assert_notification("analyze.active_storage", analyzer: "ffprobe") do
94+
blob.analyze
95+
end
96+
end
9797
end
9898
end

activesupport/test/cache/stores/memory_store_test.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,9 @@ def test_cleanup_instrumentation
4444
size = 3
4545
size.times { |i| @cache.write(i.to_s, i) }
4646

47-
events = capture_notifications("cache_cleanup.active_support") do
47+
assert_notification("cache_cleanup.active_support", size: size, store: @cache.class.name) do
4848
@cache.cleanup
4949
end
50-
51-
assert_equal %w[cache_cleanup.active_support], events.map(&:name)
52-
assert_equal size, events[0].payload[:size]
53-
assert_equal @cache.class.name, events[0].payload[:store]
5450
end
5551

5652
def test_nil_coder_bypasses_mutation_safeguard

0 commit comments

Comments
 (0)