简体   繁体   中英

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/ . 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) . 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.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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