Commit e5e4c6b7 authored by Andreas Brandl's avatar Andreas Brandl

Move things to their right scope in specs.

parent 72347448
...@@ -7,12 +7,6 @@ describe Gitlab::Database::Count do ...@@ -7,12 +7,6 @@ describe Gitlab::Database::Count do
end end
let(:models) { [Project, Identity] } let(:models) { [Project, Identity] }
let(:reltuples_strategy) { double('reltuples_strategy', count: {}) }
let(:exact_strategy) { double('exact_strategy', count: {}) }
before do
allow(Gitlab::Database::Count::ReltuplesCountStrategy).to receive(:new).with(models).and_return(reltuples_strategy)
end
context '.approximate_counts' do context '.approximate_counts' do
context 'selecting strategies' do context 'selecting strategies' do
...@@ -62,7 +56,14 @@ describe Gitlab::Database::Count do ...@@ -62,7 +56,14 @@ describe Gitlab::Database::Count do
end end
end end
context 'with PostgreSQL', :postgresql do xcontext 'with PostgreSQL', :postgresql do
let(:reltuples_strategy) { double('reltuples_strategy', count: {}) }
let(:exact_strategy) { double('exact_strategy', count: {}) }
before do
allow(Gitlab::Database::Count::ReltuplesCountStrategy).to receive(:new).with(models).and_return(reltuples_strategy)
end
describe 'when reltuples have not been updated' do describe 'when reltuples have not been updated' do
it 'counts all models the normal way' do it 'counts all models the normal way' do
expect(Project).to receive(:count).and_call_original expect(Project).to receive(:count).and_call_original
...@@ -107,59 +108,59 @@ describe Gitlab::Database::Count do ...@@ -107,59 +108,59 @@ describe Gitlab::Database::Count do
expect(described_class.approximate_counts(models)).to eq({ Project => 3, Identity => 1 }) expect(described_class.approximate_counts(models)).to eq({ Project => 3, Identity => 1 })
end end
end end
end
end
describe Gitlab::Database::Count::ExactCountStrategy do describe Gitlab::Database::Count::ExactCountStrategy do
subject { described_class.new(models).count } subject { described_class.new(models).count }
describe '#count' do describe '#count' do
it 'counts all models' do it 'counts all models' do
models.each { |model| expect(model).to receive(:count).and_call_original } models.each { |model| expect(model).to receive(:count).and_call_original }
expect(subject).to eq({ Project => 3, Identity => 1 }) expect(subject).to eq({ Project => 3, Identity => 1 })
end end
end end
describe '.enabled?' do describe '.enabled?' do
it 'is enabled for PostgreSQL' do it 'is enabled for PostgreSQL' do
allow(Gitlab::Database).to receive(:postgresql?).and_return(true) allow(Gitlab::Database).to receive(:postgresql?).and_return(true)
expect(described_class.enabled?).to be_truthy expect(described_class.enabled?).to be_truthy
end end
it 'is enabled for MySQL' do it 'is enabled for MySQL' do
allow(Gitlab::Database).to receive(:postgresql?).and_return(false) allow(Gitlab::Database).to receive(:postgresql?).and_return(false)
expect(described_class.enabled?).to be_truthy expect(described_class.enabled?).to be_truthy
end
end
end end
end
end
describe Gitlab::Database::Count::ReltuplesCountStrategy do describe Gitlab::Database::Count::ReltuplesCountStrategy do
subject { described_class.new(models).count } subject { described_class.new(models).count }
describe '#count' do describe '#count' do
context 'when reltuples is not up to date' do context 'when reltuples is not up to date' do
it 'returns an empty hash' do it 'returns an empty hash' do
models.each { |model| expect(model).not_to receive(:count) } models.each { |model| expect(model).not_to receive(:count) }
expect(subject).to eq({}) expect(subject).to eq({})
end
end
end end
end
end
describe '.enabled?' do describe '.enabled?' do
it 'is enabled for PostgreSQL' do it 'is enabled for PostgreSQL' do
allow(Gitlab::Database).to receive(:postgresql?).and_return(true) allow(Gitlab::Database).to receive(:postgresql?).and_return(true)
expect(described_class.enabled?).to be_truthy expect(described_class.enabled?).to be_truthy
end end
it 'is disabled for MySQL' do it 'is disabled for MySQL' do
allow(Gitlab::Database).to receive(:postgresql?).and_return(false) allow(Gitlab::Database).to receive(:postgresql?).and_return(false)
expect(described_class.enabled?).to be_falsey expect(described_class.enabled?).to be_falsey
end
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment