diff --git a/app/assets/images/default_avatar.png b/app/assets/images/default_avatar.png deleted file mode 100644 index 69b6b15..0000000 Binary files a/app/assets/images/default_avatar.png and /dev/null differ diff --git a/app/decorators/helpers/avatar_helper.rb b/app/decorators/helpers/avatar_helper.rb index ef026ad..254e78f 100644 --- a/app/decorators/helpers/avatar_helper.rb +++ b/app/decorators/helpers/avatar_helper.rb @@ -7,18 +7,10 @@ module AvatarHelper private def avatar_url - gravatar_url || model.avatar_url || default_avatar_filename - end - - def gravatar_url - return unless model.email.present? - - hash = Digest::MD5.hexdigest(model.email.to_s.downcase) - "//gravatar.com/avatar/#{hash}?s=128" - end - - def default_avatar_filename - h.image_path "default_avatar.png" + username = model.username || model.temporary_username || model.id + email = model.email || "#{username}@asciinema.org" + hash = Digest::MD5.hexdigest(email.downcase) + "//gravatar.com/avatar/#{hash}?s=128&d=retro" end end diff --git a/db/migrate/20141129115837_remove_avatar_url_from_users.rb b/db/migrate/20141129115837_remove_avatar_url_from_users.rb new file mode 100644 index 0000000..18d9a18 --- /dev/null +++ b/db/migrate/20141129115837_remove_avatar_url_from_users.rb @@ -0,0 +1,5 @@ +class RemoveAvatarUrlFromUsers < ActiveRecord::Migration + def change + remove_column :users, :avatar_url + end +end diff --git a/db/schema.rb b/db/schema.rb index 12476ec..f190f3a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141127112626) do +ActiveRecord::Schema.define(version: 20141129115837) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -100,7 +100,6 @@ ActiveRecord::Schema.define(version: 20141127112626) do t.string "uid" t.string "email" t.string "name" - t.string "avatar_url" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "username" diff --git a/spec/decorators/helpers/avatar_helper_spec.rb b/spec/decorators/helpers/avatar_helper_spec.rb index 9029c3c..a6f6b60 100644 --- a/spec/decorators/helpers/avatar_helper_spec.rb +++ b/spec/decorators/helpers/avatar_helper_spec.rb @@ -3,39 +3,28 @@ require 'rails_helper' describe AvatarHelper do def expected_img(src) - %(satyr) + %(satyr) end let(:decorator) { double('decorator', h: h, model: model). extend(described_class) } - let(:model) { double('model', username: 'satyr', avatar_url: avatar_url, - email: email) } + let(:model) { double('model', username: 'satyr', email: email) } describe '#avatar_image_tag' do subject { decorator.avatar_image_tag } - context "when user has an avatar_url" do - let(:avatar_url) { 'http://avatar/url' } + context "when user has an email" do + let(:email) { 'foo@email.com' } - context "and user has an email" do - let(:email) { 'foo@email.com' } - - it { should eq(expected_img( - '//gravatar.com/avatar/9dcfeb70fe212ea12562dddd22b0fc92?s=128')) } - end - - context "and user has no email" do - let(:email) { nil } - - it { should eq(expected_img("http://avatar/url")) } - end + it { should eq(expected_img( + '//gravatar.com/avatar/9dcfeb70fe212ea12562dddd22b0fc92?s=128&d=retro')) } end - context "when user has neither email nor avatar_url" do + context "when user has no email" do let(:email) { nil } - let(:avatar_url) { nil } - it { should eq(expected_img('/assets/default_avatar.png')) } + it { should eq(expected_img( + '//gravatar.com/avatar/9c0388ed63799af1e5f588e610851f0c?s=128&d=retro')) } end end