Skip to content

Commit cdb429b

Browse files
committed
Migrate applicable activestorage tests to use NotificationAssertions
1 parent 6a62eed commit cdb429b

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

activestorage/test/analyzer/audio_analyzer_test.rb

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

2020
test "instrumenting analysis" do
21-
events = subscribe_events_from("analyze.active_storage")
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")
24+
blob.analyze
25+
end
26+
end
2227

23-
blob = create_file_blob(filename: "audio.mp3", content_type: "audio/mp3")
24-
blob.analyze
25-
26-
assert_equal 1, events.size
2728
assert_equal({ analyzer: "ffprobe" }, events.first.payload)
2829
end
2930
end

activestorage/test/analyzer/image_analyzer/image_magick_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class ActiveStorage::Analyzer::ImageAnalyzer::ImageMagickTest < ActiveSupport::T
4848

4949
test "instrumenting analysis" do
5050
analyze_with_image_magick do
51-
events = subscribe_events_from("analyze.active_storage")
52-
53-
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
54-
blob.analyze
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
5555

5656
assert_equal 1, events.size
5757
assert_equal({ analyzer: "mini_magick" }, events.first.payload)

activestorage/test/analyzer/image_analyzer/vips_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class ActiveStorage::Analyzer::ImageAnalyzer::VipsTest < ActiveSupport::TestCase
4848

4949
test "instrumenting analysis" do
5050
analyze_with_vips do
51-
events = subscribe_events_from("analyze.active_storage")
52-
53-
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
54-
blob.analyze
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
5555

5656
assert_equal 1, events.size
5757
assert_equal({ analyzer: "vips" }, events.first.payload)

activestorage/test/analyzer/video_analyzer_test.rb

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

8989
test "instrumenting analysis" do
90-
events = subscribe_events_from("analyze.active_storage")
91-
92-
blob = create_file_blob(filename: "video_without_audio_stream.mp4", content_type: "video/mp4")
93-
blob.analyze
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
9494

9595
assert_equal 1, events.size
9696
assert_equal({ analyzer: "ffprobe" }, events.first.payload)

activestorage/test/test_helper.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ def with_raise_on_open_redirects(service)
114114
ActionController::Base.raise_on_open_redirects = old_raise_on_open_redirects
115115
ActiveStorage::Blob.service = old_service
116116
end
117-
118-
def subscribe_events_from(name)
119-
events = []
120-
ActiveSupport::Notifications.subscribe(name) { |event| events << event }
121-
events
122-
end
123117
end
124118

125119
require "global_id"

0 commit comments

Comments
 (0)