0

I had a single-table inheritance data model, where CityPage < Destination. This worked fine.

Now that I have added a second type CountryPage < Destination, my tests fail. Specifically, CityPage.all returns an empty result even though I have CityPage fixtures (which have not been changed & worked perfectly before).

What am I doing wrong? Why is my test data not being generated?

henrebotha
  • 1,244
  • 2
  • 14
  • 36

1 Answers1

0

When you have STI with more than one child model, you need to use one fixtures file named after the parent, and distinguish the individual fixtures using the type property (i.e. what STI does under the hood). So in my case, I needed to have /test/fixtures/destinations.yml, not /test/fixtures/{city,country}_pages.yml.

Brief Googling indicates this has something to do with Minitest clearing the db after test runs - see comment below.

henrebotha
  • 1,244
  • 2
  • 14
  • 36
  • 1
    To clarify, the sequential loading of each fixture file causes the associated database table to be emptied before importing each file. If you have multiple fixture files that ultimately use the same table (`destinations` in this case), then you're going to have a bad time. The order in which your YAML files are processed will be system dependent, so what works locally may not work on your CI service, or vice-versa. – Barry Apr 27 '17 at 08:16