user8745303
user8745303

Reputation: 39

Ruby on Rails 4 fixtures require table

Fixtures when using Rails (My environment Rails 4.2)

Why when running a test, why does it error when a fixture exists but there isn't a table with the same name? And why does the fixture require to have a matching column in the table?

Example 1: (table does not exist)

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: joes: DELETE FROM "joes"

Example 2: (table exists, but column does not)

ActiveRecord::Fixture::FixtureError: table "products" has no column named "other".

I thought I could use fixtures as common place to reference in my tests, but doesn't need to match my DB.

Upvotes: 0

Views: 999

Answers (1)

Tim
Tim

Reputation: 1005

Fixtures are your data, they still require a place to go!

"Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model."

http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures

They are not some sort of in memory replacement for a testing database, they just allow you to pre-populate your test database with values, so that you can test more conveniently without having to put lots of data in, when setting up a test run. That's all.

Upvotes: 2

Related Questions