View difference between Paste ID: MdgGbXTC and afBmK7dA
SHOW: | | - or go back to the newest paste.
1
require 'rails_helper'
2
3-
RSpec.describe ApplicationController do
3+
describe ApplicationController do
4
  controller do
5
    def index
6
      render text: 'nothing'
7
    end
8
  end
9
10-
  let(:user_ip) { '88.198.169.232' }
10+
  context '#geocode_locale' do
11-
  let(:country) { 'Germany' }
11+
    let(:user_ip) { '88.198.169.232' }
12-
  let(:locale) { 'de' }
12+
    let(:country) { 'Germany' }
13
    let(:locale) { 'de' }
14-
  describe 'set locale by ip' do
14+
15-
    context "when user from Germany" do
15+
    before do
16
      controller.stub(:ip).and_return user_ip
17-
        expect(controller).to receive(:ip).and_return user_ip
17+
18
19-
      it "should write :de in session locale" do
19+
    context 'locale set in session' do
20-
        expect{
20+
21
        session[:locale] = locale
22-
        }.to change{ I18n.locale }.to locale.to_sym
22+
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