summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-11-21 16:11:21 +0100
committerJacob Vosmaer <jacob@gitlab.com>2017-11-21 16:11:21 +0100
commit595631d26fbde49a5644108d75b38da0a53f925a (patch)
tree34bbdc1c90b7904dd006fc0a05bcacfa40105cc9
parent59fbefbdfa18ee59296bc55a7bd62d297d960d5e (diff)
downloadgitlab-ce-branch-exists-redis.tar.gz
refactor testsbranch-exists-redis
-rw-r--r--spec/models/repository_spec.rb39
1 files changed, 16 insertions, 23 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 115af6ab36b..a8e0115cfe5 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -1167,35 +1167,28 @@ describe Repository do
end
describe '#branch_exists?' do
- subject { repository.branch_exists?(branch_name) }
+ it 'uses branch_names' do
+ allow(repository).to receive(:branch_names).and_return(['foobar'])
- before do
- # If raw_repository.branch_names gets called more than once then
- # caching is broken. We don't want that.
- expect(repository.raw_repository).to receive(:branch_names)
- .with(no_args)
- .once
- .and_return(['master'])
+ expect(repository.branch_exists?('foobar')).to eq(true)
+ expect(repository.branch_exists?('master')).to eq(false)
end
+ end
- context 'when true' do
- let(:branch_name) { 'master' }
+ describe '#branch_names' do
+ let(:fake_branch_names) { ['foobar'] }
- it 'returns true and caches it' do
- expect(subject).to eq(true)
- # Second call hits the cache
- expect(subject).to eq(true)
- end
- end
+ it 'gets cached across Repository instances' do
+ allow(repository.raw_repository).to receive(:branch_names).once.and_return(fake_branch_names)
- context 'when false' do
- let(:branch_name) { 'foobar' }
+ expect(repository.branch_names).to eq(fake_branch_names)
- it 'returns false and caches it' do
- expect(subject).to eq(false)
- # Second call hits the cache
- expect(subject).to eq(false)
- end
+ fresh_repository = repository.dup
+ RequestStore.clear!
+ expect(fresh_repository).to eq(repository)
+
+ expect(fresh_repository.raw_repository).not_to receive(:branch_names)
+ expect(fresh_repository.branch_names).to eq(fake_branch_names)
end
end