2

I downloaded a Rails codebase on Windows. When I try to run functional tests the fixtures aren't being initialized, with errors like:

Field 'created_at' doesn't have a default value: INSERT INTO `mytable` (`name`, `code`) VALUES ('MyString', 'MyString')

It's like record_timestamps is set to false, but explicitly setting it to true in config/test.rb makes no difference. The tests work correctly on a Linux machine. How can I get the fixtures to load properly?

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
Ben Fulton
  • 3,988
  • 3
  • 19
  • 35

1 Answers1

1

The issue was as follows: The name of the model object that failed was pluralized, "MyTables" instead of "MyTable". Fixtures.rb makes a call to constantize to find the name of the class, which ordinarily raises a NameError exception when it fails, but in a fixture the exception is swallowed. The pluralized model object raised the exception and so the fixture was unable to determine what class it was trying to create. Without that information it didn't try to add timestamps to the insert statement - or labels or primary keys for that matter - and thus the error was thrown.

I imagine the error message would have been different if the code had been in a slightly different order. Maybe that was the difference between running on Linux and running on Windows.

Ben Fulton
  • 3,988
  • 3
  • 19
  • 35
  • Another user who found the same issue: http://stackoverflow.com/questions/16548352/rails-dont-generate-create-at-for-fixture – Ben Fulton Sep 17 '14 at 18:11