3

I'm just starting to implement some tests for my work in progress rails app. I have some dependencies (the main one being devise for user management) which will require me to have a user already registered.

I have these items set up in my db/seeds.rb file.

I have found some information from this article, this question and this question but they relate to earlier versions of rails.

I created a test_seeds.rake file as suggested by one of the questions, but it didn't seem to get called when I run

rake tests

so I'm working on the theory that it wasn't just the test folder structure that changed as part of rails 4.

Can anyone provide any rails 4 guidance on how to achieve this?

Thanks Jane

Community
  • 1
  • 1
Jane
  • 1,953
  • 1
  • 20
  • 27

2 Answers2

3

Aha, thanks to Steve's comment to this question I discovered

Rails.application.load_seed 

which I've implemented in the following method in my test/test_helper.rb file as follows:

  def set_up
    Rails.application.load_seed 
  end

which does what I need. I'm unsure if this is a Rails 4 way of doing it though.

Community
  • 1
  • 1
Jane
  • 1,953
  • 1
  • 20
  • 27
1

I would use seedbank.

It allows you to specify separate seed files.

  • Seed files that need to be run in every environment.
  • Seed files that only need to be run in development, test or production.
  • Seed files that need to be run in certain custom situations.

I think that seedbank overrides the rake db:setup task, and that this in turn is run by rake tests. But you would have to test that to make sure.

Arjan
  • 6,264
  • 2
  • 26
  • 42