diff --git a/app/models/user.rb b/app/models/user.rb index abc239b6..9127cd74 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 @@ -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 diff --git a/db/migrate/20120322155347_add_gravatar_hash_to_users.rb b/db/migrate/20120322155347_add_gravatar_hash_to_users.rb new file mode 100644 index 00000000..8252cac0 --- /dev/null +++ b/db/migrate/20120322155347_add_gravatar_hash_to_users.rb @@ -0,0 +1,6 @@ +class AddGravatarHashToUsers < ActiveRecord::Migration + def change + add_column :users, :gravatar_hash, :text + + end +end diff --git a/db/schema.rb b/db/schema.rb index 0405faf1..fe4dc76d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0f6ecc75..90acdf78 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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