I have a custom class with a unique email, but it is attached to the tenant:
class User < ActiveRecord::Base validates :email, :uniqueness => {:scope => :tenant_id, :allow_blank => true} #... end
I am trying to check it with:
class UserTest < ActiveSupport::TestCase context "a user" do setup { @user = create :user } subject { @user } should validate_uniqueness_of(:email).scoped_to(:tenant_id) end end
but the test fails with this message:
Expected errors for the inclusion of "have already been accepted" when the email is set to " joseph.allen_1@example.com ", received errors: ["the letter has already been received (" joseph.allen_1@example.com \ "))", "first_name cannot be empty (nil) "," last_name cannot be empty (nil) "] (with a different tenant_id value)
which raises a lot of questions. Why does the error message not match? It looks like the actual email address is included in the error message, but why is it included? When I generate an error from the user interface, it does not seem to be included:
In addition, at the end, he says that he is trying it with another tenant, who, if he was true, should not generate any errors (this does not happen when the application itself starts), but why is it expecting an error? He should only expect an error if he is the same tenant_id.
This is so confusing. Any ideas what is going on and / or how to verify this correctly?
source share