Use retro gravatars for default avatars
This commit is contained in:
parent
cd0030a376
commit
45d1d6c18b
Binary file not shown.
Before Width: | Height: | Size: 285 B |
@ -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
|
||||
|
@ -0,0 +1,5 @@
|
||||
class RemoveAvatarUrlFromUsers < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :users, :avatar_url
|
||||
end
|
||||
end
|
@ -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"
|
||||
|
@ -3,39 +3,28 @@ require 'rails_helper'
|
||||
describe AvatarHelper do
|
||||
|
||||
def expected_img(src)
|
||||
%(<img alt="satyr" class="avatar" src="#{src}" />)
|
||||
%(<img alt="satyr" class="avatar" src="#{src.gsub('&', '&')}" />)
|
||||
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 "and user has an email" do
|
||||
context "when user has an email" do
|
||||
let(:email) { 'foo@email.com' }
|
||||
|
||||
it { should eq(expected_img(
|
||||
'//gravatar.com/avatar/9dcfeb70fe212ea12562dddd22b0fc92?s=128')) }
|
||||
'//gravatar.com/avatar/9dcfeb70fe212ea12562dddd22b0fc92?s=128&d=retro')) }
|
||||
end
|
||||
|
||||
context "and user has no email" do
|
||||
context "when user has no email" do
|
||||
let(:email) { nil }
|
||||
|
||||
it { should eq(expected_img("http://avatar/url")) }
|
||||
end
|
||||
end
|
||||
|
||||
context "when user has neither email nor avatar_url" 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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user