Replacing granular admin email settings with one default email (#13853)

* Replaced granular emails with the default one

* Set reply to header in emails

* Extract shared_examples from NotifyMailer

* Removed unused code

* Replaced SiteConfig with Settings::General

* Fixes related to replacing SiteConfig with Settings

* Removed duplicate line from specs
This commit is contained in:
Anna Buianova 2021-05-28 12:17:08 +03:00 committed by GitHub
parent 8b92a5c1fd
commit 1862eb5cde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 115 additions and 191 deletions

View file

@ -73,7 +73,7 @@ module Admin
user = User.find(params[:id])
send_to_admin = params[:send_to_admin].to_boolean
if send_to_admin
email = ::Settings::General.email_addresses[:contact]
email = ::Settings::General.email_addresses[:default]
receiver = "admin"
else
email = user.email

View file

@ -24,7 +24,7 @@ class ApiSecretsController < ApplicationController
flash[:notice] = "Your API Key has been revoked."
else
flash[:error] =
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:contact]}"
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}"
end
redirect_back(fallback_location: root_path)

View file

@ -6,7 +6,7 @@ class ConfirmationsController < Devise::ConfirmationsController
self.resource = resource_class.send_confirmation_instructions(resource_params)
resource.errors.clear # Don't leak user information, like paranoid mode.
message = format(FLASH_MESSAGE, email: Settings::General.email_addresses[:members])
message = format(FLASH_MESSAGE, email: Settings::General.email_addresses[:default])
flash.now[:global_notice] = message
render :new
end

View file

@ -134,7 +134,7 @@ class UsersController < ApplicationController
def remove_identity
set_current_tab("account")
error_message = format(REMOVE_IDENTITY_ERROR, email: Settings::General.email_addresses[:contact])
error_message = format(REMOVE_IDENTITY_ERROR, email: Settings::General.email_addresses[:default])
unless Authentication::Providers.enabled?(params[:provider])
flash[:error] = error_message
redirect_to user_settings_path(@tab)

View file

@ -19,7 +19,7 @@ module Authentication
def message
format(PREVIOUSLY_SUSPENDED_MESSAGE,
community_name: Settings::Community.community_name,
community_email: Settings::General.email_addresses[:contact])
community_email: Settings::General.email_addresses[:default])
end
end
end

View file

@ -194,10 +194,8 @@ module ApplicationHelper
link_to body, collection.path, **kwargs
end
def email_link(type = :contact, text: nil, additional_info: nil)
# The allowed types for type are the keys of `Settings::General.email_addresses`
# :default, :contact, :business, :privacy, :members
email = Settings::General.email_addresses[type] || Settings::General.email_addresses[:contact]
def email_link(text: nil, additional_info: nil)
email = Settings::General.email_addresses[:default]
mail_to email, text || email, additional_info
end

View file

@ -12,6 +12,7 @@ class ApplicationMailer < ActionMailer::Base
default(
from: -> { email_from },
template_path: ->(mailer) { "mailers/#{mailer.class.name.underscore}" },
reply_to: -> { Settings::General.email_addresses[:default] },
)
def email_from(topic = "")

View file

@ -9,7 +9,7 @@ module ErrorMessages
def self.call(error_message)
return error_message unless error_message.match?(FRONTMATTER_ERROR)
format(REPLACEMENT_ERROR, Settings::General.email_addresses[:contact])
format(REPLACEMENT_ERROR, Settings::General.email_addresses[:default])
end
end
end

View file

@ -604,19 +604,6 @@
</div>
<input type="text" value="<%= ApplicationConfig["DEFAULT_EMAIL"] %>" class="form-control" readonly>
</div>
<%= f.fields_for :email_addresses do |email_field| %>
<% Settings::General.email_addresses.except(:default).each do |type, address| %>
<div class="crayons-field">
<%= admin_config_label type %>
<%= admin_config_description Constants::Settings::General::DETAILS[:email_addresses][:description] %>
<%= email_field.text_field type,
class: "crayons-textfield",
value: Settings::General.email_addresses[type],
placeholder: Constants::Settings::General::DETAILS[:email_addresses][:placeholder] %>
</div>
<% end %>
<% end %>
<%= render "form_submission", f: f %>
</fieldset>
</div>
</div>

View file

@ -12,7 +12,7 @@
</p>
<p>
Exporting the data to your admin account will send it to your contact
admin email (<%= Settings::General.email_addresses[:contact] %>),
admin email (<%= Settings::General.email_addresses[:default] %>),
and exporting to the user will send it to their email (<%= @user.email %>).
</p>
<div style="display: flex;">

View file

@ -47,7 +47,7 @@
</div>
<br />
</div>
<p class="bulk-description"><em>Contact <%= email_link(:business, additional_info: { subject: "Custom Bulk Pricing/Partnerships" }) %> for custom bulk pricing and partnerships.</em></p>
<p class="bulk-description"><em>Contact <%= email_link(additional_info: { subject: "Custom Bulk Pricing/Partnerships" }) %> for custom bulk pricing and partnerships.</em></p>
<details>
<summary>
How many credits does one listing cost?

View file

@ -9,7 +9,7 @@
Whoops! Did you get stuck trying to open the mobile app?
</p>
<p class="mt-5">
Make sure it's installed and try again. If the problem persists contact <a href="mailto:<%= Settings::General.email_addresses[:contact] %>"><%= Settings::General.email_addresses[:contact] %></a>
Make sure it's installed and try again. If the problem persists contact <a href="mailto:<%= Settings::General.email_addresses[:default] %>"><%= Settings::General.email_addresses[:contact] %></a>
</p>
</div>

View file

@ -75,7 +75,7 @@
<span class="timezone">America/New_York</span>
<span class="title"><%= event.title %></span>
<span class="organizer"><%= community_name %></span>
<span class="organizer_email"><%= Settings::General.email_addresses[:members] %></span>
<span class="organizer_email"><%= Settings::General.email_addresses[:default] %></span>
<span class="calname">dev-event</span>
<span class="location"><%= event.location_url %></span>
<span class="alarm_reminder">15</span>

View file

@ -1,6 +1,6 @@
Hi <%= @name %>, your account has been successfully deleted.
Contact us at <%= Settings::General.email_addresses[:contact] %> if there is anything more we can help with.
Contact us at <%= Settings::General.email_addresses[:default] %> if there is anything more we can help with.
Thanks,
The <%= community_name %> Team

View file

@ -20,7 +20,7 @@ When in doubt about how to exercise your new privileges, please ask! If these Co
Tag moderation is something we're continuously iterating on, so you can expect adjustments and expanding features over time as we receive feedback.
We regularly send out a biweekly Mod Newsletter to keep mods up to date on these changes, so look out for it!
Of course, don't hesitate to reach out to us at any moment if you have any feedback — feel free to write to <%= Settings::General.email_addresses[:contact] %> and share your thoughts.
Of course, don't hesitate to reach out to us at any moment if you have any feedback — feel free to write to <%= Settings::General.email_addresses[:default] %> and share your thoughts.
Thanks so much for volunteering your time to benefit <%= community_name %>. We sincerely appreciate your help!

View file

@ -14,7 +14,7 @@ You may occasionally receive notifications about optional moderation actions; pl
For details on all available features and how to access them, visit our <%= community_name %> Trusted User Guide: <%= app_url("/community-moderation") %>
If you have any questions or feedback for us, please write to <%= Settings::General.email_addresses[:contact] %> and share your thoughts.
If you have any questions or feedback for us, please write to <%= Settings::General.email_addresses[:default] %> and share your thoughts.
Thanks for being such an awesome member of the community!

View file

@ -79,7 +79,7 @@
Have feedback to improve your Mod experience?
</span>
<span>
Please email <%= Settings::General.email_addresses[:contact] %>!
Please email <%= Settings::General.email_addresses[:default] %>!
</span>
</div>
</aside>

View file

@ -3,6 +3,6 @@
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName><%= helper.community_name %> Search</ShortName>
<Description>Find posts from <%= helper.community_name %>.</Description>
<Contact><%= Settings::General.email_addresses[:contact] %></Contact>
<Contact><%= Settings::General.email_addresses[:default] %></Contact>
<Url type="text/html" template="<%= URL.url("search") %>?q={searchTerms}" />
</OpenSearchDescription>

View file

@ -132,14 +132,14 @@
</p>
<p><strong>Deleting Your Personal Information</strong>
<br>
You may request deletion of your personal information and account by emailing <%= email_link(:privacy) %>.
You may request deletion of your personal information and account by emailing <%= email_link %>.
<br>
<br>
To protect information from accidental or malicious destruction, we may maintain residual copies for a brief time period. But, if you delete your account, your information and content will be unrecoverable after that time.
</p>
<p><strong>Data Portability</strong>
<br>
If you would like to request a copy of your user data, please email <%= email_link(:privacy) %>.</p>
If you would like to request a copy of your user data, please email <%= email_link %>.</p>
<p><strong>Business Transfers</strong>
<br>
If we are involved in a merger, acquisition, bankruptcy, reorganization or sale of assets such that your information would be transferred or become subject to a different privacy policy, well notify you in advance of any such change.
@ -150,4 +150,4 @@
</p>
<p><strong>Questions</strong>
<br>
We welcome feedback about this policy at <%= email_link(:privacy) %>.</p>
We welcome feedback about this policy at <%= email_link %>.</p>

View file

@ -231,7 +231,7 @@
<% end %>
<p>
Questions? Email us at
<a href="<%= Settings::General.email_addresses[:contact] %>"><%= Settings::General.email_addresses[:contact] %></a>
<a href="<%= Settings::General.email_addresses[:default] %>"><%= Settings::General.email_addresses[:default] %></a>
for help.
</p>
</div>

View file

@ -1,16 +1,10 @@
module DataUpdateScripts
class UpdateDefaultEmailAddresses
def run
return if Settings::General.email_addresses[:contact].present?
return if Settings::General.email_addresses[:default].present?
# In order to trigger the attribute setter on the Settings::General hash object,
# it seems like we need to set all the values in the hash and not only the one we are changing.
Settings::General.email_addresses = {
default: Settings::General.email_addresses[:default],
business: Settings::General.email_addresses[:business],
privacy: Settings::General.email_addresses[:privacy],
members: Settings::General.email_addresses[:members],
contact: ApplicationConfig["DEFAULT_EMAIL"]
default: ApplicationConfig["DEFAULT_EMAIL"]
}
end
end

View file

@ -0,0 +1,9 @@
module DataUpdateScripts
class RemoveUnusedSiteConfigEmails
def run
Settings::General.email_addresses = {
default: ApplicationConfig["DEFAULT_EMAIL"]
}
end
end
end

View file

@ -158,16 +158,12 @@ RSpec.describe ApplicationHelper, type: :helper do
end
describe "#email_link" do
let(:contact_email) { "contact@dev.to" }
let(:default_email) { "hi@dev.to" }
before do
allow(Settings::General).to receive(:email_addresses).and_return(
{
default: "hi@dev.to",
contact: contact_email,
business: "business@dev.to",
privacy: "privacy@dev.to",
members: "members@dev.to"
default: default_email
},
)
end
@ -177,17 +173,12 @@ RSpec.describe ApplicationHelper, type: :helper do
end
it "sets the correct href" do
expect(helper.email_link).to have_link(href: "mailto:#{contact_email}")
expect(helper.email_link(:business)).to have_link(href: "mailto:business@dev.to")
expect(helper.email_link).to have_link(href: "mailto:#{default_email}")
end
it "has the correct text in the a tag" do
expect(helper.email_link(text: "Link Name")).to have_text("Link Name")
expect(helper.email_link).to have_text(contact_email)
end
it "returns the default email if it doesn't understand the type parameter" do
expect(helper.email_link(:nonsense)).to have_link(href: "mailto:#{contact_email}")
expect(helper.email_link).to have_text(default_email)
end
it "returns an href with additional_info parameters" do
@ -196,7 +187,7 @@ RSpec.describe ApplicationHelper, type: :helper do
body: "This is a longer body with a question mark ? \n and a newline"
}
link = "<a href=\"mailto:#{contact_email}?body=This%20is%20a%20longer%20body%20with%20a%20" \
link = "<a href=\"mailto:#{default_email}?body=This%20is%20a%20longer%20body%20with%20a%20" \
"question%20mark%20%3F%20%0A%20and%20a%20newline&amp;subject=This%20is%20a%20long%20subject\">text</a>"
expect(email_link(text: "text", additional_info: additional_info)).to eq(link)
end

View file

@ -0,0 +1,23 @@
require "rails_helper"
require Rails.root.join(
"lib/data_update_scripts/20210509105151_remove_unused_site_config_emails.rb",
)
describe DataUpdateScripts::RemoveUnusedSiteConfigEmails do
let(:contact_email) { "contact@dev.to" }
before do
Settings::General.email_addresses = {
default: ApplicationConfig["DEFAULT_EMAIL"],
contact: "contact@dev.to",
business: "business@dev.to",
privacy: "privacy@dev.to",
members: "members@dev.to"
}
end
it "removes the unused emails" do
described_class.new.run
expect(Settings::General.email_addresses.symbolize_keys).to eq(default: ApplicationConfig["DEFAULT_EMAIL"])
end
end

View file

@ -4,20 +4,8 @@ require Rails.root.join(
)
describe DataUpdateScripts::UpdateDefaultEmailAddresses do
let(:contact_email) { "contact@dev.to" }
context "with no contact email set in the email_addresses hash" do
it "adds the contact email" do
described_class.new.run
expect(Settings::General.email_addresses).to include(contact: ApplicationConfig["DEFAULT_EMAIL"])
end
end
context "with a contact email set in the email_addresses hash" do
it "preserves the current contact email" do
Settings::General.email_addresses[:contact] = contact_email
described_class.new.run
expect(Settings::General.email_addresses).to include(contact: contact_email)
end
it "adds the default email" do
described_class.new.run
expect(Settings::General.email_addresses).to include(default: ApplicationConfig["DEFAULT_EMAIL"])
end
end

View file

@ -11,17 +11,13 @@ RSpec.describe NotifyMailer, type: :mailer do
describe "#new_reply_email" do
let(:email) { described_class.with(comment: comment).new_reply_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expected_subject = "#{comment.user.name} replied to your #{comment.parent_type}"
expect(email.subject).to eq(expected_subject)
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([comment.user.email])
end
@ -32,16 +28,12 @@ RSpec.describe NotifyMailer, type: :mailer do
before { user2.follow(user) }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("#{user2.name} just followed you on #{Settings::Community.community_name}")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -52,48 +44,36 @@ RSpec.describe NotifyMailer, type: :mailer do
let(:comment_mention) { create(:mention, user: user2, mentionable: comment) }
let(:email) { described_class.with(mention: comment_mention).new_mention_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject and receiver", :aggregate_failures do
expect(email.subject).to eq("#{comment.user.name} just mentioned you in their comment")
expect(email.to).to eq([user2.email])
end
it "renders proper sender", :aggregate_failures do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
end
context "when mentioning in an article" do
let(:article_mention) { create(:mention, user: user2, mentionable: article) }
let(:email) { described_class.with(mention: article_mention).new_mention_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject and receiver", :aggregate_failures do
expect(email.subject).to eq("#{article.user.name} just mentioned you in their post")
expect(email.to).to eq([user2.email])
end
it "renders proper sender", :aggregate_failures do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
end
end
describe "#unread_notifications_email" do
let(:email) { described_class.with(user: user).unread_notifications_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("🔥 You have 0 unread notifications on #{Settings::Community.community_name}")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -102,16 +82,12 @@ RSpec.describe NotifyMailer, type: :mailer do
describe "#video_upload_complete_email" do
let(:email) { described_class.with(article: article).video_upload_complete_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("Your video upload is complete")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([article.user.email])
end
@ -135,16 +111,12 @@ RSpec.describe NotifyMailer, type: :mailer do
)
end
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("You just got a badge")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -277,16 +249,12 @@ RSpec.describe NotifyMailer, type: :mailer do
end
let(:email) { described_class.with(email_params).feedback_message_resolution_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("#{Settings::Community.community_name} Report Status Update")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -311,16 +279,12 @@ RSpec.describe NotifyMailer, type: :mailer do
describe "#feedback_response_email" do
let(:email) { described_class.with(email_to: user.email).feedback_response_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("Thanks for your report on #{Settings::Community.community_name}")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -340,16 +304,12 @@ RSpec.describe NotifyMailer, type: :mailer do
end
let(:email) { described_class.with(email_params).user_contact_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("Buddy")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -360,16 +320,12 @@ RSpec.describe NotifyMailer, type: :mailer do
let(:direct_message) { create(:message, user: user, chat_channel: direct_channel) }
let(:email) { described_class.with(message: direct_message).new_message_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("#{user.name} just messaged you")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([direct_message.direct_receiver.email])
end
@ -378,16 +334,12 @@ RSpec.describe NotifyMailer, type: :mailer do
describe "#account_deleted_email" do
let(:email) { described_class.with(name: user.name, email: user.email).account_deleted_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("#{Settings::Community.community_name} - Account Deletion Confirmation")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -398,16 +350,12 @@ RSpec.describe NotifyMailer, type: :mailer do
described_class.with(name: user.name, email: user.email, org_name: organization.name).organization_deleted_email
end
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("#{Settings::Community.community_name} - Organization Deletion Confirmation")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -416,16 +364,12 @@ RSpec.describe NotifyMailer, type: :mailer do
describe "#export_email" do
let(:email) { described_class.with(email: user.email, attachment: "attachment").export_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to include("export of your content is ready")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -446,16 +390,12 @@ RSpec.describe NotifyMailer, type: :mailer do
described_class.with(user: user, tag: tag, channel_slug: "javascript-4l67").tag_moderator_confirmation_email
end
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expect(email.subject).to eq("Congrats! You're the moderator for ##{tag.name}")
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -465,17 +405,13 @@ RSpec.describe NotifyMailer, type: :mailer do
let(:tag) { create(:tag) }
let(:email) { described_class.with(user: user).trusted_role_email }
include_examples "#renders_proper_email_headers"
it "renders proper subject" do
expected_subject = "Congrats! You're now a \"trusted\" user on #{Settings::Community.community_name}!"
expect(email.subject).to eq(expected_subject)
end
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
@ -505,6 +441,10 @@ RSpec.describe NotifyMailer, type: :mailer do
expect(member_email["from"].value).to eq(expected_from)
end
it "renders proper reply_to" do
expect(moderator_email["reply_to"].value).to eq(Settings::General.email_addresses[:default])
end
it "renders proper receiver" do
expect(moderator_email.to).to eq([user2.email])
expect(member_email.to).to eq([user2.email])

View file

@ -0,0 +1,11 @@
RSpec.shared_examples "#renders_proper_email_headers" do
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper reply_to" do
expect(email["reply_to"].value).to eq(Settings::General.email_addresses[:default])
end
end

View file

@ -36,6 +36,7 @@ Dir[Rails.root.join("spec/system/shared_examples/**/*.rb")].sort.each { |f| requ
Dir[Rails.root.join("spec/models/shared_examples/**/*.rb")].sort.each { |f| require f }
Dir[Rails.root.join("spec/workers/shared_examples/**/*.rb")].sort.each { |f| require f }
Dir[Rails.root.join("spec/initializers/shared_examples/**/*.rb")].sort.each { |f| require f }
Dir[Rails.root.join("spec/mailers/shared_examples/**/*.rb")].sort.each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.

View file

@ -278,25 +278,6 @@ RSpec.describe "/admin/customization/config", type: :request do
end
describe "Emails" do
it "updates email_addresses" do
expected_email_addresses = {
contact: "contact@example.com",
business: "partners@example.com",
privacy: "privacy@example.com",
members: "members@example.com"
}
post admin_config_path, params: {
settings_general: { email_addresses: expected_email_addresses },
confirmation: confirmation_message
}
expect(Settings::General.email_addresses[:contact]).to eq("contact@example.com")
expect(Settings::General.email_addresses[:business]).to eq("partners@example.com")
expect(Settings::General.email_addresses[:privacy]).to eq("privacy@example.com")
expect(Settings::General.email_addresses[:members]).to eq("members@example.com")
end
it "does not update the default email address" do
post admin_config_path, params: {
settings_general: { email_addresses: { default: "random@example.com" } },

View file

@ -401,7 +401,7 @@ RSpec.describe "UserSettings", type: :request do
expect(response).to redirect_to("/settings/account")
error =
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:contact]}"
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}"
expect(flash[:error]).to eq(error)
end
@ -444,7 +444,7 @@ RSpec.describe "UserSettings", type: :request do
delete users_remove_identity_path, params: { provider: provider }
error =
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:contact]}"
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}"
expect(flash[:error]).to eq(error)
end

View file

@ -8,7 +8,7 @@ RSpec.describe "/confirm-email", type: :system do
expect(page).to have_current_path(user_confirmation_path)
expected_message = format(ConfirmationsController::FLASH_MESSAGE,
email: Settings::General.email_addresses[:members])
email: Settings::General.email_addresses[:default])
expect(page).to have_content(expected_message)
end
end