2016-08-06 13:03:39 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "action_view"
|
|
|
|
require "action_controller"
|
2011-01-14 03:32:51 -05:00
|
|
|
|
|
|
|
class I18nTestMailer < ActionMailer::Base
|
|
|
|
configure do |c|
|
2016-08-06 13:03:39 -04:00
|
|
|
c.assets_dir = ""
|
2011-01-14 03:32:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def mail_with_i18n_subject(recipient)
|
2011-01-19 17:42:10 -05:00
|
|
|
@recipient = recipient
|
2011-01-14 03:32:51 -05:00
|
|
|
I18n.locale = :de
|
2014-05-12 23:43:26 -04:00
|
|
|
mail(to: recipient, subject: I18n.t(:email_subject),
|
2012-10-07 13:54:14 -04:00
|
|
|
from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
|
2011-01-14 03:32:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestController < ActionController::Base
|
|
|
|
def send_mail
|
2014-08-20 04:34:57 -04:00
|
|
|
email = I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver_now
|
2014-05-12 23:43:26 -04:00
|
|
|
render text: "Mail sent - Subject: #{email.subject}"
|
2011-01-14 03:32:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
Routes = ActionDispatch::Routing::RouteSet.new
|
|
|
|
Routes.draw do
|
2016-03-30 12:07:43 -04:00
|
|
|
ActiveSupport::Deprecation.silence do
|
2016-08-06 13:03:39 -04:00
|
|
|
get ":controller(/:action(/:id))"
|
2016-03-30 12:07:43 -04:00
|
|
|
end
|
2011-01-14 03:32:51 -05:00
|
|
|
end
|
|
|
|
|
2014-07-07 18:08:12 -04:00
|
|
|
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)
|
|
|
|
|
2011-01-14 03:32:51 -05:00
|
|
|
def app
|
2014-07-07 18:08:12 -04:00
|
|
|
APP
|
2011-01-14 03:32:51 -05:00
|
|
|
end
|
|
|
|
|
2014-06-06 12:52:24 -04:00
|
|
|
teardown do
|
|
|
|
I18n.locale = I18n.default_locale
|
|
|
|
end
|
|
|
|
|
2014-05-12 23:43:26 -04:00
|
|
|
def test_send_mail
|
2015-08-20 01:57:49 -04:00
|
|
|
stub_any_instance(Mail::SMTP, instance: Mail::SMTP.new({})) do |instance|
|
|
|
|
assert_called(instance, :deliver!) do
|
2016-08-06 13:03:39 -04:00
|
|
|
with_translation "de", email_subject: "[Anmeldung] Willkommen" do
|
2015-08-20 01:57:49 -04:00
|
|
|
ActiveSupport::Deprecation.silence do
|
2016-08-06 13:03:39 -04:00
|
|
|
get "/test/send_mail"
|
2015-08-20 01:57:49 -04:00
|
|
|
end
|
|
|
|
assert_equal "Mail sent - Subject: [Anmeldung] Willkommen", @response.body
|
|
|
|
end
|
2015-07-29 11:42:19 -04:00
|
|
|
end
|
2014-05-12 23:43:26 -04:00
|
|
|
end
|
2011-01-19 17:42:10 -05:00
|
|
|
end
|
2011-01-14 03:32:51 -05:00
|
|
|
|
2014-05-12 23:43:26 -04:00
|
|
|
protected
|
2011-01-14 03:32:51 -05:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
def with_translation(locale, data)
|
|
|
|
I18n.backend.store_translations(locale, data)
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
I18n.backend.reload!
|
|
|
|
end
|
2011-01-14 03:32:51 -05:00
|
|
|
end
|