RailsCasts Pro episodes are now free!

Learn more or hide this

Jay Elbourne's Profile

GitHub User: JElbourne

Comments by Jay Elbourne

Avatar

Testing

If you follow this cast and are testing with RSpec here is a tip.

In order for the scopes to work I added this to the before block

RSpec test before block
  before do
    sign_up_tenant(subdomain)
    @tenant = Tenant.first
    Tenant.current_id = @tenant.id

  end

I have a macro setup called sign_up_tenant that simply fills in the form and submits, but you can just create the Tenant using FactoryGirl or something similar.

The important bit is the Tenant.current_id = @tenant.id

Avatar

If anyone is using this with Devise gem and want to have unique emails per scope, here is what I added to the user model file.

user.rb
  def email_required?
    false
  end

  def email_changed?
    false
  end

This disables the Devise validation for email (only) so you can implement your own. ie Use the validation Ryan shows in this video.