diff --git a/app/models/mailer.rb b/app/models/mailer.rb index dfd2737ab..9c409af69 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -272,6 +272,7 @@ class Mailer < ActionMailer::Base # Overrides default deliver! method to prevent from sending an email # with no recipient, cc or bcc def deliver!(mail = @mail) + set_language_if_valid @initial_language return false if (recipients.nil? || recipients.empty?) && (cc.nil? || cc.empty?) && (bcc.nil? || bcc.empty?) @@ -313,6 +314,7 @@ class Mailer < ActionMailer::Base private def initialize_defaults(method_name) super + @initial_language = current_language set_language_if_valid Setting.default_language from Setting.mail_from diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index dfc6caf88..fbbff1a03 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -20,7 +20,7 @@ require File.dirname(__FILE__) + '/../test_helper' class MailerTest < ActiveSupport::TestCase include Redmine::I18n include ActionController::Assertions::SelectorAssertions - fixtures :projects, :issues, :users, :members, :member_roles, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories + fixtures :projects, :enabled_modules, :issues, :users, :members, :member_roles, :roles, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories def test_generated_links_in_emails ActionMailer::Base.deliveries.clear @@ -296,4 +296,18 @@ class MailerTest < ActiveSupport::TestCase assert_not_nil mail mail end + + def test_mailer_should_not_change_locale + Setting.default_language = 'en' + # Set current language to italian + set_language_if_valid 'it' + # Send an email to a french user + user = User.find(1) + user.language = 'fr' + Mailer.deliver_account_activated(user) + mail = ActionMailer::Base.deliveries.last + assert mail.body.include?('Votre compte') + + assert_equal :it, current_language + end end