-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
translation_test.rb
69 lines (56 loc) · 1.85 KB
/
translation_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require "test_helper"
class TranslationTest < ActiveSupport::TestCase
class I18nExample < Noticed::Event
deliver_by :test do |config|
config.message = -> { t("hello") }
end
def message
t("hello")
end
def html_message
t("message_html")
end
end
class Noticed::I18nExample < Noticed::Event
def message
t(".message")
end
end
class ::ScopedI18nExample < Noticed::Event
def i18n_scope
:noticed
end
def message
t(".message")
end
end
test "I18n support" do
assert_equal "hello", I18nExample.new.send(:scope_translation_key, "hello")
assert_equal "Hello world", I18nExample.new.message
end
test "I18n supports namespaces" do
assert_equal "notifiers.noticed.i18n_example.message", Noticed::I18nExample.new.send(:scope_translation_key, ".message")
assert_equal "This is a notification", Noticed::I18nExample.new.message
end
test "I18n supports custom scopes" do
assert_equal "noticed.scoped_i18n_example.message", ScopedI18nExample.new.send(:scope_translation_key, ".message")
assert_equal "This is a custom scoped translation", ScopedI18nExample.new.message
end
if defined?(ActiveSupport::HtmlSafeTranslation)
test "I18n supports html safe translations" do
message = I18nExample.new.html_message
assert_equal "<p>Hello world</p>", message
assert message.html_safe?
end
end
test "delivery method blocks can use translations" do
block = I18nExample.delivery_methods[:test].config[:message]
assert_equal "Hello world", noticed_notifications(:one).instance_exec(&block)
end
test "ephemeral translations" do
assert_equal "Hello world", EphemeralNotifier.new.t("hello")
end
test "ephemeral notification translations" do
assert_equal "Hello world", EphemeralNotifier::Notification.new.t("hello")
end
end