diff options
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 42151d86ac0..610b3e47c11 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -4084,4 +4084,46 @@ describe User, :do_not_mock_admin_mode do end end end + + describe '#read_only_attribute?' do + context 'when LDAP server is enabled' do + before do + allow(Gitlab::Auth::LDAP::Config).to receive(:enabled?).and_return(true) + end + + %i[name email location].each do |attribute| + it "is true for #{attribute}" do + expect(subject.read_only_attribute?(attribute)).to be_truthy + end + end + + context 'and ldap_readonly_attributes feature is disabled' do + before do + stub_feature_flags(ldap_readonly_attributes: false) + end + + %i[name email location].each do |attribute| + it "is false" do + expect(subject.read_only_attribute?(attribute)).to be_falsey + end + end + end + end + + context 'when synced attributes metadata is present' do + it 'delegates to synced_attributes_metadata' do + subject.build_user_synced_attributes_metadata + + expect(subject.build_user_synced_attributes_metadata) + .to receive(:read_only?).with(:email).and_return('return-value') + expect(subject.read_only_attribute?(:email)).to eq('return-value') + end + end + + context 'when synced attributes metadata is present' do + it 'is false for any attribute' do + expect(subject.read_only_attribute?(:email)).to be_falsey + end + end + end end |