1

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.

partydrone
  • 507
  • 4
  • 15

1 Answers1

2

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).

Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82
  • What do you use? Factory Girl/Factory Bot? – partydrone Feb 14 '18 at 23:18
  • Factory Girl, but it really doesn't matter. When you're using any factory gem, you have to build actual associations, so you just need to know the table/association names, nothing else from Mobility should really matter. – Chris Salzberg Feb 16 '18 at 12:22