FEATURE: Implement refresh method for bio
https://github.com/mozilla/discourse/issues/183
This commit is contained in:
Родитель
2b49d2b2dd
Коммит
ded00deded
|
@ -104,6 +104,7 @@ require_relative "profile/update_emails"
|
|||
require_relative "profile/duplicate_accounts"
|
||||
require_relative "profile/is_aal_enough"
|
||||
require_relative "profile/dinopark_enabled"
|
||||
require_relative "profile/update_bio"
|
||||
require_relative "profile/update_name"
|
||||
require_relative "profile/update_title"
|
||||
require_relative "profile/update_username"
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
module MozillaIAM
|
||||
Profile.class_eval do
|
||||
during_refresh :update_bio
|
||||
|
||||
def update_bio
|
||||
return unless dinopark_enabled?
|
||||
|
||||
bio = attr(:description)
|
||||
return if @user.user_profile.bio_raw == bio
|
||||
|
||||
unless bio.blank?
|
||||
@user.user_profile.update(bio_raw: bio)
|
||||
else
|
||||
@user.user_profile.update(bio_raw: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# name: mozilla-iam
|
||||
# about: A plugin to integrate Discourse with Mozilla's Identity and Access Management (IAM) system
|
||||
# version: 1.2.0-alpha.5
|
||||
# version: 1.2.0-alpha.6
|
||||
# authors: Leo McArdle
|
||||
# url: https://github.com/mozilla/discourse-mozilla-iam
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
require_relative '../../../iam_helper'
|
||||
|
||||
describe MozillaIAM::Profile do
|
||||
|
||||
shared_context "shared context" do
|
||||
before do
|
||||
user.user_profile.update(bio_raw: "Default description")
|
||||
end
|
||||
let!(:bio_before) { user.user_profile.bio_raw }
|
||||
let!(:bio_cooked_before) { user.user_profile.bio_cooked }
|
||||
end
|
||||
|
||||
shared_context "with attribute already set" do
|
||||
before do
|
||||
profile.expects(:attr).with(:description).returns(bio_before)
|
||||
user.user_profile.expects(:update).never
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "no change" do
|
||||
it "does nothing" do
|
||||
profile.send(:update_bio)
|
||||
user.reload
|
||||
expect(user.user_profile.bio_raw).to eq bio_before
|
||||
expect(user.user_profile.bio_cooked).to eq bio_cooked_before
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "undefines" do
|
||||
it "makes the user's bio blank" do
|
||||
profile.send(:update_bio)
|
||||
user.reload
|
||||
expect(user.user_profile.bio_raw).to eq nil
|
||||
expect(user.user_profile.bio_cooked).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "with dinopark_enabled? set to true" do
|
||||
context "with a dinopark description" do
|
||||
before do
|
||||
profile.expects(:attr).with(:description).returns("This is a description of who I am")
|
||||
end
|
||||
|
||||
it "updates the user's bio" do
|
||||
profile.send(:update_bio)
|
||||
user.reload
|
||||
expect(user.user_profile.bio_raw).to eq "This is a description of who I am"
|
||||
expect(user.user_profile.bio_cooked).to eq "<p>This is a description of who I am</p>"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
include_examples "dinopark refresh method", :update_bio, :description
|
||||
end
|
Загрузка…
Ссылка в новой задаче