diff options
author | Rémy Coutable <remy@rymai.me> | 2018-10-17 16:05:23 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-10-17 16:05:23 +0000 |
commit | 34f89db60881aa3e478323d82a4987fdbdeafc32 (patch) | |
tree | 76d4d21178d86170a6240ab5d0582db798c7445f /spec | |
parent | a621c8d0ea6891456605245fed014996538abed5 (diff) | |
parent | 0669127a328af171850afb01deef2a07eb89a6a6 (diff) | |
download | gitlab-ce-34f89db60881aa3e478323d82a4987fdbdeafc32.tar.gz |
Merge branch '49591-use-cached-readme-blobs' into 'master'
Use cached readme blobs where appropriate
Closes #49591
See merge request gitlab-org/gitlab-ce!22325
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/project_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 28 |
2 files changed, 31 insertions, 11 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index a807c336165..88f70a88210 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -527,28 +527,28 @@ describe Project do end describe "#readme_url" do - let(:project) { create(:project, :repository, path: "somewhere") } - context 'with a non-existing repository' do - it 'returns nil' do - allow(project.repository).to receive(:tree).with(:head).and_return(nil) + let(:project) { create(:project) } + it 'returns nil' do expect(project.readme_url).to be_nil end end context 'with an existing repository' do context 'when no README exists' do - it 'returns nil' do - allow_any_instance_of(Tree).to receive(:readme).and_return(nil) + let(:project) { create(:project, :empty_repo) } + it 'returns nil' do expect(project.readme_url).to be_nil end end context 'when a README exists' do + let(:project) { create(:project, :repository) } + it 'returns the README' do - expect(project.readme_url).to eql("#{Gitlab.config.gitlab.url}/#{project.namespace.full_path}/somewhere/blob/master/README.md") + expect(project.readme_url).to eq("#{project.web_url}/blob/master/README.md") end end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index fb16a321e4b..799a60ac62f 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -461,6 +461,24 @@ describe Repository do it { is_expected.to be_nil } end + + context 'regular blob' do + subject { repository.blob_at(repository.head_commit.sha, '.gitignore') } + + it { is_expected.to be_an_instance_of(::Blob) } + end + + context 'readme blob on HEAD' do + subject { repository.blob_at(repository.head_commit.sha, 'README.md') } + + it { is_expected.to be_an_instance_of(::ReadmeBlob) } + end + + context 'readme blob not on HEAD' do + subject { repository.blob_at(repository.find_branch('feature').target, 'README.md') } + + it { is_expected.to be_an_instance_of(::Blob) } + end end describe '#merged_to_root_ref?' do @@ -1922,23 +1940,25 @@ describe Repository do describe '#readme', :use_clean_rails_memory_store_caching do context 'with a non-existing repository' do - it 'returns nil' do - allow(repository).to receive(:tree).with(:head).and_return(nil) + let(:project) { create(:project) } + it 'returns nil' do expect(repository.readme).to be_nil end end context 'with an existing repository' do context 'when no README exists' do - it 'returns nil' do - allow_any_instance_of(Tree).to receive(:readme).and_return(nil) + let(:project) { create(:project, :empty_repo) } + it 'returns nil' do expect(repository.readme).to be_nil end end context 'when a README exists' do + let(:project) { create(:project, :repository) } + it 'returns the README' do expect(repository.readme).to be_an_instance_of(ReadmeBlob) end |