Skip to content

Commit

Permalink
Adds gravatar_hash on user creation and specs
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Manohar J <akash@akash.im>
  • Loading branch information
HashNuke committed Mar 22, 2012
1 parent 06fffb4 commit b408902
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class User < ActiveRecord::Base

has_many :activities
before_save :ensure_authentication_token
before_save :ensure_gravatar_hash

# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
Expand All @@ -16,4 +17,8 @@ def bushido_extra_attributes(extra_attributes)
self.email = extra_attributes["email"]
end

def ensure_gravatar_hash
self.gravatar_hash = Digest::MD5.hexdigest self.email
end

end
6 changes: 6 additions & 0 deletions db/migrate/20120322155347_add_gravatar_hash_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddGravatarHashToUsers < ActiveRecord::Migration
def change
add_column :users, :gravatar_hash, :text

end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120306163143) do
ActiveRecord::Schema.define(:version => 20120322155347) do

create_table "activities", :force => true do |t|
t.text "content"
Expand Down Expand Up @@ -68,6 +68,7 @@
t.string "locale"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "gravatar_hash"
end

add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true
Expand Down
7 changes: 6 additions & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
end
end

it "user should have authentication token on creation" do
it "should have authentication token on creation" do
@user = Factory :user
@user.authentication_token.should_not be_nil
end

it "should have gravatar hash on creation" do
@user = Factory :user
@user.gravatar_hash.should_not be_nil
end
end

0 comments on commit b408902

Please sign in to comment.