Skip to content

Commit 2dda06f

Browse files
committed
specs: add spec for switch_lang action
1 parent 0145656 commit 2dda06f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe ApplicationController do
4+
describe '#switch_lang' do
5+
let(:original_locale) { I18n.locale }
6+
7+
before do
8+
request.env["HTTP_REFERER"] = root_path
9+
end
10+
11+
after do
12+
I18n.locale = original_locale
13+
end
14+
15+
it 'switches locale to passed language via params' do
16+
new_locale = (I18n.available_locales - [original_locale]).sample
17+
18+
expect do
19+
get :switch_lang, locale: new_locale
20+
end.to change(I18n, :locale).from(original_locale).to(new_locale)
21+
22+
expect(response).to redirect_to(root_path)
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)