FactoryGirl,它保存到数据库了吗?
FactoryGirl, Does it save to the database?
当我用 factory girl 创建一个模型并调用保存函数时,是否将该数据保存到数据库中?
trait :myTrait do
after :create do |user|
user.partners << Partner.MyPartner
user.save
end
end
取决于您的测试套件的事务级别设置。
rails_helper.rb:
RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
如果 config.use_transactional_fixtures 为真,记录不会保存到数据库中,但测试将可以访问创建的数据。
当我用 factory girl 创建一个模型并调用保存函数时,是否将该数据保存到数据库中?
trait :myTrait do
after :create do |user|
user.partners << Partner.MyPartner
user.save
end
end
取决于您的测试套件的事务级别设置。
rails_helper.rb:
RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
如果 config.use_transactional_fixtures 为真,记录不会保存到数据库中,但测试将可以访问创建的数据。