I have a higher level app, that includes two engines:
- Core (engine)
- API (engine)
The API engine depends on the models present in the Core engine. I was wondering how to reference these.
What I have tried
For example, if the Core engine has the model "User", how do I reference it via the API engine?
module Api
describe User do
routes { Api::Engine.routes }
before :each do
::Core::User.create!
end
....
With this code, I received:
Failure/Error: ::Core::User.create!
NameError:
uninitialized constant Core
So I thought that I had to include the core engine in the api.gemspec file.
s.add_dependency "core", path: "core/"
however, looks like bundler did not like that.
There was a Gem::Requirement::BadRequirementError while loading
api.gemspec:
Illformed requirement [{:path=>"core/"}] from myAppPath/api/api.gemspec:21:in
I also tried
s.add_dependency "core", path: "../core/"
but that gave me a similar error.
Any idea what should be done to reference the Core
models from the API
engine?
Thanks!
Update I attempted to add the Core engine into the Api engine via the Api's Gemfile. Unfortunately, I get an error. I'm starting to feel that engine's should not reference other engines. Would that be true?
/home/.rvm/gems/ruby-2.0.0-p247/gems/railties-
4.0.0/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_updated':
Rails::Application::RoutesReloader#execute_if_updated delegated to
updater.execute_if_updated, but updater is nil: #
<Rails::Application::RoutesReloader:0x007fb53b67bce8 @paths=
["/home/myApp/api/spec/dummy/config/routes.rb", "/home/myApp/core/config/routes.rb",
"/home/myApp/api/config/routes.rb"], @route_sets=[#
<ActionDispatch::Routing::RouteSet:0x007fb53b3b8420>, #
<ActionDispatch::Routing::RouteSet:0x007fb53b6008b8>, #
<ActionDispatch::Routing::RouteSet:0x007fb53b6b9b60>]> (RuntimeError)
UPDATE on findings In addition to the answer below, I would like to add that .gemspec files DO NOT have any information on where the gem will be stored, i.e. it will not point to a git repository, or a file path, etc. This is explained in this article:
http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/