Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Rspec Test on Multi tanent app with aparment gem

General • Asked by Francisco Quinones

Hi I'm having a hard time figuring this out.

Im starting to do test on my Multitenant app and encounter a problem when trying to run the project_spec.rb
I get this error:

  $ bundle exec rspec spec/models/project_spec.rb 


 1) Project has a valid factory
 Failure/Error: Apartment::Tenant.create(subdomain)

   The schema companydemo already exists.
 # ./app/models/company.rb:67:in `create_tenant'
 # ./spec/models/project_spec.rb:5:in `block (2 levels) in <top (required)>'
 # ------------------
 # --- Caused by: ---
 # PG::DuplicateSchema:
 #   ERROR:  schema "companydemo" already exists
 #   ./app/models/company.rb:67:in `create_tenant'

 Finished in 1.22 seconds (files took 4.13 seconds to load)
  1 example, 1 failure
  Failed examples:
  rspec ./spec/models/project_spec.rb:12 # Project has a valid factory

What im looking for is how can I do test on a multitenant playing nice with the Company Model callback for creating tenant when a Company is create. I know I need to setup some before logic.
Im new to test so please any help on how to solve this problem.

Thank you.

The error says you've already created the companydemo tenant. I think the thing you're going to run into here is making sure you architect your tests properly to create and operate on a tenant and safely revert them as necessary. You'll need to add cleanup methods in your tests to make sure that once you're done using the tenant that it gets dropped. That's basically the only changes you'll need to do aside from setting up your other tests to already have a tenant setup, migrated, and selected.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.