How can I setup Minitest fixtures to test Apartment using postgres schemas

514 views Asked by At

I am building a multi tenant app in Rails using the Apartment Gem and Postgresql 9.4.1.

I use Minitest and dont' know RSpec.

How can I setup Minitest fixtures to put some fixtures/data in the public schema and some other data in a specific schema?

Example: Accounts is my non schema table, the rest goes in a schema. I have tried to setup my fixtures to prefix the schema name like so:

  • accounts.yml
  • schema1.users.yml
  • schema1.projects.yml

This just fails with a:

PG::UndefinedTable: ERROR:  relation "schema1.customers" does not exist

So it is trying to put the data into the correct schema, the schema just doesn't exist.

It looks like I need a way for to build the tenants/schemas when the test DB is migrated or first built, something like:

Apartment::Tenant.create('schema1')

and then the normal minitest preload will put the fixtures data into the appropriate schema.

Not sure on where/when/how this needs to happen.

Any ideas?

0

There are 0 answers