From 595631d26fbde49a5644108d75b38da0a53f925a Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 21 Nov 2017 16:11:21 +0100 Subject: refactor tests --- spec/models/repository_spec.rb | 39 ++++++++++++++++----------------------- 1 file 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 -- cgit v1.2.1