Kyle Fazzari
2014-Nov-14 19:22 UTC
Engines: How to write tests that depend upon main app models?
Hello all. The Rails Engines documentation[1] was really quite good for understanding how to write engines. However, it left me with a question which I've been unable to answer. Say I'm writing the engine discussed in the documentation (a blog). The `Post` model doesn't need to know anything about its author, and this engine doesn't need to deal with accounts in any way, but it makes sense for posts to _have_ an author, so we make the class for the author configurable and we say that the `Post` model `belongs_to` it. The engine can then simply make use of whatever account scheme is in use in the main application. How then do we write tests for the `Post` model if the engine doesn't contain a model for the author? I'm using FactoryGirl and I tried just putting together a factory for a user, but it doesn't work without a corresponding table. I suppose I could create a basic `Author` class within the generated `test/dummy` application, but then all the tests would have to be put in there as well, which feels a little nasty to me (I just want my tests in an obvious place, I guess). I think a solution is probably outside of the testing setup being used (rspec, minitest, fixtures or factories, etc.). I feel like this is a fairly typical use for an engine, so I thought maybe some of you had run into this issue before. I appreciate any help! [1]: http://guides.rubyonrails.org/engines.html -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b677140e-15ce-4223-83fc-b1ab3f597e95%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.