【问题标题】:How to load the rspec fixtures in to the database from the files如何将 rspec 固定装置从文件加载到数据库中
【发布时间】:2019-02-26 11:57:02
【问题描述】:

我正在使用带有 ruby​​ 2.4 和 gem 'rspec-rails', '~> 3.8' 的 rails 5
我正在为用户模型使用“设计”gem,它的夹具如下: 夹具:users.yml

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

one:
  first_name: one
  last_name: Hotmail
  email: vidur.punj@gmail.com
#  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: vidur.punj@hotmail.com
#  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

但我无法通过命令行将这些数据保存到数据库中。 是的,写入时数据会持久化

fixtures :users

在我的控制器中, 但是如何在测试模式下在项目字符串的启动时持久化。
并且数据应该在测试模式下重新启动服务器时刷新。 在此先感谢

【问题讨论】:

  • rake db:fixtures:load RAILS_ENV=test FIXTURES_PATH=spec/fixtures
  • 红宝石 4? Ruby 3 尚未发布。
  • ruby 2.4 和 rails 5

标签: rspec ruby-on-rails-5 rspec-rails ruby-on-rails-5.2


【解决方案1】:

对于在应用程序启动之前可用的数据库设备,您需要执行此 rake 任务:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 2012-10-07
    • 2013-01-09
    相关资源
    最近更新 更多