🖥
Shoulda::Matchers::ActiveRecord::ValidateUniquenessOfMatcher::Existing
Answer
Create some record before test case
require "rails_helper"
RSpec.describe User, type: :model do
describe "validations" do
# Some way create one record
before do
User.create(name: "Alice #{rand(99999999)}")
# FactoryBot.create :user
end
it { should validate_uniqueness_of(:name) }
end
end
Error
Shoulda::Matchers::ActiveRecord::ValidateUniquenessOfMatcher::ExistingRecordInvalid:
validate_uniqueness_of works by matching a new record against an
existing record. If there is no existing record, it will create one
using the record you provide.
While doing this, the following error was raised:
...
The best way to fix this is to provide the matcher with a record where
any required attributes are filled in with valid values beforehand.
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2020-04-14
Discussion