diff options
author | Sean McGivern <sean@gitlab.com> | 2017-06-29 12:43:56 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-06-30 10:33:46 +0100 |
commit | 0c6cdd07829668e04012219eb21cc60db8c1eabc (patch) | |
tree | 3d6eca853345bd56ba2939b950296a6c2cb68f36 /spec/helpers | |
parent | 8deece32478aaa83354fcfff7b5d6f3250d55844 (diff) | |
download | gitlab-ce-0c6cdd07829668e04012219eb21cc60db8c1eabc.tar.gz |
Make finders responsible for counter cache keys
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/issuables_helper_spec.rb | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index 7dfda388de4..d2e918ef014 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -77,59 +77,57 @@ describe IssuablesHelper do }.with_indifferent_access end - let(:finder) { double(:finder, user_cannot_see_confidential_issues?: true, user_can_see_all_confidential_issues?: false) } + let(:issues_finder) { IssuesFinder.new(nil, params) } + let(:merge_requests_finder) { MergeRequestsFinder.new(nil, params) } before do - allow(helper).to receive(:issues_finder).and_return(finder) - allow(helper).to receive(:merge_requests_finder).and_return(finder) + allow(helper).to receive(:issues_finder).and_return(issues_finder) + allow(helper).to receive(:merge_requests_finder).and_return(merge_requests_finder) end it 'returns the cached value when called for the same issuable type & with the same params' do - expect(helper).to receive(:params).twice.and_return(params) - expect(finder).to receive(:count_by_state).and_return(opened: 42) + expect(issues_finder).to receive(:count_by_state).and_return(opened: 42) expect(helper.issuables_state_counter_text(:issues, :opened)) .to eq('<span>Open</span> <span class="badge">42</span>') - expect(finder).not_to receive(:count_by_state) + expect(issues_finder).not_to receive(:count_by_state) expect(helper.issuables_state_counter_text(:issues, :opened)) .to eq('<span>Open</span> <span class="badge">42</span>') end it 'takes confidential status into account when searching for issues' do - allow(helper).to receive(:params).and_return(params) - expect(finder).to receive(:count_by_state).and_return(opened: 42) + expect(issues_finder).to receive(:count_by_state).and_return(opened: 42) expect(helper.issuables_state_counter_text(:issues, :opened)) .to include('42') - expect(finder).to receive(:user_cannot_see_confidential_issues?).and_return(false) - expect(finder).to receive(:count_by_state).and_return(opened: 40) + expect(issues_finder).to receive(:user_cannot_see_confidential_issues?).twice.and_return(false) + expect(issues_finder).to receive(:count_by_state).and_return(opened: 40) expect(helper.issuables_state_counter_text(:issues, :opened)) .to include('40') - expect(finder).to receive(:user_can_see_all_confidential_issues?).and_return(true) - expect(finder).to receive(:count_by_state).and_return(opened: 45) + expect(issues_finder).to receive(:user_can_see_all_confidential_issues?).and_return(true) + expect(issues_finder).to receive(:count_by_state).and_return(opened: 45) expect(helper.issuables_state_counter_text(:issues, :opened)) .to include('45') end it 'does not take confidential status into account when searching for merge requests' do - allow(helper).to receive(:params).and_return(params) - expect(finder).to receive(:count_by_state).and_return(opened: 42) - expect(finder).not_to receive(:user_cannot_see_confidential_issues?) - expect(finder).not_to receive(:user_can_see_all_confidential_issues?) + expect(merge_requests_finder).to receive(:count_by_state).and_return(opened: 42) + expect(merge_requests_finder).not_to receive(:user_cannot_see_confidential_issues?) + expect(merge_requests_finder).not_to receive(:user_can_see_all_confidential_issues?) expect(helper.issuables_state_counter_text(:merge_requests, :opened)) .to include('42') end it 'does not take some keys into account in the cache key' do - expect(finder).to receive(:count_by_state).and_return(opened: 42) - expect(helper).to receive(:params).and_return({ + expect(issues_finder).to receive(:count_by_state).and_return(opened: 42) + expect(issues_finder).to receive(:params).and_return({ author_id: '11', state: 'foo', sort: 'foo', @@ -140,8 +138,8 @@ describe IssuablesHelper do expect(helper.issuables_state_counter_text(:issues, :opened)) .to eq('<span>Open</span> <span class="badge">42</span>') - expect(finder).not_to receive(:count_by_state) - expect(helper).to receive(:params).and_return({ + expect(issues_finder).not_to receive(:count_by_state) + expect(issues_finder).to receive(:params).and_return({ author_id: '11', state: 'bar', sort: 'bar', @@ -154,14 +152,14 @@ describe IssuablesHelper do end it 'does not take params order into account in the cache key' do - expect(helper).to receive(:params).and_return('author_id' => '11', 'state' => 'opened') - expect(finder).to receive(:count_by_state).and_return(opened: 42) + expect(issues_finder).to receive(:params).and_return('author_id' => '11', 'state' => 'opened') + expect(issues_finder).to receive(:count_by_state).and_return(opened: 42) expect(helper.issuables_state_counter_text(:issues, :opened)) .to eq('<span>Open</span> <span class="badge">42</span>') - expect(helper).to receive(:params).and_return('state' => 'opened', 'author_id' => '11') - expect(finder).not_to receive(:count_by_state) + expect(issues_finder).to receive(:params).and_return('state' => 'opened', 'author_id' => '11') + expect(issues_finder).not_to receive(:count_by_state) expect(helper.issuables_state_counter_text(:issues, :opened)) .to eq('<span>Open</span> <span class="badge">42</span>') |