-
-
Notifications
You must be signed in to change notification settings - Fork 315
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 #2973 from AlchemyCMS/backport/7.1-stable/pr-2957
[7.1-stable] Clear current language when switching sites
- Loading branch information
Showing
6 changed files
with
50 additions
and
0 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
33 changes: 33 additions & 0 deletions
33
lib/alchemy/test_support/current_language_shared_examples.rb
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples_for "a controller that loads current language" do |args| | ||
context "when session has current language id key" do | ||
let!(:site_1) { create(:alchemy_site) } | ||
let!(:site_1_default_language) { create :alchemy_language, site: site_1, default: true } | ||
let!(:another_site_1_language) { create :alchemy_language, site: site_1, code: :de } | ||
let(:site_2) { create :alchemy_site, host: "another.host", languages: [build(:alchemy_language, code: :en), build(:alchemy_language, code: :de)] } | ||
|
||
context "on index action" do | ||
context "when switching the current site" do | ||
before do | ||
session[:alchemy_site_id] = site_1.id | ||
session[:alchemy_language_id] = another_site_1_language.id | ||
end | ||
|
||
it "sets @current_language to the new site default language" do | ||
get :index, params: {site_id: site_2.id} | ||
expect(assigns(:current_language)).to eq site_2.default_language | ||
end | ||
end | ||
|
||
context "when no language to set" do | ||
it "shows flash warning with redirect" do | ||
Alchemy::Language.destroy_all | ||
get :index, params: {site_id: site_1.id} | ||
expect(flash[:warning]).to eq Alchemy.t("Please create a language first.") | ||
expect(response).to redirect_to admin_languages_path | ||
end | ||
end | ||
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
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