Skip to content

Commit 712644f

Browse files
Implement specs that test setting of locale cookie and if it is correctly set and read
1 parent c49e16a commit 712644f

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Diff for: spec/controllers/people_controller_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@
2323
expect(people(:bob).reload.nationality2).to eql("DE")
2424
end
2525
end
26+
27+
describe 'handling of locale' do
28+
it 'it should correctly set locale cookie' do
29+
# Check if locale cookie is not set by default
30+
get :index, params: {locale: :fr}
31+
expect(response.cookies['locale']).to be_nil
32+
33+
# Check if locale cookie is set if it is changed by user
34+
get :index, params: {locale: :fr, set_by_user: true}
35+
expect(response.cookies['locale']).to eql('fr')
36+
37+
# Cookie should not be changed if user requests page with other locale
38+
get :index, params: {locale: :en}
39+
expect(response.cookies['locale']).to be_nil
40+
end
41+
end
2642
end

Diff for: spec/features/routing_spec.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@
2929
context "Set locale via dropdown" do
3030
before(:each) do
3131
visit people_path
32-
select 'Italiano', from: "i18n_language"
3332
end
3433

3534
it "Should open profile with correct language and preserve language in cookie" do
36-
# Simulate revisit without a locale in the url
35+
select 'Italiano', from: "i18n_language"
36+
37+
select_from_slim_select("#person_id_person", bob.name)
38+
expect(page).to have_text("Dati personali")
39+
40+
# Visiting page with locale explicitly defined in route should use locale from route
41+
visit '/en/'
42+
select_from_slim_select("#person_id_person", bob.name)
43+
expect(page).to have_text("Personal details")
44+
45+
# Simulate revisit without a locale in the url, which should use locale from cookie
3746
visit '/'
3847

3948
select_from_slim_select("#person_id_person", bob.name)

0 commit comments

Comments
 (0)