Mysql2::Error: Column 'encrypted_password' cannot be null

130 Views Asked by At

Rails 5, ruby 2.4.0 Error: rails while running rails test

Mysql2::Error: Column 'encrypted_password' cannot be null

My test: utilities_controller_test.rb

require 'test_helper'

class UsersControllerTest < ActionDispatch::IntegrationTest
  test "Has first name vidur" do
    get users_update_address_url
    assert_equal "vidur", users(:regular).first_name
  end

end

My Fixture: users.yml

admin:
 id: 1
 first_name: admin
 last_name: tukaweb
 email: '[email protected]'
 encrypted_password: <% Devise::Encryptor.digest(User, 'password') %>

regular:
 id: 2
 first_name: vidur
 last_name: punj
 email: '[email protected]'
 encrypted_password: <% Devise::Encryptor.digest(User, 'password') %>
1

There are 1 best solutions below

0
NM Pennypacker On

You probably want to print the output of that Ruby code instead of just evaluating it, so you'll want to change your ERB delimiters from the evaluate-only to output.

In other words, change

<% %> to <%= %>

So in your case:

encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>