1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionmailer/test/i18n_with_controller_test.rb
Ryuta Kamizono c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00

76 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require "abstract_unit"
require "action_view"
require "action_controller"
class I18nTestMailer < ActionMailer::Base
configure do |c|
c.assets_dir = ""
end
def mail_with_i18n_subject(recipient)
@recipient = recipient
I18n.locale = :de
mail(to: recipient, subject: I18n.t(:email_subject),
from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
end
end
class TestController < ActionController::Base
def send_mail
email = I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver_now
render plain: "Mail sent - Subject: #{email.subject}"
end
end
class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest
Routes = ActionDispatch::Routing::RouteSet.new
Routes.draw do
ActiveSupport::Deprecation.silence do
get ":controller(/:action(/:id))"
end
end
class RoutedRackApp
attr_reader :routes
def initialize(routes, &blk)
@routes = routes
@stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
end
def call(env)
@stack.call(env)
end
end
APP = RoutedRackApp.new(Routes)
def app
APP
end
teardown do
I18n.locale = I18n.default_locale
end
def test_send_mail
stub_any_instance(Mail::SMTP, instance: Mail::SMTP.new({})) do |instance|
assert_called(instance, :deliver!) do
with_translation "de", email_subject: "[Anmeldung] Willkommen" do
get "/test/send_mail"
assert_equal "Mail sent - Subject: [Anmeldung] Willkommen", @response.body
end
end
end
end
private
def with_translation(locale, data)
I18n.backend.store_translations(locale, data)
yield
ensure
I18n.backend.reload!
end
end