-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathi18n_localization_adapter_spec.rb
83 lines (62 loc) · 2.3 KB
/
i18n_localization_adapter_spec.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require "spec_helper"
require 'test_doubles'
describe LightService::I18n::LocalizationAdapter do
let(:action_class) { TestDoubles::AnAction }
let(:adapter) { described_class.new }
describe "#failure" do
subject { adapter.failure(message_or_key, action_class) }
context "when provided a Symbol" do
let(:message_or_key) { :not_found }
it "translates the message" do
expected_scope = "test_doubles/an_action.light_service.failures"
expect(I18n).to receive(:t)
.with(message_or_key, :scope => expected_scope)
.and_return("message")
expect(subject).to eq("message")
end
it "allows passing interpolation options to I18n layer" do
expect(I18n).to receive(:t)
.with(message_or_key, hash_including(:i18n_variable => "value"))
.and_return("message")
subject = adapter.failure(message_or_key,
action_class,
:i18n_variable => "value")
expect(subject).to eq("message")
end
end
context "when provided a String" do
let(:message_or_key) { "action failed" }
it "returns the message" do
expect(subject).to eq(message_or_key)
end
end
end
describe "#success" do
subject { adapter.success(message_or_key, action_class) }
context "when provided a Symbol" do
let(:message_or_key) { :not_found }
it "translates the message" do
expected_scope = "test_doubles/an_action.light_service.successes"
expect(I18n).to receive(:t)
.with(message_or_key, :scope => expected_scope)
.and_return("message")
expect(subject).to eq("message")
end
it "allows passing interpolation options to I18n layer" do
expect(I18n).to receive(:t)
.with(message_or_key, hash_including(:i18n_variable => "value"))
.and_return("message")
subject = adapter.success(message_or_key,
action_class,
:i18n_variable => "value")
expect(subject).to eq("message")
end
end
context "when provided a String" do
let(:message_or_key) { "action failed" }
it "returns the message" do
expect(subject).to eq(message_or_key)
end
end
end
end