1

Someone asked this question here:

How to load db:seed data into test database automatically?

But their solution only works if you are going to run db:test:prepare which depends on a schema to load. Mongoid doesn't have a schema file, and db:test:prepare doesn't do anything and so this is not working. Is there another strategy that would work?

Community
  • 1
  • 1
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114

2 Answers2

1

There is a similar question here. I think that especially the last answer would help you :

How to load db:seed data into test database automatically?

Community
  • 1
  • 1
Spyros
  • 46,820
  • 25
  • 86
  • 129
  • Yeah that was the question I referenced in my post. But if I put Rake::Task["db:seed"].invoke in my Rakefile it still isn't getting invoked. Maybe because I'm using Mongoid and so rake it being skipped? – Jeremy Smith Mar 31 '11 at 17:10
1

Just as a FYI, I figured out a way to meet my requirements. I set up a database called seed like so in mongoid.yml:

 databases:
    seeds:
      database: seeds_db
      host: localhost
      port: 27018

Then in my model I just have the datase use seeds like:

class SeededData
  include Mongoid::Document
    set_database :seeds

This actually works great because production, test, and development are all pulling from the seed database, which is what I want. And I'm never vacuuming out the data when running tests.

Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114