为什么after_commit即使use_transactional_fixtures = false也无法运行 [英] Why after_commit not running even with use_transactional_fixtures = false
本文介绍了为什么after_commit即使use_transactional_fixtures = false也无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
rspec中的事务装置阻止了after_commit的调用,但是即使我使用以下命令将其禁用
Transactional fixtures in rspec prevent after_commit from being called, but even when I disable them with
RSpec.configure do |config|
config.use_transactional_fixtures = false
end
after_commit回调
无法运行。
以下是我产生问题的最新rspec / rails的Rails应用程序:
git://github.com/sheabarton/after_commit_demo.git
Here is a rails app with the latest rspec / rails that I have produced the issue on: git://github.com/sheabarton/after_commit_demo.git
推荐答案
一种解决方法是手动触发 commit
回调。示例:
One way around this is to trigger the commit
callbacks manually. Example:
describe SomeModel do
subject { ... }
context 'after_commit' do
after { subject.run_callbacks(:commit) }
it 'does something' do
subject.should_receive(:some_message)
end
end
end
有点晚了,但是希望对其他人有帮助。
A little late, but hope this helps others.
这篇关于为什么after_commit即使use_transactional_fixtures = false也无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文