70
67

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 5 years have passed since last update.

FactoryGirlでModel作成時のValidationをスキップする方法

Posted at

実装の都合上、どうしてもFactoryGirlでModel作成時のValidationを避けたいときの回避策はこんな感じです。

# spec/factories.rb
FactoryGirl.define do
  factory :user do
    email 'foobar@hogehoge.com'

    # save時にvalidationをスキップする
    to_create do |instance|
      instance.save validate: false
    end 
  end
end

###参考サイト
Bypass Rails validations when creating FactoryGirl objects

70
67
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
70
67

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?