Testing User Model (Devise Authentication) with MiniTest

此生再无相见时 提交于 2019-12-04 17:02:23

I got a work around after some investigation like below: Add a helper method for fixture:

module FixtureFileHelpers
  def encrypted_password(password = 'password123')
    User.new.send(:password_digest, password)
  end
end

ActiveRecord::FixtureSet.context_class.send :include, FixtureFileHelpers

And make fixture like this:

default:
  email: 'default@example.com'
  name: "User name"
  encrypted_password: <%= encrypted_password %>
  work_number: '(911) 235-9871'
  cell_number: '(911) 235-9871'

And use this fixture as user object in user test.

def setup
    @user = users(:default)
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!