Sha256: d817937f30bdc62c32e8d790ecb3f45541397dd21ac0cbb0b609d9960aed679d
Contents?: true
Size: 1.98 KB
Versions: 2
Compression:
Stored size: 1.98 KB
Contents
require 'spec_helper' describe LostInTranslations::Base do describe '.translation_data_field =' do context "when it points to a real method" do before do @user_class = Struct.new(:first_name, :last_name) do include LostInTranslations::Base self.translation_data_field = :translation_json def translation_json { en: { first_name: 'Jon', last_name: 'Snow' }, fr: { first_name: 'Jean', last_name: 'Neige' } } end end LostInTranslations.define_translation_methods(@user_class, :first_name) @user = @user_class.new('Joao', 'Neve') end it "LostInTranslations.translate must return a translation" do expect(LostInTranslations.translate(@user, :first_name, :en)).to eq 'Jon' end it "calling a field not translated, must return the original data" do I18n.with_locale(:en) do expect(@user.last_name).to eq 'Neve' end end context "and the translation data doesn't contain results" do it "LostInTranslations.translate must return nil" do expect(LostInTranslations.translate(@user, :first_name, :de)).to be_nil end end end context "when it DOENS't point to a real method" do before do @user_class = Struct.new(:first_name, :last_name) do include LostInTranslations::Base self.translation_data_field = :translation_json end LostInTranslations.define_translation_methods(@user_class, :first_name) @user = @user_class.new('Joao', 'Neve') end it "LostInTranslations.translate must raise an error" do expect { LostInTranslations.translate(@user, :first_name, :en) }.to raise_error(NotImplementedError) end it "calling a field not translated, must return the original data" do I18n.with_locale(:en) do expect(@user.last_name).to eq 'Neve' end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lost_in_translations-1.3.0 | spec/lost_in_translations/base_spec.rb |
lost_in_translations-1.2.0 | spec/lost_in_translations/base_spec.rb |