0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

単体テストコードで重複したメールアドレスを通さないようにする

Posted at

重複したメールアドレスについて単体テストコードでつまづいたので記録。
ファクトリーボットでインスタンスを作成したあと、
セーブメソッドで保存。
あとは記述の通り。

 it "重複したメールアドレスは登録できない" do
          @user.save
          another_user = FactoryBot.build(:user)
          another_user.email = @user.email
          another_user.valid?
         expect(another_user.errors.full_messages).to include('Email has already been taken')
       end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?