summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-10-19 15:57:20 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-10-20 12:58:49 -0300
commit6d04f3789cc16f7211fb3d465956bbd84c9430b4 (patch)
tree930ed33ccbf391cc8a984e61288749141144f1a3 /spec/models
parent00c15cc27c33dd387069fce5777beb29d01f55ac (diff)
downloadgitlab-ce-non-existing-repo-optimization.tar.gz
Avoid calling underlying methods on non-existing reposnon-existing-repo-optimization
This saves us Rugged/gRPC invocations
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/repository_spec.rb34
1 files changed, 28 insertions, 6 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 39d188f18af..874368ada67 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -2110,19 +2110,41 @@ describe Repository do
end
describe '#cache_method_output', :use_clean_rails_memory_store_caching do
+ let(:fallback) { 10 }
+
context 'with a non-existing repository' do
- let(:value) do
- repository.cache_method_output(:cats, fallback: 10) do
- raise Rugged::ReferenceError
+ let(:project) { create(:project) } # No repository
+
+ subject do
+ repository.cache_method_output(:cats, fallback: fallback) do
+ repository.cats_call_stub
end
end
- it 'returns a fallback value' do
- expect(value).to eq(10)
+ it 'returns the fallback value' do
+ expect(subject).to eq(fallback)
+ end
+
+ it 'avoids calling the original method' do
+ expect(repository).not_to receive(:cats_call_stub)
+
+ subject
+ end
+ end
+
+ context 'with a method throwing a non-existing-repository error' do
+ subject do
+ repository.cache_method_output(:cats, fallback: fallback) do
+ raise Gitlab::Git::Repository::NoRepository
+ end
+ end
+
+ it 'returns the fallback value' do
+ expect(subject).to eq(fallback)
end
it 'does not cache the data' do
- value
+ subject
expect(repository.instance_variable_defined?(:@cats)).to eq(false)
expect(repository.send(:cache).exist?(:cats)).to eq(false)