简体   繁体   English

如何从引擎加载灯具?

[英]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.

相关问题 使用 Watir 进行 Rails 测试。 如何从 /test/fixtures 加载我的测试数据库 - Rails testing with Watir. How do I load my test db with the fixtures from /test/fixtures 如何在Rails引擎测试中使用“虚拟”中的灯具? - How can I use fixtures from “dummy” in my Rails engine tests? 如何在导轨的模拟对象中加载夹具以进行测试? - How to load fixtures in a mock object in rails for tests? 如何使用Minitest和Rails 3.0.10加载灯具? - How to load fixtures using Minitest and Rails 3.0.10? 如何在 Rails 5 中以特定顺序加载装置 - How to load fixtures in a specific order in Rails 5 如何从Rails单元中的测试/夹具yml文件加载测试数据 - How to load test data from test/fixtures yml file in Rails units 如何使用fixtures / yml文件中的数据加载neo4j测试数据库? - How to load neo4j test database with data from fixtures/ yml file? Rails无法从具有HABTM关系的夹具中加载数据 - Rails, can't load data from fixtures that have HABTM relationshionship 如何将夹具加载到命名空间模型表中? - How do I load fixtures into a namespaced models table? 如何使ar_fixtures加载受保护的属性? - How to get ar_fixtures to load protected attributes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM