Is there a rake command in Rails 3 to clone my development database data? I noticed rake db:test:prepare
and rake db:test:clone
are mentioned throughout various blogs, but running them seems to do nothing. Furthermore, rake -T
shows no db:test
cases. I've resorted to loading a sql dump for now, but it would be great if I could just clone my existing development data for up-to-date testing.
在Rails 3中是否有rake命令来克隆我的开发数据库数据?我注意到rake db:test:prepare和rake db:test:clone在各个博客中都有提及,但运行它们似乎什么都不做。此外,rake -T显示没有db:测试用例。我现在暂时使用sql转储,但如果我能克隆现有的开发数据以进行最新的测试,那将会很棒。
EDIT -- I desire to test on a database since I am dealing with legacy data that I run through model filters when accessed. Factories won't work for me in this context, since data passed through create
is defined as a different schema than that of the legacy data.
编辑 - 因为我正在处理访问时通过模型过滤器运行的遗留数据,所以我希望在数据库上进行测试。在这种情况下,工厂对我不起作用,因为通过create传递的数据被定义为与传统数据不同的模式。
2 个解决方案
#1
10
rake db:test:prepare
is still there even though it doesn't show up in rake -Tdb
. I guess the Rails team decided to de-clutter the rake -T
output?
rake db:test:即使它没有出现在rake -Tdb中,它仍然存在。我猜Rails团队决定解除rake -T输出的混乱?
#2
1
I would suggest you not clone your development database but rather rely on factories to give you predictable data you can craft for your exact test cases. Sooner or later, relying on having reliable test data in a database you can access will break your tests. It will also break the tests of anyone else who works on the project. And changes/additions to the data will not propagate to other developers as would your carefully constructed factories.
我建议你不要克隆你的开发数据库,而是依靠工厂为你提供可以为你的确切测试用例制作的可预测数据。迟早,依赖于您可以访问的数据库中的可靠测试数据将破坏您的测试。它还将打破其他任何从事该项目的人的测试。对数据的更改/添加不会像您精心构建的工厂那样传播给其他开发人员。
Look over Machinist, FixJour, FactoryGirl and the lot. They really solve the test data problem well and you check them into version control so the rest of your team has access to them.
查看Machinist,FixJour,FactoryGirl等等。他们确实很好地解决了测试数据问题,并将它们检查到版本控制中,以便团队的其他成员可以访问它们。
#1
10
rake db:test:prepare
is still there even though it doesn't show up in rake -Tdb
. I guess the Rails team decided to de-clutter the rake -T
output?
rake db:test:即使它没有出现在rake -Tdb中,它仍然存在。我猜Rails团队决定解除rake -T输出的混乱?
#2
1
I would suggest you not clone your development database but rather rely on factories to give you predictable data you can craft for your exact test cases. Sooner or later, relying on having reliable test data in a database you can access will break your tests. It will also break the tests of anyone else who works on the project. And changes/additions to the data will not propagate to other developers as would your carefully constructed factories.
我建议你不要克隆你的开发数据库,而是依靠工厂为你提供可以为你的确切测试用例制作的可预测数据。迟早,依赖于您可以访问的数据库中的可靠测试数据将破坏您的测试。它还将打破其他任何从事该项目的人的测试。对数据的更改/添加不会像您精心构建的工厂那样传播给其他开发人员。
Look over Machinist, FixJour, FactoryGirl and the lot. They really solve the test data problem well and you check them into version control so the rest of your team has access to them.
查看Machinist,FixJour,FactoryGirl等等。他们确实很好地解决了测试数据问题,并将它们检查到版本控制中,以便团队的其他成员可以访问它们。