2

I'm using Rails engines to break up a big app into smaller pieces. The parent app mostly handles users and authentication.

In one of my engine tests I want to log in a user before each test. How should I access this user log in functionality, which exists in the parent app, from the engine?

It seems there are two options:

1) Build user authentication into the dummy app. When you run rails plugin new app_name --mountable a "dummy app" - just a plain Rails app - is created in your test folder. During tests the engine is mounted on to this dummy app. For feature (integration, acceptance, what-have-you) tests, I thought it would be good to use real objects whenever possible. So I was planning on using a factory to create a real user and then log in that user. To do this with the dummy app, I would need to build that user functionality in.

This seems like a pain because if the real parent app changes, I need to change this dummy app as well.

2) Put all my tests in the parent app. This will work fine, I think, but it seems fishy. I feel like I should put my engine tests in the engine.

0

There may be something missing from my understanding of constraints you face. I would have thought:

  1. User login is part of the setup for each test. Do it however you need as part of the test framework. If it can call the parent that's fine. If it can just set up some status variables that's fine too. [I don't know what you mean by dummy app.]
  2. Engine tests should be part of the engine, rather than part of the parent. They should have minimal dependencies.

Perhaps the information missing is what is implied by user login and why it's at all hard.


It is a routine part of constructing any kind of automated testing, whether unit, functional or integration, that you have to write mocks and stubs. I think that's the way to think about this situation. You don't need a real user validation, just a 'good enough' mock.

  • Thanks for your answer! When you run rails plugin new app_name --mountable a dummy app - just a plain Rails app - is created in your test folder. During tests the engine is mounted on to this dummy app. For feature (integration, acceptance, what-have-you) tests, I thought it would be good to use real objects whenever possible. So I was planning on using a factory to create a real user and then log in that user. To do this with the dummy app, I would need to build that user functionality in. I could use the parent app authentication but then that seems to violate (2) in your answer. – niftygrifty Apr 14 '14 at 7:34
  • Frankly, I'm pretty new to this, so if I'm missing something basic, please let me know :) – niftygrifty Apr 14 '14 at 7:34
  • You should edit your question and add all that new info. Yes, I know the process but it's not obvious what dummy referred to. See edit. – david.pfx Apr 14 '14 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.