Skip to content

Commit

Permalink
Update valid locale code rules
Browse files Browse the repository at this point in the history
  • Loading branch information
virolea committed Sep 10, 2024
1 parent 529ffa3 commit db08b9b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/rosetta/locale.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rosetta
class Locale < ApplicationRecord
CODE_FORMAT = /\A[a-z]+(-[A-Z]+)?\z/
CODE_FORMAT = /\A[a-zA-Z]+(-[a-zA-Z]+)?\z/

validates :name, :code, presence: true
validates :code, uniqueness: true
Expand Down
3 changes: 2 additions & 1 deletion test/models/rosetta/locale_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class Rosetta::LocaleTest < ActiveSupport::TestCase

test "code format" do
assert Rosetta::Locale.new(name: "English", code: "en").valid?
assert Rosetta::Locale.new(name: "English", code: "EN").valid?
assert Rosetta::Locale.new(name: "English", code: "en-GB").valid?
assert_not Rosetta::Locale.new(name: "English", code: "EN").valid?
assert Rosetta::Locale.new(name: "English", code: "EN-gb").valid?
assert_not Rosetta::Locale.new(name: "English", code: "en-GB-UK").valid?
assert_not Rosetta::Locale.new(name: "English", code: "qw12").valid?
end
Expand Down

0 comments on commit db08b9b

Please sign in to comment.