Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails fixtures and namespace model - ActiveRecord::Fixture::FixtureError

in an app I work on test suite is done with Minitest and fixtures and I faced such a problem, I can't solve, neither find a solution.

I have a model Survey and fixtures for it test/fixtures/surveys.yml:

one:
  user: admin
  name: Survey one
  description: This is survey one
  company: university
  review_type: 1

two:
  user: admin
  name: Survey two
  description: This is survey two
  company: university

also, I have namespace surveys and there a model for question - Surveys::Question (with polymorphic association), which has corresponding fixtures test/fixtures/surveys/questions.yml:

one:
  sentence: Survey question one?
  display_order: 1
  question_type: 0
  questionable: one (Survey)

two:
  sentence: Survey question two?
  display_order: 2
  question_type: 1
  questionable: one (Survey)

So far so good, things work. But whenever I try to add another questions definition to fixtures, let's say:

three:
  sentence: Survey question three?
  display_order: 3
  question_type: 2
  questionable: one (Survey)

an error is raised: ActiveRecord::Fixture::FixtureError: table "surveys" has no column named "sentence"

I totally can't follow up, why suddenly ActiveRecord::Fixtures fails to follow up.

I would be grateful for any suggestion on this.

like image 544
adkra Avatar asked May 07 '18 20:05

adkra


1 Answers

Make sure your database schema has not changed and that you didn't remove or rename the column or table in your database. Whenever you change your schema and run your migrations, be sure to run this before running your tests:

rake db:test:prepare

Then try running your tests again. If you get the same error, it indicates your test database is missing that column. Check your migrations to make sure.

Also, do you think maybe you need three: in test/fixtures/surveys.yml ?

like image 86
lacostenycoder Avatar answered Oct 13 '22 19:10

lacostenycoder