简体   繁体   English

在加载课程之前加载导轨固定装置

[英]Load rails fixtures before classes are loaded

I have classes in my Rails project that are 'registered' with attributes read from the database. 我在Rails项目中有使用从数据库读取的属性进行“注册”的类。 However, when I run 'rake test', the classes are loaded before the fixtures are created in SQLLite. 但是,当我运行“ rake test”时,将在SQLLite中创建固定装置之前加载类。 As a result, the classes are 'registered' with null values, causing my tests to fail. 结果,这些类被“注册”为空值,导致我的测试失败。

Manually testing by running my rails server works perfectly fine, so I don't think there is a problem with my code logic. 通过运行Rails服务器进行手动测试可以很好地工作,因此我认为我的代码逻辑没有问题。 Also, my fixtures are correct. 另外,我的装置是正确的。

How can I change the order of loading the fixtures before the classes and models are instantiated. 在实例化类和模型之前,如何更改夹具的加载顺序。

rake test loads fixtures if you specify fixtures :all . 如果指定了fixtures :allrake test会加载夹具。 Run rake test --trace to see what happens behind the scenes. 运行rake test --trace以查看幕后情况。 I dont think the fixtures are loaded without mentioning fixtures :all Try to rake db:fixtures:load and see if it raises any error. 我不认为没有提到灯具就加载了fixtures :all尝试rake db:fixtures:load ,看看是否引发任何错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM