diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:22:29 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:22:29 +0000 |
commit | 61d81025139e2e6b3706c05eee4e60ff13417323 (patch) | |
tree | 517dc8ebc4a9f8d74fd77eb7bd6d5466d5184d94 /spec/models | |
parent | 25fc1060affe576fd7c2f8aad586c5109c51cf7e (diff) | |
download | gitlab-ce-61d81025139e2e6b3706c05eee4e60ff13417323.tar.gz |
Add latest changes from gitlab-org/gitlab@14-0-stable-ee
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/lfs_download_object_spec.rb | 50 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 26 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 32 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 1 |
4 files changed, 87 insertions, 22 deletions
diff --git a/spec/models/lfs_download_object_spec.rb b/spec/models/lfs_download_object_spec.rb index d1c323cd177..d82e432b7d6 100644 --- a/spec/models/lfs_download_object_spec.rb +++ b/spec/models/lfs_download_object_spec.rb @@ -6,8 +6,45 @@ RSpec.describe LfsDownloadObject do let(:oid) { 'cd293be6cea034bd45a0352775a219ef5dc7825ce55d1f7dae9762d80ce64411' } let(:link) { 'http://www.example.com' } let(:size) { 1 } + let(:headers) { { test: "asdf" } } - subject { described_class.new(oid: oid, size: size, link: link) } + subject { described_class.new(oid: oid, size: size, link: link, headers: headers) } + + describe '#headers' do + it 'returns specified Hash' do + expect(subject.headers).to eq(headers) + end + + context 'with nil headers' do + let(:headers) { nil } + + it 'returns a Hash' do + expect(subject.headers).to eq({}) + end + end + end + + describe '#has_authorization_header?' do + it 'returns false' do + expect(subject.has_authorization_header?).to be false + end + + context 'with uppercase form' do + let(:headers) { { 'Authorization' => 'Basic 12345' } } + + it 'returns true' do + expect(subject.has_authorization_header?).to be true + end + end + + context 'with lowercase form' do + let(:headers) { { 'authorization' => 'Basic 12345' } } + + it 'returns true' do + expect(subject.has_authorization_header?).to be true + end + end + end describe 'validations' do it { is_expected.to validate_numericality_of(:size).is_greater_than_or_equal_to(0) } @@ -66,5 +103,16 @@ RSpec.describe LfsDownloadObject do end end end + + context 'headers attribute' do + it 'only nil and Hash values are valid' do + aggregate_failures do + expect(described_class.new(oid: oid, size: size, link: 'http://www.example.com', headers: nil)).to be_valid + expect(described_class.new(oid: oid, size: size, link: 'http://www.example.com', headers: {})).to be_valid + expect(described_class.new(oid: oid, size: size, link: 'http://www.example.com', headers: { 'test' => 123 })).to be_valid + expect(described_class.new(oid: oid, size: size, link: 'http://www.example.com', headers: 'test')).to be_invalid + end + end + end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 7eb02749f72..144b00e1d2e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -3122,35 +3122,19 @@ RSpec.describe Project, factory_default: :keep do end end - describe '#change_head' do - let_it_be(:project) { create(:project, :repository) } - - it 'returns error if branch does not exist' do - expect(project.change_head('unexisted-branch')).to be false - expect(project.errors.size).to eq(1) - end - - it 'calls the before_change_head and after_change_head methods' do - expect(project.repository).to receive(:before_change_head) - expect(project.repository).to receive(:after_change_head) - - project.change_head(project.default_branch) - end + describe '#after_repository_change_head' do + let_it_be(:project) { create(:project) } it 'updates commit count' do expect(ProjectCacheWorker).to receive(:perform_async).with(project.id, [], [:commit_count]) - project.change_head(project.default_branch) - end - - it 'copies the gitattributes' do - expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch) - project.change_head(project.default_branch) + project.after_repository_change_head end it 'reloads the default branch' do expect(project).to receive(:reload_default_branch) - project.change_head(project.default_branch) + + project.after_repository_change_head end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index b6f09babb4b..c896b6c0c6c 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -2138,6 +2138,12 @@ RSpec.describe Repository do repository.after_change_head end + + it 'calls after_repository_change_head on container' do + expect(repository.container).to receive(:after_repository_change_head) + + repository.after_change_head + end end describe '#expires_caches_for_tags' do @@ -3261,4 +3267,30 @@ RSpec.describe Repository do settings.save! end end + + describe '#change_head' do + let(:branch) { repository.container.default_branch } + + it 'adds an error to container if branch does not exist' do + expect(repository.change_head('unexisted-branch')).to be false + expect(repository.container.errors.size).to eq(1) + end + + it 'calls the before_change_head and after_change_head methods' do + expect(repository).to receive(:before_change_head) + expect(repository).to receive(:after_change_head) + + repository.change_head(branch) + end + + it 'copies the gitattributes' do + expect(repository).to receive(:copy_gitattributes).with(branch) + repository.change_head(branch) + end + + it 'reloads the default branch' do + expect(repository.container).to receive(:reload_default_branch) + repository.change_head(branch) + end + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 2185df0609e..e86a9c262d8 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -394,6 +394,7 @@ RSpec.describe User do expect(user).not_to be_valid expect(user.errors.full_messages).to include('Username ending with MIME type format is not allowed.') + expect(build(:user, username: "test#{type}")).to be_valid end end |