In order to have friendlier names to my column, I ran the following migration :
class RenameDigestColumnsOnUserToEncryptedTokens < ActiveRecord::Migration[5.0]
def change
rename_column :users, :password_digest, :encrypted_password
rename_column :users, :activation_digest, :encrypted_activation_token
rename_column :users, :reset_digest, :encrypted_reset_password_token
end
end
It worked well, the columns are effectively renamed in my database.
I renamed accordingly all the actions I could have with these names, which means I don't have anything remaining in my code with whether Password_digest, activation_digest or reset_digest.
The problem is when I run the tests, I still get the errors as if I hadn't renamed them in the project, eg this kind of errors :
.E
Error:
PasswordResetsTest#test_password_resets:
NoMethodError: undefined method `password_digest' for #<User:0x00563d149684d8>
Did you mean? password
app/controllers/password_resets_controller.rb:29:in `update'
test/integration/password_resets_test.rb:42:in `block in <class:PasswordResetsTest>'
bin/rails test test/integration/password_resets_test.rb:10
The code of the password_resets_controller's update action is what follows :
def update
if params[:user][:password].empty?
@user.errors.add(:password, "can't be empty")
render 'edit'
elsif @user.update_attributes(user_params)
log_in @user
# to prevent, on a public machine for example, people from pressing the back button and changing
# the password (and getting logged in to the site) whereas it's always been reset
@user.update_attribute(:encrypted_reset_password_token, nil)
flash[:success] = 'Password has been reset.'
redirect_to @user
else
render 'edit'
end
end
And the related log_in method :
# Logs in the given user.
def log_in(user)
session[:user_id] = user.id
end
I tried restarting spring and even rebooting the computer, I can't see where it comes from, how the computer can still see these names.
I am using the bcrypt gem to generate encrypted tokens, formerly named with digest, and this is those ones I tried to rename.
Has anyone ever had this problem ? Thanks in advance for your help.
如果您看到有关 password_digest 列的错误,您可能正在使用需要该列的活动记录has_secure_password : http : //api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.