Ask A Question

Notifications

You’re not receiving notifications from this thread.

Rspec Test on Multi tanent app with aparment gem

Francisco Quinones asked in General

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

https://gist.github.com/Frank004/8aa4acf20f60a3666a42

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 
 F

Failures:

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

 Apartment::TenantExists:
   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.

Reply

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.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.