[英]How to load the fixtures from an Engine?
I've extracted my models into a mountable engine and now I want the host-app (the app including that mountable engine) to use the fixtures from that engine. 我已将我的模型提取到可安装的引擎中,现在我希望主机应用程序(包括可安装引擎的应用程序)使用该引擎的灯具。
class ActiveSupport::TestCase
# Add fixtures from the mounted engine "blorgh"
fixture_path = Blorgh::Engine.root.join("test", "fixtures")
fixtures :all
end
Debugging learns that fixture_path is correctly set, to something like /home/x/.rvm/gems/ruby-1.9.3-p286@x/bundler/gems/blorgh-07520673953b/test/fixtures/
. 调试了解到fixture_path的设置是否正确,如
/home/x/.rvm/gems/ruby-1.9.3-p286@x/bundler/gems/blorgh-07520673953b/test/fixtures/
。 This is the correct path with the correct fixtures. 这是正确的固定装置路径。
But, somehow the fixtures appear not to get loaded. 但是,不知何故,灯具似乎没有加载。 The database remains empty.
数据库仍为空。 And the helpers are not available.
帮助者不可用。 Eg a fixture
contacts.yml
normally leads to the helper contacts(:harry)
. 例如夹具
contacts.yml
通常会导致辅助contacts(:harry)
。 This helper is not set, because the fixtures were not loaded. 未设置此助手,因为未加载灯具。
The engine is not namespaced, but for the sake of completeness, blorgh_contacts(:harry)
is not defined either. 引擎没有命名空间,但为了完整起见,还没有定义
blorgh_contacts(:harry)
。
How can I use the fixtures from an engine? 我怎样才能使用发动机的夹具?
这适合我
self.fixture_path = Rails.root.parent + "./fixtures/ads"
这对我有用,我觉得更简洁。
self.fixture_path = Blorgh::Engine.root.join("test", "fixtures")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.