Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in language from session w/o site #1769

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/alchemy/controller_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def load_alchemy_language_from_params
# Load language from session if it's present on current site.
# Otherwise return nil so we can load the default language from current site.
def load_alchemy_language_from_session
if session[:alchemy_language_id].present?
if session[:alchemy_language_id].present? && Site.current
Site.current.languages.find_by(id: session[:alchemy_language_id])
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/libraries/controller_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@
expect(Alchemy::Language.current).to eq(klingon)
end

context "if no current site exists" do
before do
expect(Alchemy::Site).to receive(:current).exactly(:twice) { nil }
end

it "should set the default language" do
controller.send :set_alchemy_language

expect(assigns(:language)).to eq(default_language)
expect(Alchemy::Language.current).to eq(default_language)
end
end

context "if the language is not on the current site" do
let(:french_site) do
create(:alchemy_site, host: 'french.fr')
Expand Down