-
-
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.
- Loading branch information
Showing
7 changed files
with
61 additions
and
2 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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
# 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)] } | ||
|
||
before { session[:alchemy_language_id] = another_site_1_language.id } | ||
|
||
context "when language ID in session is associated with the current site" do | ||
it "sets @current_language" do | ||
get :index, params: { site_id: site_1.id } | ||
expect(assigns(:current_language)).to eq(another_site_1_language) | ||
end | ||
end | ||
|
||
context "when language ID in session is not associated with the current site" do | ||
it "sets @current_language to the current site default language" do | ||
get :index, params: { site_id: site_2.id } | ||
expect(assigns(:current_language)).to eq(site_2.default_language) | ||
end | ||
|
||
it "does not change the language ID in session" do | ||
expect { get :index, params: { site_id: site_2.id } }.not_to change { session[:alchemy_language_id] } | ||
end | ||
end | ||
|
||
context "when no language ID in session" do | ||
before { session[:alchemy_language_id] = nil } | ||
|
||
it "sets @current_language to language 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 |
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
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