Setting up fixtures for model translations using Mobility in a Rails app

How do I set up fixtures for models translations in a Rails app using Mobility?

Currently, I have the following directory structure:

📂 test
  📂 fixtures
    📂 article
      📄 translations.yml
    📄 articles.yml


# test/fixtures/articles.yml

past_article:
  type: BlogPost
  author: Barney Rubble
  posted_on: <%= 5.days.ago.to_s(:db) %>
  hero_image_id: 1


# test/fixtures/article/translations.yml

past_article_translation:
  article: past_article
  locale: en
  title: Past Article Fixture
  subtitle: Temporary subtitle
  body: This is the temporary blog post content.

I get ActiveRecord::Fixture::FixtureError: table "article_translations" has no column named "article". when trying to run my tests.

With Globalize gem, I could change the key in translations.yml from article to globalized_model, but that doesn't work with Mobility.

1 answer

  • answered 2018-02-13 11:09 Chris Salzberg

    If you change article to translated_model, I believe it should work. translated_model is the equivalent in Mobility to globalized_model in Globalize.

    (I don't use fixtures myself so not really familiar with syntax, but the inverse relationship from translation to model is translated_model, which you can see here).