Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 18:08:16 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 18:08:16 +0300
commite80e0dd64fbb04f60394cb1bb08e17dbcb22b8ce (patch)
tree9e538341b9b77e96737964813e10235dbecf47ff /spec/models/user_spec.rb
parentef31adeb0fb9a02b2c6a4529ec4e38d7082a4b2b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r--spec/models/user_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index bbd45afadd7..b7abcb31321 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -55,6 +55,67 @@ describe User, :do_not_mock_admin_mode do
it { is_expected.to have_many(:custom_attributes).class_name('UserCustomAttribute') }
it { is_expected.to have_many(:releases).dependent(:nullify) }
+ describe "#bio" do
+ it 'syncs bio with `user_details.bio` on create' do
+ user = create(:user, bio: 'my bio')
+
+ expect(user.bio).to eq(user.user_detail.bio)
+ end
+
+ context 'when `migrate_bio_to_user_details` feature flag is off' do
+ before do
+ stub_feature_flags(migrate_bio_to_user_details: false)
+ end
+
+ it 'does not sync bio with `user_details.bio`' do
+ user = create(:user, bio: 'my bio')
+
+ expect(user.bio).to eq('my bio')
+ expect(user.user_detail.bio).to eq('')
+ end
+ end
+
+ it 'syncs bio with `user_details.bio` on update' do
+ user = create(:user)
+
+ user.update!(bio: 'my bio')
+
+ expect(user.bio).to eq(user.user_detail.bio)
+ end
+
+ context 'when `user_details` association already exists' do
+ let(:user) { create(:user) }
+
+ before do
+ create(:user_detail, user: user)
+ end
+
+ it 'syncs bio with `user_details.bio`' do
+ user.update!(bio: 'my bio')
+
+ expect(user.bio).to eq(user.user_detail.bio)
+ end
+
+ it 'falls back to "" when nil is given' do
+ user.update!(bio: nil)
+
+ expect(user.bio).to eq(nil)
+ expect(user.user_detail.bio).to eq('')
+ end
+
+ # very unlikely scenario
+ it 'truncates long bio when syncing to user_details' do
+ invalid_bio = 'a' * 256
+ truncated_bio = 'a' * 255
+
+ user.bio = invalid_bio
+ user.save(validate: false)
+
+ expect(user.user_detail.bio).to eq(truncated_bio)
+ end
+ end
+ end
+
describe "#abuse_report" do
let(:current_user) { create(:user) }
let(:other_user) { create(:user) }