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:
Diffstat (limited to 'spec/models/user_preference_spec.rb')
-rw-r--r--spec/models/user_preference_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb
index 343576de4d3..ee3fbb97e47 100644
--- a/spec/models/user_preference_spec.rb
+++ b/spec/models/user_preference_spec.rb
@@ -64,6 +64,10 @@ RSpec.describe UserPreference, feature_category: :user_profile do
end
end
+ describe 'associations' do
+ it { is_expected.to belong_to(:home_organization).class_name('Organizations::Organization').optional }
+ end
+
describe 'notes filters global keys' do
it 'contains expected values' do
expect(UserPreference::NOTES_FILTERS.keys).to match_array([:all_notes, :only_comments, :only_activity])
@@ -291,4 +295,30 @@ RSpec.describe UserPreference, feature_category: :user_profile do
expect(pref.read_attribute(:render_whitespace_in_code)).to eq(true)
end
end
+
+ describe '#user_belongs_to_home_organization' do
+ let_it_be(:organization) { create(:organization) }
+
+ context 'when user is an organization user' do
+ before do
+ create(:organization_user, organization: organization, user: user)
+ end
+
+ it 'does not add any validation errors' do
+ user_preference.home_organization = organization
+
+ expect(user_preference).to be_valid
+ expect(user_preference.errors).to be_empty
+ end
+ end
+
+ context 'when user is not an organization user' do
+ it 'adds a validation error' do
+ user_preference.home_organization = organization
+
+ expect(user_preference).to be_invalid
+ expect(user_preference.errors.messages[:user].first).to eq(_("is not part of the given organization"))
+ end
+ end
+ end
end