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.
This commit is contained in:
Dan Singerman 2015-01-28 16:52:07 +00:00
parent d9ae4e791e
commit 64c4bd5dbf
3 changed files with 21 additions and 9 deletions

View File

@ -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

View File

@ -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