vidur punj
vidur punj

Reputation: 5871

How to load the rspec fixtures in to the database from the files

I am using rails 5 with ruby 2.4 and gem 'rspec-rails', '~> 3.8'
I am using 'devise' gem for the user model the fixture for it is as: fixture: users.yml

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
  first_name: one
  last_name: Hotmail
  email: [email protected]
#  password: 123greetings
  encrypted_password: <%= User.new.send(:password_digest, '123greetings') %>
  confirmed_at: <%= DateTime.now %>
  created_at: 2018-11-26 14:16:12
  updated_at: 2018-11-26 14:16:12

two:
  first_name: one
  last_name: Gmail
  email: [email protected]
#  password: 123greetings
  encrypted_password: <%= User.new.send(:password_digest, '123greetings') %>
  confirmed_at: <%= DateTime.now %>
  created_at: 2018-11-26 14:16:12
  updated_at: 2018-11-26 14:16:12

But I am not able to persist this data into the database via command line. Yes the data get persisted when write

fixtures :users

inside my controller, But how to persist at boot time of the project string in test mode.
and data should refresh on restarting the server in test mode. thanks in advance

Upvotes: 0

Views: 1785

Answers (1)

Paweł Gościcki
Paweł Gościcki

Reputation: 9604

For database fixtures being available before the application boots, you need to execute this rake task:

RAILS_ENV=test FIXTURES_PATH="spec/fixtures" rails db:fixtures:load

Upvotes: 2

Related Questions