Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[#74] initialize salt for old user records without salt

  • Loading branch information...
commit 8eca763745dc845c90808107addfbb6d64e8f219 1 parent 340f518
@croaky croaky authored
Showing with 11 additions and 1 deletion.
  1. +1 −1  lib/clearance/user.rb
  2. +10 −0 test/models/user_test.rb
View
2  lib/clearance/user.rb
@@ -143,7 +143,7 @@ def generate_hash(string)
end
def initialize_salt
- if new_record?
+ if salt.blank?
self.salt = generate_hash("--#{Time.now.utc}--#{password}--#{rand}--")
end
end
View
10 test/models/user_test.rb
@@ -28,6 +28,16 @@ class UserTest < ActiveSupport::TestCase
assert_not_nil Factory(:user).salt
end
+ should "initialize salt for old user records without salt" do
+ user = Factory(:user)
+ sql = "update users set salt = NULL where id = #{user.id}"
+ ActiveRecord::Base.connection.update(sql)
+ assert_nil user.reload.salt
+
+ user.save
+ assert_not_nil user.salt
+ end
+
should "initialize confirmation token" do
assert_not_nil Factory(:user).confirmation_token
end
Please sign in to comment.
Something went wrong with that request. Please try again.