我有以下代码(正式):
服务:
class Service
def self.method(params)
raise Error if some_object_exists?
ActiveRecord::Base.transaction do
# blah-blah create object
end
end
end
Rspec测试:
it "does not create the same object twice" do
params = {}
params2 = {}
Service.method(params)
Service.method(params2)
expect { Service.method(params) }.to raise_error(Error)
end
按照标题中提到的升级 Ruby 和 Rails 后,错误没有出现。
如果我删除交易,一切都会按预期进行:存储对象并引发错误。 在此升级过程中我缺少什么?我尝试了不同的 Rspec 和应用程序配置,但没有任何改变这种行为。