Files
dunlop-core/spec/config/initializers/human_plural_spec.rb
T
2018-01-20 13:02:44 -03:00

56 lines
1.8 KiB
Ruby

require 'rails_helper'
class ModelNameTest
extend ActiveModel::Naming
def self.i18n_scope
'activerecord'
end
end
module ModelNameTestRootModel
class NestedModelNameTest
extend ActiveModel::Naming
def self.i18n_scope
'activerecord'
end
end
end
describe '.human_plural' do
def with_translation_modifications(&block)
original = I18n.backend.instance_variable_get('@translations').deep_dup
block.call
I18n.backend.instance_variable_set('@translations', original)
end
let(:translations){ I18n.backend.instance_variable_get('@translations') }
it "works when translation is specified in locales" do
User.model_name.human_plural.should eq 'Gebruikers'
end
it "Falls back to reasonable human.pluralize when no translation can be found" do
ModelNameTest.model_name.human_plural.should eq 'Model name tests'
end
describe 'nested' do
subject { ModelNameTestRootModel::NestedModelNameTest.model_name }
it "falls back to unnested path if nested path is not given" do
with_translation_modifications do
translations[:nl][:activerecord][:models][:plural][:model_name_test_root_model] = "Non sti version human plural"
subject.human_plural.should eq "Non sti version human plural"
end
end
it "chooses the most specific translation if available" do
with_translation_modifications do
translations[:nl][:activerecord][:models][:plural][:model_name_test_root_model] = "Non sti version human plural"
translations[:nl][:activerecord][:models][:plural][:"model_name_test_root_model/nested_model_name_test"] = "Sti version human plural"
subject.human_plural.should eq "Sti version human plural"
end
end
it "returns a resonable default when not given" do
subject.human_plural.should eq 'Nested model name tests'
end
end
end