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