debian-mirror-gitlab/spec/lib/gitlab/issuables_count_for_state_spec.rb
2020-10-24 23:57:45 +05:30

55 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::IssuablesCountForState do
let(:finder) do
double(:finder, count_by_state: { opened: 2, closed: 1 })
end
let(:counter) { described_class.new(finder) }
describe 'project given' do
let(:project) { build(:project) }
let(:counter) { described_class.new(finder, 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
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
end
end