Rails How to use FactoryGirl in Seeds.rb?

I want the Seeds.rb file to run a method in a file from the Rails.root.join('spec') directory, which populates the database with the data created by FactoryGirl. Lets call this file "helpers.rb" with the "seed_data" method

Edit: require Rails.root.join('spec','helpers.rb') links the file. a source

This method, which I want to use in before(:all) do seed_data end , to sow test database and rake db:seed for development / production databases with the same effect.

+4
source share
1 answer

Seeds.rb

 require Rails.root.join('spec','helpers.rb') require 'rubygems' #so it can load gems require 'factory_girl_rails' #so it can run in development seed_data 

specifications /helpers.rb

 def seed_data Factory.create(:user) end 
+4
source

Source: https://habr.com/ru/post/1403567/


All Articles