-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2626 from jhawthorn/frontend_locale_set
Make frontend's LocaleController compatible with solidus_i18n
- Loading branch information
Showing
5 changed files
with
82 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Spree::LocaleController, type: :controller do | ||
include_context "fr locale" | ||
|
||
context 'switch_to_locale specified' do | ||
context "available locale" do | ||
it 'sets locale and redirects' do | ||
get :set, params: { switch_to_locale: 'fr' } | ||
expect(I18n.locale).to eq :fr | ||
expect(response).to redirect_to('/') | ||
expect(session[:locale]).to eq('fr') | ||
expect(flash[:notice]).to eq(I18n.t("spree.locale_changed")) | ||
end | ||
end | ||
|
||
context "unavailable locale" do | ||
it 'does not change locale and redirects' do | ||
get :set, params: { switch_to_locale: 'klingon' } | ||
expect(I18n.locale).to eq :en | ||
expect(response).to redirect_to('/') | ||
expect(flash[:error]).to eq(I18n.t("spree.locale_not_changed")) | ||
end | ||
end | ||
end | ||
|
||
context 'locale specified' do | ||
context "available locale" do | ||
it 'sets locale and redirects' do | ||
get :set, params: { locale: 'fr' } | ||
expect(I18n.locale).to eq :fr | ||
expect(response).to redirect_to('/') | ||
expect(flash[:notice]).to eq(I18n.t("spree.locale_changed")) | ||
end | ||
end | ||
|
||
context "unavailable locale" do | ||
it 'does not change locale and redirects' do | ||
get :set, params: { locale: 'klingon' } | ||
expect(I18n.locale).to eq :en | ||
expect(response).to redirect_to('/') | ||
expect(flash[:error]).to eq(I18n.t("spree.locale_not_changed")) | ||
end | ||
end | ||
end | ||
|
||
context 'both locale and switch_to_locale specified' do | ||
it 'uses switch_to_locale value' do | ||
get :set, params: { locale: 'en', switch_to_locale: 'fr' } | ||
expect(I18n.locale).to eq :fr | ||
expect(response).to redirect_to('/') | ||
expect(flash[:notice]).to eq(I18n.t("spree.locale_changed")) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
shared_context 'fr locale' do | ||
before do | ||
I18n.backend.store_translations(:fr, spree: { | ||
i18n: { this_file_language: "Français" }, | ||
cart: 'Panier', | ||
shopping_cart: 'Panier' | ||
}) | ||
end | ||
|
||
after do | ||
I18n.reload! | ||
end | ||
end |