You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spec User it { is_expected.to validate_presence_of(:email) } it { is_expected.to validate_uniqueness_of(:email).case_insensitive } it { is_expected.to validate_presence_of(:username) } it { is_expected.to validate_uniqueness_of(:username).case_insensitive }
Spec Phone it { is_expected.to validate_presence_of(:phone_number) } it { is_expected.to validate_uniqueness_of(:phone_number).case_insensitive }
My factories
User factory :user do name { Faker::Name.name } email { Faker::Internet.email } password_digest { Faker::Internet.password(min_length: 8) } token_password_recovery { rand(1..999) } token_password_recovery_deadline { '2023-06-17 15:28:41' } token_password_confirmation { rand(1..999) } token_password_confirmation_deadline { '2023-06-17 15:28:41' } company username { Faker::Internet.username } end
Phone factory :phone do phone_type { rand(0..1) } phone_number { Faker::PhoneNumber.phone_number_with_country_code } after :build, &:phoneble end
The text was updated successfully, but these errors were encountered:
For email and username tests. It looks like your tests expects it not to be scoped_to anything. I'm guessing based on the results that you have it scoped to :company in your model validation.
Try adding .scoped_to(:company) in your test cases and see if it helps.
it { is_expected.to validate_uniqueness_of(:email).case_insensitive.scoped_to(:company) }
I don't specifically see it scoped in the examples you give, but perhaps you have some 3rd party like Tenancy scoping this in your models.
Hello everything is fine? I'm having some problems doing unique validations with the gem following my models and tests.
Model User
validates :name, :username, :email, :password_digest, presence: true validates :email, :username, uniqueness: { case_sensitive: false }
Model Phone
validates :phone_type, :phone_number, presence: true validates :phone_number, uniqueness: { case_sensitive: false }
Spec User
it { is_expected.to validate_presence_of(:email) } it { is_expected.to validate_uniqueness_of(:email).case_insensitive } it { is_expected.to validate_presence_of(:username) } it { is_expected.to validate_uniqueness_of(:username).case_insensitive }
Spec Phone
it { is_expected.to validate_presence_of(:phone_number) } it { is_expected.to validate_uniqueness_of(:phone_number).case_insensitive }
My factories
User
factory :user do name { Faker::Name.name } email { Faker::Internet.email } password_digest { Faker::Internet.password(min_length: 8) } token_password_recovery { rand(1..999) } token_password_recovery_deadline { '2023-06-17 15:28:41' } token_password_confirmation { rand(1..999) } token_password_confirmation_deadline { '2023-06-17 15:28:41' } company username { Faker::Internet.username } end
Phone
factory :phone do phone_type { rand(0..1) } phone_number { Faker::PhoneNumber.phone_number_with_country_code } after :build, &:phoneble end
The text was updated successfully, but these errors were encountered: