Permalink
Browse files

break saving out into their own methods to keep it a bit more DRY

  • Loading branch information...
1 parent 38169e1 commit a94c495f5f3cac2ddab64bcbd767fd4652f3c54d @maddox maddox committed Apr 12, 2012
Showing with 36 additions and 1 deletion.
  1. +15 −1 app/models/user.rb
  2. +21 −0 test/user_test.rb
View
@@ -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
View
@@ -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

0 comments on commit a94c495

Please sign in to comment.