49c4f2adc6
When ActiveStorage::Record uses `connects_to` for read replica support, it creates a separate connection pool from ApplicationRecord. This causes `after_commit` callbacks to fire in non-deterministic order - the Attachment's `create_variants` callback can fire before the User model's upload callback completes, resulting in FileNotFoundError. The fix removes replica connection configuration from ActiveStorage::Record so it shares the same connection pool as application models, ensuring proper callback ordering. Also reverts test workarounds that were added to work around this issue, since the root cause is now fixed. See: https://github.com/rails/rails/issues/53694
45 lines
1.4 KiB
Ruby
45 lines
1.4 KiB
Ruby
require "test_helper"
|
|
|
|
class Notification::BundleMailerTest < ActionMailer::TestCase
|
|
setup do
|
|
@user = users(:david)
|
|
|
|
@bundle = Notification::Bundle.create!(
|
|
user: @user,
|
|
starts_at: 1.hour.ago,
|
|
ends_at: 1.hour.from_now
|
|
)
|
|
end
|
|
|
|
test "renders avatar with initials in span when avatar is not attached" do
|
|
create_notification(@user)
|
|
|
|
email = Notification::BundleMailer.notification(@bundle)
|
|
|
|
assert_match /<span[^>]*class="avatar"[^>]*>/, email.html_part.body.to_s
|
|
assert_match /#{@user.initials}/, email.html_part.body.to_s
|
|
assert_match /style="background-color: #[A-F0-9]{6};?"/, email.html_part.body.to_s
|
|
end
|
|
|
|
test "renders avatar with external image URL when avatar is attached" do
|
|
@user.avatar.attach(
|
|
io: File.open(Rails.root.join("test", "fixtures", "files", "avatar.png")),
|
|
filename: "avatar.png",
|
|
content_type: "image/png"
|
|
)
|
|
|
|
create_notification(@user)
|
|
|
|
email = Notification::BundleMailer.notification(@bundle)
|
|
|
|
assert_match /<img[^>]*class="avatar"[^>]*>/, email.html_part.body.to_s
|
|
assert_match /<img[^>]*class="avatar"[^>]*src="[^"]*"/, email.html_part.body.to_s
|
|
assert_match /alt="#{@user.name}"/, email.html_part.body.to_s
|
|
end
|
|
|
|
private
|
|
def create_notification(user)
|
|
Notification.create!(user: user, creator: user, source: events(:logo_published), created_at: 30.minutes.ago)
|
|
end
|
|
end
|