mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: registration fails with timeout on gravatar
This commit is contained in:
parent
b2e2a99898
commit
521226f4c9
6 changed files with 46 additions and 33 deletions
18
app/jobs/regular/update_gravatar.rb
Normal file
18
app/jobs/regular/update_gravatar.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module Jobs
|
||||
|
||||
class UpdateGravatar < Jobs::Base
|
||||
|
||||
def execute(args)
|
||||
user = User.find_by(id: args[:user_id])
|
||||
avatar = UserAvatar.find_by(id: args[:avatar_id])
|
||||
|
||||
if user && avatar
|
||||
avatar.update_gravatar!
|
||||
if !user.uploaded_avatar_id && avatar.gravatar_upload_id
|
||||
user.update_column(:uploaded_avatar_id, avatar.gravatar_upload_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -638,15 +638,9 @@ class User < ActiveRecord::Base
|
|||
return if @import_mode
|
||||
|
||||
avatar = user_avatar || create_user_avatar
|
||||
gravatar_downloaded = false
|
||||
|
||||
if SiteSetting.automatically_download_gravatars? && !avatar.last_gravatar_download_attempt
|
||||
avatar.update_gravatar!
|
||||
gravatar_downloaded = avatar.gravatar_upload_id
|
||||
end
|
||||
|
||||
if !self.uploaded_avatar_id && gravatar_downloaded
|
||||
self.update_column(:uploaded_avatar_id, avatar.gravatar_upload_id)
|
||||
Jobs.enqueue(:update_gravatar, user_id: self.id, avatar_id: avatar.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require_dependency 'letter_avatar'
|
||||
|
||||
class UserAvatar < ActiveRecord::Base
|
||||
MAX_SIZE = 240
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :gravatar_upload, class_name: 'Upload', dependent: :destroy
|
||||
belongs_to :custom_upload, class_name: 'Upload', dependent: :destroy
|
||||
|
|
21
spec/jobs/update_gravatar_spec.rb
Normal file
21
spec/jobs/update_gravatar_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Jobs::UpdateGravatar do
|
||||
|
||||
it "picks gravatar if system avatar is picked and gravatar was just downloaded" do
|
||||
user = User.create!(username: "bob", name: "bob", email: "a@a.com")
|
||||
user.uploaded_avatar_id.should == nil
|
||||
user.user_avatar.gravatar_upload_id.should == nil
|
||||
|
||||
png = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
|
||||
FakeWeb.register_uri(:get, "http://www.gravatar.com/avatar/d10ca8d11301c2f4993ac2279ce4b930.png?s=500&d=404", body: png)
|
||||
|
||||
SiteSetting.automatically_download_gravatars = true
|
||||
|
||||
user.refresh_avatar
|
||||
user.reload
|
||||
|
||||
user.uploaded_avatar_id.should == user.user_avatar.gravatar_upload_id
|
||||
end
|
||||
|
||||
end
|
|
@ -1094,7 +1094,6 @@ describe User do
|
|||
|
||||
describe "automatic avatar creation" do
|
||||
it "sets a system avatar for new users" do
|
||||
SiteSetting.enable_system_avatars = true
|
||||
u = User.create!(username: "bob", email: "bob@bob.com")
|
||||
u.reload
|
||||
u.uploaded_avatar_id.should == nil
|
||||
|
@ -1128,30 +1127,14 @@ describe User do
|
|||
end
|
||||
|
||||
describe "refresh_avatar" do
|
||||
it "picks gravatar if system avatar is picked and gravatar was just downloaded" do
|
||||
|
||||
png = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
|
||||
FakeWeb.register_uri( :get,
|
||||
"http://www.gravatar.com/avatar/d10ca8d11301c2f4993ac2279ce4b930.png?s=500&d=404",
|
||||
body: png )
|
||||
|
||||
user = User.create!(username: "bob", name: "bob", email: "a@a.com")
|
||||
user.reload
|
||||
|
||||
it "enqueues the update_gravatar job when automatically downloading gravatars" do
|
||||
SiteSetting.automatically_download_gravatars = true
|
||||
SiteSetting.enable_system_avatars = true
|
||||
|
||||
user = Fabricate(:user)
|
||||
|
||||
Jobs.expects(:enqueue).with(:update_gravatar, anything)
|
||||
|
||||
user.refresh_avatar
|
||||
user.reload
|
||||
|
||||
user.user_avatar.gravatar_upload_id.should == user.uploaded_avatar_id
|
||||
|
||||
user.uploaded_avatar_id = nil
|
||||
user.save
|
||||
user.refresh_avatar
|
||||
|
||||
user.reload
|
||||
user.uploaded_avatar_id.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ Spork.prefork do
|
|||
# let's not run seed_fu every test
|
||||
SeedFu.quiet = true if SeedFu.respond_to? :quiet
|
||||
|
||||
SiteSetting.enable_system_avatars = false
|
||||
SiteSetting.automatically_download_gravatars = false
|
||||
|
||||
SeedFu.seed
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
@ -90,7 +90,6 @@ Spork.prefork do
|
|||
end
|
||||
|
||||
# very expensive IO operations
|
||||
SiteSetting.enable_system_avatars = false
|
||||
SiteSetting.automatically_download_gravatars = false
|
||||
|
||||
I18n.locale = :en
|
||||
|
|
Loading…
Reference in a new issue