Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rails_helper'
- describe ApplicationController do
- controller do
- def index
- render text: 'nothing'
- end
- end
- context '#geocode_locale' do
- let(:user_ip) { 'ip' }
- let(:country) { double country: 'country' }
- let(:locale) { 'locale' }
- before do
- controller.stub(:ip).and_return user_ip
- end
- context 'locale set in session' do
- before do
- session[:locale] = locale
- end
- it 'should not change locale' do
- expect(Geocoder).not to_receive(:search)
- expect do
- get :index
- end.not_to change { session[:locale] }
- end
- end
- context 'locale is not in session yet' do
- it 'should get country and change session' do
- expect(Geocoder).to receive(:search).with(user_ip).
- and_return([country])
- expect(I18nData).to receive(:country_code).with(country).
- and_return(locale)
- expect do
- get :index
- end.to change { session[:locale] }.to locale.to_sym
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement