forked from glebm/i18n-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelative_keys_spec.rb
152 lines (128 loc) · 4.02 KB
/
relative_keys_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# frozen_string_literal: true
require 'spec_helper'
require 'i18n/tasks/scanners/relative_keys'
class RelativeKeysUser
include ::I18n::Tasks::Scanners::RelativeKeys
def config
{}
end
end
RSpec.describe 'Relative keys' do
let(:relative_keys) { RelativeKeysUser.new }
describe 'absolute_key' do
context 'default settings' do
it 'works' do
expect(relative_keys.absolute_key('.title', 'app/views/movies/show.html.slim',
roots: %w[app/views])).to eq('movies.show.title')
end
end
context 'custom roots' do
it 'works' do
expect(relative_keys.absolute_key('.title', 'app/views-mobile/movies/show.html.slim',
roots: %w[app/views app/views-mobile])).to eq('movies.show.title')
end
end
context 'relative key in controller' do
it 'works' do
key = relative_keys.absolute_key(
'.success',
'app/controllers/users_controller.rb',
roots: %w[app/controllers],
calling_method: 'create'
)
expect(key).to eq('users.create.success')
end
context 'multiple words in controller name' do
it 'works' do
key = relative_keys.absolute_key(
'.success',
'app/controllers/admin_users_controller.rb',
roots: %w[app/controllers],
calling_method: 'create'
)
expect(key).to eq('admin_users.create.success')
end
end
context 'nested in module' do
it 'works' do
key = relative_keys.absolute_key(
'.success',
'app/controllers/nested/users_controller.rb',
roots: %w[app/controllers],
calling_method: 'create'
)
expect(key).to eq('nested.users.create.success')
end
end
end
context 'relative key in mailer' do
it 'works' do
key = relative_keys.absolute_key(
'.subject',
'app/mailers/user_mailer.rb',
roots: %w[app/mailers],
calling_method: 'welcome'
)
expect(key).to eq('user_mailer.welcome.subject')
end
context 'multiple words in mailer name' do
it 'works' do
key = relative_keys.absolute_key(
'.subject',
'app/mailers/admin_user_mailer.rb',
roots: %w[app/mailers],
calling_method: 'welcome'
)
expect(key).to eq('admin_user_mailer.welcome.subject')
end
end
context 'nested in module' do
it 'works' do
key = relative_keys.absolute_key(
'.subject',
'app/mailers/nested/user_mailer.rb',
roots: %w[app/mailers],
calling_method: 'welcome'
)
expect(key).to eq('nested.user_mailer.welcome.subject')
end
end
end
context 'using exclude_method_name_paths' do
it 'works' do
key = relative_keys.absolute_key(
'.subject',
'app/mailers/user_mailer.rb',
roots: %w[app/mailers],
exclude_method_name_paths: %w[app/mailers],
calling_method: 'welcome'
)
expect(key).to eq('user_mailer.subject')
end
context 'multiple words in file name' do
it 'works' do
key = relative_keys.absolute_key(
'.subject',
'app/mailers/admin_user_mailer.rb',
roots: %w[app/mailers],
exclude_method_name_paths: %w[app/mailers],
calling_method: 'welcome'
)
expect(key).to eq('admin_user_mailer.subject')
end
end
context 'nested in module' do
it 'works' do
key = relative_keys.absolute_key(
'.subject',
'app/mailers/nested/user_mailer.rb',
roots: %w[app/mailers],
exclude_method_name_paths: %w[app/mailers],
calling_method: 'welcome'
)
expect(key).to eq('nested.user_mailer.subject')
end
end
end
end
end