Sha256: 56f96880a71f1cca841783323ce6170e6d6077f5b8f4cb7de1b23f12886a1fa0

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

shared_context "behaves as translatable" do
  testable_attributes = [:name, :value]
  attribute = nil

  before do
    subject.attribute_names.each do |a|
      if testable_attributes.include? a.to_sym
        attribute = a.to_sym
      end
    end
  end

  context "when there's a missing translation" do
    before do
      subject[attribute] = "English"
      I18n.locale = :es
    end

    it "falls back to default locale" do
      expect(subject[attribute]).to eq "English"
    end
  end

  context "missing translation on default locale" do
    let!(:change_locale) { I18n.locale = :es }
    let!(:model) { subject.class.new }

    before do
      [:es, :en, :de].each do |locale|
        create(:store, default_locale: locale)
      end
      SpreeMobility::Fallbacks.config!

      model[attribute] = 'produto'
    end

    it "falls back to not default translations" do
      I18n.locale = :en
      expect(model[attribute]).to eq "produto"
    end
  end

  context "missing translation on locale other than default" do
    let!(:model) { subject.class.new }

    before do
      [:es, :en, :de].each do |locale|
        create(:store, default_locale: locale)
      end
      SpreeMobility::Fallbacks.config!

      model[attribute] = 'product'
    end

    it "falls back to default locale first" do
      I18n.locale = :es
      model[attribute] = "produto"

      I18n.locale = :de
      expect(model[attribute]).to eq "product"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_mobility-1.4.0 spec/support/shared_contexts/translatable_context.rb
spree_mobility-1.3.0 spec/support/shared_contexts/translatable_context.rb
spree_mobility-1.2.0 spec/support/shared_contexts/translatable_context.rb
spree_mobility-1.1.0 spec/support/shared_contexts/translatable_context.rb
spree_mobility-1.0.0 spec/support/shared_contexts/translatable_context.rb