Skip to content

Commit

Permalink
[thoughtbot#74] initialize salt for old user records without salt
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Croak committed Feb 21, 2010
1 parent 340f518 commit 8eca763
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/clearance/user.rb
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/models/user_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 8eca763

Please sign in to comment.