1

I'm switching from Globalize gem to Mobility gem in my app. I'm facing an issue with Mobility fallbacks: empty attribute correctly falls back to another language in console, but it doesn't in unit tests.

I don't understand why nor how to fix that...

In console:

    prod = Product.last
    prod.send(:title=, "French Title", locale: :fr)
    prod.send(:title=, nil, locale: :en)
    prod.save
    Mobility.with_locale(:en) { p prod.title }
    # => "French Title"

In unit tests:

require 'test_helper'
class ProductI18nTest < ActiveSupport::TestCase
  test "test" do
    prod = Product.last
    prod.send(:title=, "French Title", locale: :fr)
    prod.send(:title=, nil, locale: :en)
    assert prod.save
    Mobility.with_locale(:en) { assert_equal "French Title", prod.title }
    # Error: Expected: "French Title". Actual: nil
  end
end

My model looks like:

class Product < ApplicationRecord
  # [..]
  extend Mobility
  translates :title, fallbacks: true
  # [..]
end

And my mobility.rb config file:

Mobility.configure do
  plugins do
    fallbacks
    locale_accessors
    # fallthrough_accessors
    # [..]
  end
end

Current stack:

  • Ruby 2.5.9
  • Rails 5.1.7
  • Mobility 1.1.2
  • Minitest 5.14.4

Does anyone can help me on this? :-) Thank you!

Pierre-Yves O.
  • 508
  • 3
  • 15

0 Answers0