home_controller_spec.rb
1.12 KB
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
require 'rails_helper'
describe HomeController, :type => :controller do
context 'Method' do
context '#index' do
before :each do
Project.expects(:latest).with(5).returns([])
end
describe 'Rendering' do
before :each do
get :index
end
it {is_expected.to render_template(:index)}
end
describe 'Language auto-detection' do
it 'should automatically use the language specified in the request headers' do
request.env['HTTP_ACCEPT_LANGUAGE'] = 'pt-BR'
get :index
expect(I18n.locale).to eq(:pt)
end
it 'should use a different region if still the best match' do
request.env['HTTP_ACCEPT_LANGUAGE'] = 'en-GB'
get :index
expect(I18n.locale).to eq(:en)
end
it 'should use the default language if no available language matches the requested one' do
request.env['HTTP_ACCEPT_LANGUAGE'] = 'de'
get :index
expect(I18n.locale).to eq(:en)
end
after do
I18n.locale = I18n.default_locale
end
end
end
end
end