Ruby on Rails 测试数据库未提交新记录
有没有办法使用 Factory Girl 将新更改提交到 Ruby on Rails 中的测试数据库?
我有以下工厂:
Factory.define :shipping_info do |si|
si.name "Foo Bar"
si.street "12 Candy Lane"
si.country "US"
si.zip "12345"
si.state "IL"
end
我有以下测试:
require File.dirname(__FILE__) + '/../../spec_helper'
describe CgCart::ShippingInfo do
before(:each) do
@order = Factory(:order)
@order.order_line_item = Factory(:order_line_item)
@shipping_info = Factory(:shipping_info)
end
it "order should not be nil" do
@shipping_info.should_not be_nil
end
end
当我运行此测试时,它通过了。但是,我的测试数据库中没有创建新记录。我需要其中的数据供 Dameon 使用。
有什么建议吗?
Is there a way to use Factory Girl to commit new changes to the test database in Ruby on Rails?
I have the following factory:
Factory.define :shipping_info do |si|
si.name "Foo Bar"
si.street "12 Candy Lane"
si.country "US"
si.zip "12345"
si.state "IL"
end
And I have the the following test:
require File.dirname(__FILE__) + '/../../spec_helper'
describe CgCart::ShippingInfo do
before(:each) do
@order = Factory(:order)
@order.order_line_item = Factory(:order_line_item)
@shipping_info = Factory(:shipping_info)
end
it "order should not be nil" do
@shipping_info.should_not be_nil
end
end
When I run this test it passes. However, no new records are created in my test database. I need data in there for a Dameon to work with.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Factory.create(:order) 应该将该对象写入数据库。
如果您将事务固定装置设置为 true,则写入数据库的所有数据都会在测试完成后回滚。
在运行测试之前,您无法
tail -f log/test.log
,并且您将在那里看到大量活动。我希望这能澄清你的情况。
Using Factory.create(:order) should write that object to your database.
If you have transactional fixture set to true, all data that gets written to database gets rolled back after the tests finish.
You cant
tail -f log/test.log
before running your tests and you will see a lot of activity there.I hope that clears your situation.