rails如何从yml文件创建临时数据库?

时间:2018-06-13 23:34:48

标签: ruby-on-rails ruby

关注rails教程https://www.railstutorial.org/book/basic_login

users.yml里

michael:
  name: Michael Example
  email: michael@example.comm
  password_digest: <%= User.digest('password') %>

users_login_test.rb

require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

  def setup
    @user = users(:michael)
  end

  test "login with valid information" do
    get login_path
    post login_path, params: { session: { email:    @user.email,
                                          password: 'password' } }
    assert_redirected_to @user
    follow_redirect!
    assert_template 'users/show'
    assert_select "a[href=?]", login_path, count: 0
    assert_select "a[href=?]", logout_path
    assert_select "a[href=?]", user_path(@user)
  end
end
  1. 通过调试用户Michael可以在不注册的情况下登录,因为我怀疑 users.yml 成为数据库,但是它是如何做到的?
  2. 有没有办法通过byebug或pry来解决这个问题?

1 个答案:

答案 0 :(得分:0)

  

我怀疑users.yml成了数据库

关闭,但不完全。 users.yml的内容已插入您的测试数据库(在database.yml中配置)。

这称为fixtures