I'm using FactoryBot and Faker for my tests, and it looks like that Faker is generating the same name:
class Profile < ApplicationRecord
belongs_to :user
validates_presence_of :first_name, :last_name, :nickname
validates :nickname, uniqueness: { case_sensitive: false }
end
FactoryBot.define do
factory :user do
sequence(:email) { |n| "user#{n}@example.org" }
password "123456"
trait :with_profile do
profile
end
end
end
FactoryBot.define do
factory :profile do
first_name Faker::Name.unique.first_name
last_name Faker::Name.unique.last_name
nickname { "#{first_name}_#{last_name}".downcase }
user
end
end
RSpec.feature "Friendships", type: :feature do
scenario "User can accept a pending friendship request" do
@tom = create(:user, :with_profile)
@jerry = create(:user, :with_profile)
#other stuff
end
end
Even I'm using the unique method, I'm getting the error
ActiveRecord::RecordInvalid: Validation failed: Nickname has already been taken`.
Any clues?