From 64c4bd5dbf5b6ee05909beb26eadaaee6196748b Mon Sep 17 00:00:00 2001 From: Dan Singerman Date: Wed, 28 Jan 2015 16:52:07 +0000 Subject: [PATCH] Fix force_avatar_update.to_i error as force_avatar_update is a boolean If force_avatar_update is passed in sso attributes it errors on force_avatar_update.to_i. The SingleSignOn class forces avatar_force_update to a boolean, so it should be treated as such. --- app/models/discourse_single_sign_on.rb | 3 +-- ...rb => single_sign_on_record_fabricator.rb} | 0 spec/models/discourse_single_sign_on_spec.rb | 27 ++++++++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) rename spec/fabricators/{single_sign_on_record_fabrictor.rb => single_sign_on_record_fabricator.rb} (100%) diff --git a/app/models/discourse_single_sign_on.rb b/app/models/discourse_single_sign_on.rb index 8d12a17f8a1..bbd849c0e87 100644 --- a/app/models/discourse_single_sign_on.rb +++ b/app/models/discourse_single_sign_on.rb @@ -126,8 +126,7 @@ class DiscourseSingleSignOn < SingleSignOn end if SiteSetting.sso_overrides_avatar && avatar_url.present? && ( - avatar_force_update == "true" || - avatar_force_update.to_i != 0 || + avatar_force_update || sso_record.external_avatar_url != avatar_url) begin diff --git a/spec/fabricators/single_sign_on_record_fabrictor.rb b/spec/fabricators/single_sign_on_record_fabricator.rb similarity index 100% rename from spec/fabricators/single_sign_on_record_fabrictor.rb rename to spec/fabricators/single_sign_on_record_fabricator.rb diff --git a/spec/models/discourse_single_sign_on_spec.rb b/spec/models/discourse_single_sign_on_spec.rb index 22c0f0f5f79..f6aa259c308 100644 --- a/spec/models/discourse_single_sign_on_spec.rb +++ b/spec/models/discourse_single_sign_on_spec.rb @@ -105,23 +105,36 @@ describe DiscourseSingleSignOn do end context 'when sso_overrides_avatar is enabled' do + let!(:sso_record) { Fabricate(:single_sign_on_record, external_avatar_url: "http://example.com/an_image.png") } + let!(:sso) { + sso = DiscourseSingleSignOn.new + sso.username = "test" + sso.name = "test" + sso.email = sso_record.user.email + sso.external_id = sso_record.external_id + sso + } + let(:logo) { file_from_fixtures("logo.png") } before do SiteSetting.sso_overrides_avatar = true end it "deal with no avatar url passed for an existing user with an avatar" do - sso_record = Fabricate(:single_sign_on_record, external_avatar_url: "http://example.com/an_image.png") - - sso = DiscourseSingleSignOn.new - sso.username = "test" - sso.name = "test" - sso.email = sso_record.user.email - sso.external_id = sso_record.external_id # Deliberately not setting avatar_url. user = sso.lookup_or_create_user expect(user).to_not be_nil end + + it "deal with no avatar_force_update passed as a boolean" do + FileHelper.stubs(:download).returns(logo) + + sso.avatar_url = "http://example.com/a_different_image.png" + sso.avatar_force_update = true + + user = sso.lookup_or_create_user + expect(user).to_not be_nil + end end end