LoginSignup
1
1

More than 5 years have passed since last update.

テストでActiveRecordのCallbcksをスキップする方法

Posted at

いろいろやり方があるみたいだけど標準機能でいけそう

sample.rb
class Sample < ActiveRecord::Base
  after_create :sample_callback

  def sample_callback
    # doing something
  end
end
sample_spec.rb
describe Sample do
  before { Sample.skip_callback(:create, :after, :sample_callback) } 
  after { Sample.set_callback(:create, :after, :sample_callback) }

  it "test" do
    # test
  end
end
1
1
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
1
1