We have a database schema in our app that is database-dependent, and we would like to load these DB features into the test database.

Specifically we need to create materialized views in a Postgres database.

I tried dumping structure.sql into the db folder, and then hoped that RAILS_ENV=test rake db:structure:load followed by rake spec (starting from a clean DB with no schemas) would cause the test DB to have the view.

However I had to explicitly call the view creation in my test file for tests to work. The error was a Postgres error saying simply that the view/table wasn't there.

Needless to say, the view is in the development DB and the code does in fact work. It's just the unit test on the service object that retrieves the view's data that doesn't work.

EDIT I also added config.active_record.schema_format(:sql) to config/environments/test.rb

0 Answers