diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/project_spec.rb | 136 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 42 |
2 files changed, 50 insertions, 128 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index df32545b90b..7decc1bc911 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -106,6 +106,14 @@ describe Project do it { is_expected.to have_many(:sourced_pipelines) } it { is_expected.to have_many(:source_pipelines) } + it_behaves_like 'model with repository' do + let_it_be(:container) { create(:project, :repository, path: 'somewhere') } + let(:stubbed_container) { build_stubbed(:project) } + let(:expected_full_path) { "#{container.namespace.full_path}/somewhere" } + let(:expected_repository_klass) { Repository } + let(:expected_storage_klass) { Storage::Hashed } + end + it 'has an inverse relationship with merge requests' do expect(described_class.reflect_on_association(:merge_requests).has_inverse?).to eq(:target_project) end @@ -510,7 +518,6 @@ describe Project do describe 'Respond to' do it { is_expected.to respond_to(:url_to_repo) } - it { is_expected.to respond_to(:repo_exists?) } it { is_expected.to respond_to(:execute_hooks) } it { is_expected.to respond_to(:owner) } it { is_expected.to respond_to(:path_with_namespace) } @@ -664,44 +671,6 @@ describe Project do expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git') end - describe "#web_url" do - let(:project) { create(:project, path: "somewhere") } - - context 'when given the only_path option' do - subject { project.web_url(only_path: only_path) } - - context 'when only_path is false' do - let(:only_path) { false } - - it 'returns the full web URL for this repo' do - expect(subject).to eq("#{Gitlab.config.gitlab.url}/#{project.namespace.full_path}/somewhere") - end - end - - context 'when only_path is true' do - let(:only_path) { true } - - it 'returns the relative web URL for this repo' do - expect(subject).to eq("/#{project.namespace.full_path}/somewhere") - end - end - - context 'when only_path is nil' do - let(:only_path) { nil } - - it 'returns the full web URL for this repo' do - expect(subject).to eq("#{Gitlab.config.gitlab.url}/#{project.namespace.full_path}/somewhere") - end - end - end - - context 'when not given the only_path option' do - it 'returns the full web URL for this repo' do - expect(project.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.namespace.full_path}/somewhere") - end - end - end - describe "#readme_url" do context 'with a non-existing repository' do let(:project) { create(:project) } @@ -931,14 +900,6 @@ describe Project do end end - describe '#repository' do - let(:project) { create(:project, :repository) } - - it 'returns valid repo' do - expect(project.repository).to be_kind_of(Repository) - end - end - describe '#default_issues_tracker?' do it "is true if used internal tracker" do project = build(:project) @@ -954,24 +915,6 @@ describe Project do end end - describe '#empty_repo?' do - context 'when the repo does not exist' do - let(:project) { build_stubbed(:project) } - - it 'returns true' do - expect(project.empty_repo?).to be(true) - end - end - - context 'when the repo exists' do - let(:project) { create(:project, :repository) } - let(:empty_project) { create(:project, :empty_repo) } - - it { expect(empty_project.empty_repo?).to be(true) } - it { expect(project.empty_repo?).to be(false) } - end - end - describe '#external_issue_tracker' do let(:project) { create(:project) } let(:ext_project) { create(:redmine_project) } @@ -3406,59 +3349,6 @@ describe Project do end end - describe '#http_url_to_repo' do - let(:project) { create(:project) } - - context 'when a custom HTTP clone URL root is not set' do - it 'returns the url to the repo without a username' do - expect(project.http_url_to_repo).to eq("#{project.web_url}.git") - expect(project.http_url_to_repo).not_to include('@') - end - end - - context 'when a custom HTTP clone URL root is set' do - before do - stub_application_setting(custom_http_clone_url_root: custom_http_clone_url_root) - end - - context 'when custom HTTP clone URL root has a relative URL root' do - context 'when custom HTTP clone URL root ends with a slash' do - let(:custom_http_clone_url_root) { 'https://git.example.com:51234/mygitlab/' } - - it 'returns the url to the repo, with the root replaced with the custom one' do - expect(project.http_url_to_repo).to eq("https://git.example.com:51234/mygitlab/#{project.full_path}.git") - end - end - - context 'when custom HTTP clone URL root does not end with a slash' do - let(:custom_http_clone_url_root) { 'https://git.example.com:51234/mygitlab' } - - it 'returns the url to the repo, with the root replaced with the custom one' do - expect(project.http_url_to_repo).to eq("https://git.example.com:51234/mygitlab/#{project.full_path}.git") - end - end - end - - context 'when custom HTTP clone URL root does not have a relative URL root' do - context 'when custom HTTP clone URL root ends with a slash' do - let(:custom_http_clone_url_root) { 'https://git.example.com:51234/' } - - it 'returns the url to the repo, with the root replaced with the custom one' do - expect(project.http_url_to_repo).to eq("https://git.example.com:51234/#{project.full_path}.git") - end - end - - context 'when custom HTTP clone URL root does not end with a slash' do - let(:custom_http_clone_url_root) { 'https://git.example.com:51234' } - - it 'returns the url to the repo, with the root replaced with the custom one' do - expect(project.http_url_to_repo).to eq("https://git.example.com:51234/#{project.full_path}.git") - end - end - end - end - end - describe '#lfs_http_url_to_repo' do let(:project) { create(:project) } @@ -5054,16 +4944,6 @@ describe Project do end end - context '#commits_by' do - let(:project) { create(:project, :repository) } - let(:commits) { project.repository.commits('HEAD', limit: 3).commits } - let(:commit_shas) { commits.map(&:id) } - - it 'retrieves several commits from the repository by oid' do - expect(project.commits_by(oids: commit_shas)).to eq commits - end - end - context '#members_among' do let(:users) { create_list(:user, 3) } 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 |