Skip to content

Commit

Permalink
break saving out into their own methods to keep it a bit more DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
maddox committed Apr 12, 2012
1 parent 38169e1 commit a94c495
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,24 @@ def self.find_by_token(token)
# Returns itself.
def save
$redis.sadd KEY, login
save_email
save_token
self
end

# Public: Saves the email.
#
# Returns bool.
def save_email
$redis.set "#{KEY}:#{login}:email", email
end

# Public: Saves the token.
#
# Returns bool.
def save_token
$redis.set "#{KEY}:#{login}:token", token
$redis.set "#{KEY}:#{token}:login", login
self
end

# Public: The MD5 hash of the user's email account. Used for showing their
Expand Down
21 changes: 21 additions & 0 deletions test/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@
assert_equal @user.email, user.email
end

test "save email" do
user = User.create('maddox','1@example.com')
user.email = "saved@example.com"
user.save_email

found_user = User.find('maddox')

assert_equal 'saved@example.com', found_user.email
end

test "save token" do
user = User.create('tater','2@example.com')
user.token = "YYYYYY"
user.save_token

found_user = User.find('tater')

assert_equal 'YYYYYY', found_user.token
end



test "gravatar_id" do
assert_equal "fb8d9bbe8a1150bc9fed0b0f99bbfc47", @user.gravatar_id
Expand Down

0 comments on commit a94c495

Please sign in to comment.