2019-11-08 03:06:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-24 16:17:04 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::IssuablesCountForState do
|
2017-08-24 16:17:04 +00:00
|
|
|
let(:finder) do
|
2020-10-14 18:08:47 +00:00
|
|
|
double(:finder, current_user: nil, params: {}, count_by_state: { opened: 2, closed: 1 })
|
2017-08-24 16:17:04 +00:00
|
|
|
end
|
|
|
|
|
2020-10-14 18:08:47 +00:00
|
|
|
let(:project) { nil }
|
|
|
|
let(:fast_fail) { nil }
|
|
|
|
let(:counter) { described_class.new(finder, project, fast_fail: fast_fail) }
|
2017-08-24 16:17:04 +00:00
|
|
|
|
2020-08-12 03:10:17 +00:00
|
|
|
describe 'project given' do
|
|
|
|
let(:project) { build(:project) }
|
|
|
|
|
|
|
|
it 'provides the project' do
|
|
|
|
expect(counter.project).to eq(project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.declarative_policy_class' do
|
|
|
|
subject { described_class.declarative_policy_class }
|
|
|
|
|
|
|
|
it { is_expected.to eq('IssuablePolicy') }
|
|
|
|
end
|
|
|
|
|
2017-08-24 16:17:04 +00:00
|
|
|
describe '#for_state_or_opened' do
|
|
|
|
it 'returns the number of issuables for the given state' do
|
|
|
|
expect(counter.for_state_or_opened(:closed)).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the number of open issuables when no state is given' do
|
|
|
|
expect(counter.for_state_or_opened).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the number of open issuables when a nil value is given' do
|
|
|
|
expect(counter.for_state_or_opened(nil)).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#[]' do
|
|
|
|
it 'returns the number of issuables for the given state' do
|
|
|
|
expect(counter[:closed]).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'casts valid states from Strings to Symbols' do
|
|
|
|
expect(counter['closed']).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 0 when using an invalid state name as a String' do
|
|
|
|
expect(counter['kittens']).to be_zero
|
|
|
|
end
|
2020-10-14 18:08:47 +00:00
|
|
|
|
|
|
|
context 'fast_fail enabled' do
|
|
|
|
let(:fast_fail) { true }
|
|
|
|
|
|
|
|
it 'returns the expected value' do
|
|
|
|
expect(counter[:closed]).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns -1 when the database times out' do
|
|
|
|
expect(finder).to receive(:count_by_state).and_raise(ActiveRecord::QueryCanceled)
|
|
|
|
|
|
|
|
expect(counter[:closed]).to eq(-1)
|
|
|
|
end
|
|
|
|
end
|
2017-08-24 16:17:04 +00:00
|
|
|
end
|
|
|
|
end
|