Skip to content

Commit

Permalink
Update locale code spec
Browse files Browse the repository at this point in the history
  • Loading branch information
virolea committed Sep 2, 2024
1 parent fe82261 commit b0f4c9b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/assets/builds/rosetta/application.css

Large diffs are not rendered by default.

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-zA-Z]+(-[a-zA-Z]+)?\z/
CODE_FORMAT = /\A[a-z]+(-[A-Z]+)?\z/

validates :name, :code, presence: true
validates :code, uniqueness: true
Expand Down
6 changes: 3 additions & 3 deletions app/views/rosetta/locales/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

<div>
<%= f.label :name, class: "label" %>
<%= f.text_field :name, class: "input max-w-xs", required: true %>
<%= f.text_field :name, placeholder: "E.g. French", class: "input max-w-xs", required: true %>
</div>

<div>
<%= f.label :code, class: "label" %>
<%= f.text_field :code, class: "input max-w-24", required: true %>
<%= f.text_field :code, placeholder: "E.g. fr, en-GB", class: "input max-w-28", required: true %>
<p class="mt-1 text-sm leading-6 text-gray-600">
Must only contain letters separated by an optional dash, e.g. <span class="badge">en-GB</span>.
Downcase letters followed by an optional region specifier in uppercase letters, separated by a dash. E.g. <span class="badge">fr</span> or <span class="badge">en-GB</span>.
</p>
</div>

Expand Down
2 changes: 1 addition & 1 deletion test/models/rosetta/locale_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ 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_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 b0f4c9b

Please sign in to comment.