Skip to content

A platform for community discussion. Free, open, simple.

DEV: fix flaky invite_mailer_spec test (#35664)

marstall060ba2ad94c6
diff --git a/spec/mailers/invite_mailer_spec.rb b/spec/mailers/invite_mailer_spec.rb
index fa3aa90e9f4..b8beca16486 100644
--- a/spec/mailers/invite_mailer_spec.rb
+++ b/spec/mailers/invite_mailer_spec.rb
@@ -76,26 +76,25 @@ RSpec.describe InviteMailer do
end
end
- # TODO: Very flaky test
- # 1) InviteMailer send_invite when inviting to site with template modifier allows plugins to customize the invite template
- # Failure/Error: expect(mail.subject).to eq("[Discourse] Custom Invite from Bruce Wayne (bruce0)")
-
- # expected: "[Discourse] Custom Invite from Bruce Wayne (bruce0)"
- # got: "[Discourse] Custom Invite from Bruce Wayne (bruce3)"
- skip "with template modifier" do
+ context "with template modifier" do
fab!(:invite)
let(:plugin) { Plugin::Instance.new }
let(:custom_template) { "plugin_custom_invite_template" }
- I18n.backend.store_translations(
- :en,
- {
- plugin_custom_invite_template: {
- subject_template: "[%{site_name}] Custom Invite from %{inviter_name}",
- text_body_template:
- "Custom invite body: %{invite_link}\n\nFrom: %{inviter_name}\nSite: %{site_domain_name}",
+ before do
+ I18n.backend.store_translations(
+ :en,
+ {
+ plugin_custom_invite_template: {
+ subject_template: "[%{site_name}] Custom Invite from %{inviter_name}",
+ text_body_template:
+ "Custom invite body: %{invite_link}\n\nFrom: %{inviter_name}\nSite: %{site_domain_name}",
+ },
},
- },
- )
+ )
+ end
+
+ after { I18n.backend.reload! }
+
it "allows plugins to customize the invite template" do
plugin_instance = Plugin::Instance.new
@modifier_block = Proc.new { |template, passed_invite| custom_template }
@@ -107,8 +106,13 @@ RSpec.describe InviteMailer do
)
mail = InviteMailer.send_invite(invite)
- expect(mail.subject).to eq("[Discourse] Custom Invite from Bruce Wayne (bruce0)")
-
+ expect(mail.subject).to eq(
+ I18n.t(
+ "#{custom_template}.subject_template",
+ site_name: "Discourse",
+ inviter_name: "#{invite.invited_by.name} (#{invite.invited_by.username})",
+ ),
+ )
DiscoursePluginRegistry.unregister_modifier(
plugin_instance,
:invite_forum_mailer_template,