How do I get RSpec and Cucumber tests to run in an app using both Mongoid and ActiveRecord?
|Added at||2016-12-30 16:12|
My team's project is a Rails 4.2 app using Mongoid 4. A new feature we are adding requires us to read data from a Postgres DB and use those records in the app through an intermediary object. In other words, our app will play with ActiveModel objects (non-persisted) that contain a mix of data from Mongoid models and ActiveRecord models, and thus can do all the normal cool Rails stuff with Controllers and Views, etc. (We think it's clever.) The intention right now is that we will never write to the SQL tables, just read. Any new data stored will be in mongodb.
For my development environment, the first steps seemed pretty straight-forward:
Using the rails console, I was able to prove to myself that I could search/find objects in both databases. So far so good.
When I first fired up the rspec tests, there were tons of failures related to validation errors because "records already existed with that name". Long investigation story short, I fixed by setting all DatabaseCleaner calls to be
BUT, Cucumber (feature) tests? I can't even get them started. It keeps saying:
No! All those migrations we have are for MONGO. There are no SQL/ActiveRecord migrations. Not surprisingly, that rake fails:
I tried this series of commands:
but cucumber still gives the same migration pending error.
So I'm stuck! I haven't found anyone doing what we're trying to do. I know there HAS to be someone, I just haven't found the right search terms, apparently.
The worst part of all this is I had no intention of even using an ActiveRecord test database at all, I was simply going to mock those records in my tests. How can I tell the app, "I only need ActiveRecord for runtime, not testing. Stop looking at the migrations, ActiveRecord, those aren't for you!"
I have run out of ideas and words to search with. I've been trying to solve this problem for a couple of days now and have tried SO many different things, please forgive me if I've left some of those out here. Any assistance would be greatly appreciated.