Skip to content

Commit

Permalink
Backup default locale session fallback with a test
Browse files Browse the repository at this point in the history
  • Loading branch information
virolea committed Sep 3, 2024
1 parent 68bdb8c commit 186a322
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rosetta/locale_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def locale=(value)
when Locale
@locale = value
when String, Symbol
@locale = Locale.find_by(code: value) || Locale.default
@locale = Locale.find_by(code: value) || Locale.default_locale
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/lib/rosetta/locale_session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ class Rosetta::LocaleSessionTest < ActiveSupport::TestCase
session.locale = locale
assert_equal locale, session.locale
end

test "assigning a non-existing locale fallbacks to the default locale" do
session = Rosetta::LocaleSession.new
session.locale = "non-existing"
assert_equal Rosetta::Locale.default_locale, session.locale
end
end

0 comments on commit 186a322

Please sign in to comment.