Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seeding test database in rails 4

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

like image 768
Jane Avatar asked Feb 18 '26 12:02

Jane


1 Answers

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.

like image 122
Jane Avatar answered Feb 21 '26 04:02

Jane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!