View difference between Paste ID: LrPNj0HU and 5kMfuLUG
SHOW: | | - or go back to the newest paste.
1
require 'rails_helper'
2
3
describe ApplicationController do
4
  controller do
5
    def index
6
      render text: 'nothing'
7
    end
8
  end
9
10
  context '#geocode_locale' do
11
    let(:user_ip) { 'ip' }
12-
    let(:country) { 'country' }
12+
    let(:country) { double country: 'country' }
13
    let(:locale) { 'locale' }
14
15
    before do
16
      controller.stub(:ip).and_return user_ip
17
    end
18
19
    context 'locale set in session' do
20
      before do
21
        session[:locale] = locale
22
      end
23
24
      it 'should not change locale' do
25
        expect(Geocoder).not to_receive(:search)
26
        expect do
27
          get :index
28
        end.not_to change { session[:locale] }
29
      end
30
    end
31
32
    context 'locale is not in session yet' do
33
      it 'should get country and change session' do
34
        expect(Geocoder).to receive(:search).with(user_ip).
35
                              and_return([country])
36
        expect(I18nData).to receive(:country_code).with(country).
37
                              and_return(locale)
38
39
        expect do
40
          get :index
41
        end.to change { session[:locale] }.to locale.to_sym
42
      end
43
    end
44
  end
45
end