aloha_analyzer 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -7
- data/aloha_analyzer.gemspec +2 -2
- data/lib/aloha_analyzer/{user.rb → base.rb} +38 -33
- data/lib/aloha_analyzer/facebook.rb +11 -0
- data/lib/aloha_analyzer/facebook_page.rb +39 -0
- data/lib/aloha_analyzer/language.rb +3 -3
- data/lib/aloha_analyzer/twitter.rb +11 -0
- data/lib/aloha_analyzer/version.rb +1 -1
- data/lib/aloha_analyzer/yaml/aliases.yml +83 -83
- data/lib/aloha_analyzer.rb +6 -3
- data/spec/aloha_analyzer/facebook_page_spec.rb +310 -0
- data/spec/aloha_analyzer/facebook_spec.rb +354 -0
- data/spec/aloha_analyzer/language_spec.rb +14 -14
- data/spec/aloha_analyzer/{user_spec.rb → twitter_spec.rb} +46 -46
- metadata +15 -8
@@ -0,0 +1,310 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AlohaAnalyzer::FacebookPage do
|
4
|
+
# {"tr_TR"=>3677, "en_US"=>89, "ka_GE"=>49, "en_GB"=>44, "az_AZ"=>39, "fr_FR"=>35, "bg_BG"=>28, "ru_RU"=>20, "de_DE"=>19, "ar_AR"=>8, "fr_CA"=>6, "es_LA"=>6, "nl_NL"=>4, "sq_AL"=>3, "pl_PL"=>2, "pt_BR"=>2, "es_ES"=>2, "it_IT"=>2, "lt_LT"=>1, "da_DK"=>1, "cs_CZ"=>1, "el_GR"=>1, "sr_RS"=>1, "et_EE"=>1, "mk_MK"=>1, "en_IN"=>1, "pt_PT"=>1, "jv_ID"=>1}
|
5
|
+
subject(:facebook_page) { described_class.new(options) }
|
6
|
+
let(:language) { 'en' }
|
7
|
+
let(:options) do
|
8
|
+
{
|
9
|
+
'language' => language,
|
10
|
+
'analysis' => analysis
|
11
|
+
}
|
12
|
+
end
|
13
|
+
let(:analysis) { nil }
|
14
|
+
|
15
|
+
describe '#new' do
|
16
|
+
context 'when language is british' do
|
17
|
+
let(:language) { 'en-gb' }
|
18
|
+
|
19
|
+
it 'changes to english' do
|
20
|
+
expect(subject.language).to eq 'en'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when language is simplified chinese' do
|
25
|
+
let(:language) { 'zh-cn' }
|
26
|
+
|
27
|
+
it 'changes to chinese' do
|
28
|
+
expect(subject.language).to eq 'zh'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when language is tradiational chinese' do
|
33
|
+
let(:language) { 'zh-tw' }
|
34
|
+
|
35
|
+
it 'changes to chinese' do
|
36
|
+
expect(subject.language).to eq 'zh'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when analysis is not nil' do
|
41
|
+
let(:analysis) { { foo: :bar } }
|
42
|
+
|
43
|
+
it 'sets the analysis to the argument' do
|
44
|
+
expect(subject.analysis).to eq analysis
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'clones the hash' do
|
48
|
+
expect(subject.analysis.object_id).not_to eq analysis.object_id
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when analysis is nil' do
|
53
|
+
let(:analysis) { nil }
|
54
|
+
|
55
|
+
it 'sets the analysis to the analysis boilerplate' do
|
56
|
+
expect(subject.analysis).to eq subject.boilerplate
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'clones the hash' do
|
60
|
+
expect(subject.analysis.object_id).not_to eq subject.boilerplate.object_id
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#analyze' do
|
66
|
+
subject(:results) { described_class.new(options).analyze(users) }
|
67
|
+
|
68
|
+
context 'when no users' do
|
69
|
+
let(:users) { {} }
|
70
|
+
|
71
|
+
it 'returns a hash' do
|
72
|
+
expect(subject).to be_a Hash
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'includes the total count' do
|
76
|
+
expect(subject['count']).to eq 0
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'has no results with the user language' do
|
80
|
+
expect(subject['account_language']['count']).to eq 0
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'has no results without the user language' do
|
84
|
+
expect(subject['foreign_languages']).to eq({})
|
85
|
+
expect(subject['foreign_languages_count']).to eq 0
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'includes the user lanugage' do
|
89
|
+
expect(subject['account_language']['language']).to eq(
|
90
|
+
'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when users' do
|
96
|
+
context 'and no aliases' do
|
97
|
+
let(:users) do
|
98
|
+
{
|
99
|
+
'en' => 2,
|
100
|
+
'fr' => 1,
|
101
|
+
'de' => 1
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns a hash' do
|
106
|
+
expect(subject).to be_a Hash
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'includes the total count' do
|
110
|
+
expect(subject['count']).to eq 4
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'includes the user lanugage' do
|
114
|
+
expect(subject['account_language']).to eq(
|
115
|
+
'count' => 2,
|
116
|
+
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia', 'greeting'=>'hello!'},
|
117
|
+
'users' => []
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'includs the foreign followers count' do
|
122
|
+
expect(subject['foreign_languages_count']).to eq 2
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns results based on the user language' do
|
126
|
+
expect(subject['foreign_languages']).to eq({
|
127
|
+
'fr' => {
|
128
|
+
'count' => 1,
|
129
|
+
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>45000000, 'countries'=>'France, Canada, Belgium, Switzerland'},
|
130
|
+
'users' => []
|
131
|
+
},
|
132
|
+
'de' => {
|
133
|
+
'count' => 1,
|
134
|
+
'language' => {'abbreviation'=>'de', 'name'=>'German', 'greeting'=>'hallo!', 'population'=>30000000, 'countries'=>'Germany, Austria, Switzerland, Belgium'},
|
135
|
+
'users' => []
|
136
|
+
}
|
137
|
+
})
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when only user langugages users' do
|
142
|
+
let(:users) do
|
143
|
+
{
|
144
|
+
'en' => 2
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'returns a hash' do
|
149
|
+
expect(subject).to be_a Hash
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'includes the total count' do
|
153
|
+
expect(subject['count']).to eq 2
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'includes the user lanugage' do
|
157
|
+
expect(subject['account_language']['language']).to eq(
|
158
|
+
'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns results based on the user language' do
|
163
|
+
expect(subject['account_language']).to eq({
|
164
|
+
'count' => 2,
|
165
|
+
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>360000000, 'countries' => 'USA, UK, Canada, Ireland, Australia', 'greeting'=>'hello!'},
|
166
|
+
'users' => []
|
167
|
+
})
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'returns results results based on the non user language' do
|
171
|
+
expect(subject['foreign_languages']).to eq({})
|
172
|
+
expect(subject['foreign_languages_count']).to eq 0
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when no users language users' do
|
177
|
+
let(:users) do
|
178
|
+
{
|
179
|
+
'de' => 1,
|
180
|
+
'fr' => 2
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'returns a hash' do
|
185
|
+
expect(subject).to be_a Hash
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'includes the total count' do
|
189
|
+
expect(subject['count']).to eq 3
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'returns results based on the user language' do
|
193
|
+
expect(subject['account_language']).to eq({
|
194
|
+
'count' => 0,
|
195
|
+
'language' => {'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'},
|
196
|
+
'users' => []
|
197
|
+
})
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'includes the correct foreign_languages_count' do
|
201
|
+
expect(subject['foreign_languages_count']).to eq 3
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'returns results results based on the non user language' do
|
205
|
+
expect(subject['foreign_languages']).to eq(
|
206
|
+
'fr' => {
|
207
|
+
'count' => 2,
|
208
|
+
'language' => { 'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>45000000, 'countries' => 'France, Canada, Belgium, Switzerland' },
|
209
|
+
'users' => []
|
210
|
+
},
|
211
|
+
'de' => {
|
212
|
+
'count' => 1,
|
213
|
+
'language' => {'abbreviation'=>'de', 'name'=>'German', 'greeting'=>'hallo!', 'population'=>30000000, 'countries' => 'Germany, Austria, Switzerland, Belgium' },
|
214
|
+
'users' => []
|
215
|
+
}
|
216
|
+
)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'when aliases' do
|
221
|
+
let(:users) do
|
222
|
+
{
|
223
|
+
'en' => 1,
|
224
|
+
'en_US' => 1,
|
225
|
+
'fr' => 1
|
226
|
+
}
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'includes the total count' do
|
230
|
+
expect(subject['count']).to eq 3
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'includes the user lanugage' do
|
234
|
+
expect(subject['account_language']).to eq({
|
235
|
+
'count' => 2,
|
236
|
+
'language' => { 'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia' },
|
237
|
+
'users' => []
|
238
|
+
})
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'includes the correct foreign_languages_count' do
|
242
|
+
expect(subject['foreign_languages_count']).to eq 1
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'merges english and british' do
|
246
|
+
expect(subject['foreign_languages']).to eq(
|
247
|
+
'fr' => {
|
248
|
+
'count' => 1,
|
249
|
+
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>45000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
250
|
+
'users' => []
|
251
|
+
}
|
252
|
+
)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'when existing analysis' do
|
258
|
+
let(:users) do
|
259
|
+
{
|
260
|
+
'en' => 1,
|
261
|
+
'fr' => 1
|
262
|
+
}
|
263
|
+
end
|
264
|
+
|
265
|
+
let(:analysis) do
|
266
|
+
{
|
267
|
+
'account_language' => {
|
268
|
+
'count' => 2,
|
269
|
+
'language' => { 'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia' },
|
270
|
+
'users' => []
|
271
|
+
},
|
272
|
+
'foreign_languages_count' => 1,
|
273
|
+
'count' => 3,
|
274
|
+
'foreign_languages' => {
|
275
|
+
'fr' => {
|
276
|
+
'count' => 1,
|
277
|
+
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>45000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
278
|
+
'users' => []
|
279
|
+
}
|
280
|
+
}
|
281
|
+
}
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'starts from the existing analysis' do
|
285
|
+
expect(subject).to eq(
|
286
|
+
'account_language' => {
|
287
|
+
'count' => 3,
|
288
|
+
'language' => {'abbreviation'=>'en', 'greeting'=>'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'},
|
289
|
+
'users' => []
|
290
|
+
},
|
291
|
+
'foreign_languages_count' => 2,
|
292
|
+
'count' => 5,
|
293
|
+
'foreign_languages' => {
|
294
|
+
'fr' => {
|
295
|
+
'count' => 2,
|
296
|
+
'language' => {
|
297
|
+
'abbreviation' => 'fr',
|
298
|
+
'name' => 'French',
|
299
|
+
'greeting' => 'bonjour!',
|
300
|
+
'population' => 45000000,
|
301
|
+
'countries' => 'France, Canada, Belgium, Switzerland'
|
302
|
+
},
|
303
|
+
'users' => []
|
304
|
+
}
|
305
|
+
}
|
306
|
+
)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
@@ -0,0 +1,354 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AlohaAnalyzer::Facebook do
|
4
|
+
subject(:facebook) { described_class.new(options) }
|
5
|
+
let(:language) { 'en' }
|
6
|
+
let(:options) do
|
7
|
+
{
|
8
|
+
'language' => language,
|
9
|
+
'analysis' => analysis
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:analysis) { nil }
|
13
|
+
|
14
|
+
describe '#new' do
|
15
|
+
context 'when language is british' do
|
16
|
+
let(:language) { 'en-gb' }
|
17
|
+
|
18
|
+
it 'changes to english' do
|
19
|
+
expect(subject.language).to eq 'en'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when language is simplified chinese' do
|
24
|
+
let(:language) { 'zh-cn' }
|
25
|
+
|
26
|
+
it 'changes to chinese' do
|
27
|
+
expect(subject.language).to eq 'zh'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when language is tradiational chinese' do
|
32
|
+
let(:language) { 'zh-tw' }
|
33
|
+
|
34
|
+
it 'changes to chinese' do
|
35
|
+
expect(subject.language).to eq 'zh'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when analysis is not nil' do
|
40
|
+
let(:analysis) { { foo: :bar } }
|
41
|
+
|
42
|
+
it 'sets the analysis to the argument' do
|
43
|
+
expect(subject.analysis).to eq analysis
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'clones the hash' do
|
47
|
+
expect(subject.analysis.object_id).not_to eq analysis.object_id
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when analysis is nil' do
|
52
|
+
let(:analysis) { nil }
|
53
|
+
|
54
|
+
it 'sets the analysis to the analysis boilerplate' do
|
55
|
+
expect(subject.analysis).to eq subject.boilerplate
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'clones the hash' do
|
59
|
+
expect(subject.analysis.object_id).not_to eq subject.boilerplate.object_id
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#analyze' do
|
65
|
+
subject(:results) { described_class.new(options).analyze(users) }
|
66
|
+
context 'when no users' do
|
67
|
+
let(:users) { [] }
|
68
|
+
|
69
|
+
it 'returns a hash' do
|
70
|
+
expect(subject).to be_a Hash
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'includes the total count' do
|
74
|
+
expect(subject['count']).to eq 0
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'has no results with the user language' do
|
78
|
+
expect(subject['account_language']['count']).to eq 0
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'has no results without the user language' do
|
82
|
+
expect(subject['foreign_languages']).to eq({})
|
83
|
+
expect(subject['foreign_languages_count']).to eq 0
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'includes the user lanugage' do
|
87
|
+
expect(subject['account_language']['language']).to eq(
|
88
|
+
'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when users' do
|
94
|
+
context 'and no aliases' do
|
95
|
+
let(:users) {
|
96
|
+
[
|
97
|
+
{'id' => '1', 'locale' => 'en'},
|
98
|
+
{'id' => '2', 'locale' => 'fr'},
|
99
|
+
{'id' => '3', 'locale' => 'en'},
|
100
|
+
{'id' => '4', 'locale' => 'de'}
|
101
|
+
]
|
102
|
+
}
|
103
|
+
|
104
|
+
it 'returns a hash' do
|
105
|
+
expect(subject).to be_a Hash
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'includes the total count' do
|
109
|
+
expect(subject['count']).to eq 4
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'includes the user lanugage' do
|
113
|
+
expect(subject['account_language']).to eq(
|
114
|
+
'count' => 2,
|
115
|
+
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia', 'greeting'=>'hello!'},
|
116
|
+
'users' => [{'id' => '1', 'locale' => 'en'}, {'id' => '3', 'locale' => 'en'}]
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'includs the foreign followers count' do
|
121
|
+
expect(subject['foreign_languages_count']).to eq 2
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'returns results based on the user language' do
|
125
|
+
expect(subject['foreign_languages']).to eq({
|
126
|
+
'fr' => {
|
127
|
+
'count' => 1,
|
128
|
+
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>45000000, 'countries'=>'France, Canada, Belgium, Switzerland'},
|
129
|
+
'users' => [{'id' => '2', 'locale' => 'fr'}]
|
130
|
+
},
|
131
|
+
'de' => {
|
132
|
+
'count' => 1,
|
133
|
+
'language' => {'abbreviation'=>'de', 'name'=>'German', 'greeting'=>'hallo!', 'population'=>30000000, 'countries'=>'Germany, Austria, Switzerland, Belgium'},
|
134
|
+
'users' => [{'id' => '4', 'locale' => 'de'}]
|
135
|
+
}
|
136
|
+
})
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'when only user langugages users' do
|
141
|
+
let(:users) {
|
142
|
+
[
|
143
|
+
{'id' => '1', 'locale' => 'en'},
|
144
|
+
{'id' => '2', 'locale' => 'en'}
|
145
|
+
]
|
146
|
+
}
|
147
|
+
|
148
|
+
it 'returns a hash' do
|
149
|
+
expect(subject).to be_a Hash
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'includes the total count' do
|
153
|
+
expect(subject['count']).to eq 2
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'includes the user lanugage' do
|
157
|
+
expect(subject['account_language']['language']).to eq(
|
158
|
+
'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns results based on the user language' do
|
163
|
+
expect(subject['account_language']).to eq({
|
164
|
+
'count' => 2,
|
165
|
+
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>360000000, 'countries' => 'USA, UK, Canada, Ireland, Australia', 'greeting'=>'hello!'},
|
166
|
+
'users' => [{'id' => '1', 'locale' => 'en'}, {'id' => '2', 'locale' => 'en'}]
|
167
|
+
})
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'returns results results based on the non user language' do
|
171
|
+
expect(subject['foreign_languages']).to eq({})
|
172
|
+
expect(subject['foreign_languages_count']).to eq 0
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when no users language users' do
|
177
|
+
let(:users) {
|
178
|
+
[
|
179
|
+
{'id' => '1', 'locale' => 'de'},
|
180
|
+
{'id' => '2', 'locale' => 'fr'},
|
181
|
+
{'id' => '3', 'locale' => 'fr'}
|
182
|
+
]
|
183
|
+
}
|
184
|
+
|
185
|
+
it 'returns a hash' do
|
186
|
+
expect(subject).to be_a Hash
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'includes the total count' do
|
190
|
+
expect(subject['count']).to eq 3
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'returns results based on the user language' do
|
194
|
+
expect(subject['account_language']).to eq({
|
195
|
+
'count' => 0,
|
196
|
+
'language' => {'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'},
|
197
|
+
'users' => []
|
198
|
+
})
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'includes the correct foreign_languages_count' do
|
202
|
+
expect(subject['foreign_languages_count']).to eq 3
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'returns results results based on the non user language' do
|
206
|
+
expect(subject['foreign_languages']).to eq(
|
207
|
+
'fr' => {
|
208
|
+
'count' => 2,
|
209
|
+
'language' => { 'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>45000000, 'countries' => 'France, Canada, Belgium, Switzerland' },
|
210
|
+
'users' => [{'id' => '2', 'locale' => 'fr'}, {'id' => '3', 'locale' => 'fr'}]
|
211
|
+
},
|
212
|
+
'de' => {
|
213
|
+
'count' => 1,
|
214
|
+
'language' => {'abbreviation'=>'de', 'name'=>'German', 'greeting'=>'hallo!', 'population'=>30000000, 'countries' => 'Germany, Austria, Switzerland, Belgium' },
|
215
|
+
'users' => [{'id' => '1', 'locale' => 'de'}]
|
216
|
+
}
|
217
|
+
)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'when aliases' do
|
222
|
+
let(:users) {
|
223
|
+
[
|
224
|
+
{'id' => '1', 'locale' => 'en'},
|
225
|
+
{'id' => '2', 'locale' => 'fr'},
|
226
|
+
{'id' => '3', 'locale' => 'en_US'}
|
227
|
+
]
|
228
|
+
}
|
229
|
+
|
230
|
+
it 'includes the total count' do
|
231
|
+
expect(subject['count']).to eq 3
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'includes the user lanugage' do
|
235
|
+
expect(subject['account_language']).to eq({
|
236
|
+
'count' => 2,
|
237
|
+
'language' => { 'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia' },
|
238
|
+
'users' => [{'id' => '1', 'locale' => 'en'}, {'id' => '3', 'locale' => 'en'}]
|
239
|
+
})
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'includes the correct foreign_languages_count' do
|
243
|
+
expect(subject['foreign_languages_count']).to eq 1
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'merges english and british' do
|
247
|
+
expect(subject['foreign_languages']).to eq(
|
248
|
+
'fr' => {
|
249
|
+
'count' => 1,
|
250
|
+
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>45000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
251
|
+
'users' => [{'id' => '2', 'locale' => 'fr'}]
|
252
|
+
}
|
253
|
+
)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'when user limit per language' do
|
259
|
+
let(:options) do
|
260
|
+
{
|
261
|
+
'language' => language,
|
262
|
+
'analysis' => analysis,
|
263
|
+
'max_users' => 1
|
264
|
+
}
|
265
|
+
end
|
266
|
+
let(:users) {
|
267
|
+
[
|
268
|
+
{'id' => '1', 'locale' => 'en'},
|
269
|
+
{'id' => '2', 'locale' => 'fr'},
|
270
|
+
{'id' => '3', 'locale' => 'en'},
|
271
|
+
{'id' => '4', 'locale' => 'fr'},
|
272
|
+
{'id' => '5', 'locale' => 'fr'}
|
273
|
+
]
|
274
|
+
}
|
275
|
+
|
276
|
+
it 'limits the number of account language users to 1' do
|
277
|
+
expect(subject['account_language']['users'].size).to eq 1
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'limits the number of foreign languages users to 1' do
|
281
|
+
expect(subject['foreign_languages']['fr']['users'].size).to eq 1
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'does not affect the account language count' do
|
285
|
+
expect(subject['account_language']['count']).to eq 2
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'does not affect the foreign_languages_count' do
|
289
|
+
expect(subject['foreign_languages_count']).to eq 3
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'does not affect the total count' do
|
293
|
+
expect(subject['count']).to eq 5
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'does not affect a foreign language count' do
|
297
|
+
expect(subject['foreign_languages']['fr']['count']).to eq 3
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context 'when existing analysis' do
|
302
|
+
let(:users) {
|
303
|
+
[
|
304
|
+
{'id' => '4', 'locale' => 'en'},
|
305
|
+
{'id' => '5', 'locale' => 'fr'}
|
306
|
+
]
|
307
|
+
}
|
308
|
+
|
309
|
+
let(:analysis) do
|
310
|
+
{
|
311
|
+
'account_language' => {
|
312
|
+
'count' => 2,
|
313
|
+
'language' => { 'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia' },
|
314
|
+
'users' => [{'id' => '1', 'locale' => 'en'}, {'id' => '3', 'locale' => 'en'}]
|
315
|
+
},
|
316
|
+
'foreign_languages_count' => 1,
|
317
|
+
'count' => 3,
|
318
|
+
'foreign_languages' => {
|
319
|
+
'fr' => {
|
320
|
+
'count' => 1,
|
321
|
+
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>45000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
322
|
+
'users' => [{'id' => '2', 'locale' => 'fr'}]
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'starts from the existing analysis' do
|
329
|
+
expect(subject).to eq(
|
330
|
+
'account_language' => {
|
331
|
+
'count' => 3,
|
332
|
+
'language' => {'abbreviation'=>'en', 'greeting'=>'hello!', 'name'=>'English', 'population'=>360000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'},
|
333
|
+
'users' => [{'id'=>'1', 'locale'=>'en'}, {'id'=>'3', 'locale'=>'en'}, {'id'=>'4', 'locale'=>'en'}]
|
334
|
+
},
|
335
|
+
'foreign_languages_count' => 2,
|
336
|
+
'count' => 5,
|
337
|
+
'foreign_languages' => {
|
338
|
+
'fr' => {
|
339
|
+
'count' => 2,
|
340
|
+
'language' => {
|
341
|
+
'abbreviation' => 'fr',
|
342
|
+
'name' => 'French',
|
343
|
+
'greeting' => 'bonjour!',
|
344
|
+
'population' => 45000000,
|
345
|
+
'countries' => 'France, Canada, Belgium, Switzerland'
|
346
|
+
},
|
347
|
+
'users' => [{'id'=>'2', 'locale'=>'fr'}, {'id'=>'5', 'locale'=>'fr'}]
|
348
|
+
}
|
349
|
+
}
|
350
|
+
)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|