Skip to content

Commit

Permalink
add test for db pluralisation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielveleba committed May 26, 2020
1 parent 51001ad commit 8a0fbc3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions spec/fast_gettext/translation_repository/db_spec.rb
Expand Up @@ -36,9 +36,9 @@
@rep = FastGettext::TranslationRepository::Db.new('x', :model=>TranslationKey)
end

def create_translation(key, text)
def create_translation(key, text, locale = "de")
translation_key = TranslationKey.create!(:key => key)
TranslationText.create!(:translation_key_id => translation_key.id, :text => text, :locale => "de")
TranslationText.create!(:translation_key_id => translation_key.id, :text => text, :locale => locale)
end

it "reads locales from the db" do
Expand Down Expand Up @@ -71,6 +71,26 @@ def create_translation(key, text)
@rep.plural('Axis','Axis').should == ['Achse','Achsen']
end

it 'can pluralize with rule on model' do
class TranslationKey < ActiveRecord::Base
def self.pluralisation_rule
case FastGettext.locale
when 'en'
->(n) { (n == 1) ? 0 : 1 }
when 'cz'
->(n) { (n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2; }
else
nil
end
end
end

FastGettext.locale = 'cz'
create_translation 'Chicken||||Chicken', 'Kuře||||Kuřata||||Kuřat', "cz"
translations = @rep.plural('Chicken','Chicken')
translations[@rep.pluralisation_rule.call(5)].should == 'Kuřat'
end

it "can reload" do
@rep.reload.should == true
end
Expand Down

0 comments on commit 8a0fbc3

Please sign in to comment.