summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-10-28 18:29:52 +0100
committerAndreas Brandl <abrandl@gitlab.com>2018-11-27 16:46:55 +0100
commitc60e9837b908771dbc2e382deea9a7e308a7406e (patch)
treec056da620df7bc3778bad0b7b3537745914a69b1
parentb8891ab7b38525dbe385d87feb6654594474bfb9 (diff)
downloadgitlab-ce-c60e9837b908771dbc2e382deea9a7e308a7406e.tar.gz
Finish refactoring specs.
The goal is to reflect separation of concern also in specs.
-rw-r--r--spec/lib/gitlab/database/count_spec.rb71
1 files changed, 15 insertions, 56 deletions
diff --git a/spec/lib/gitlab/database/count_spec.rb b/spec/lib/gitlab/database/count_spec.rb
index 881906b7991..699422abb6b 100644
--- a/spec/lib/gitlab/database/count_spec.rb
+++ b/spec/lib/gitlab/database/count_spec.rb
@@ -55,60 +55,6 @@ describe Gitlab::Database::Count do
subject
end
end
-
- 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
- it 'counts all models the normal way' do
- expect(Project).to receive(:count).and_call_original
- expect(Identity).to receive(:count).and_call_original
- expect(described_class.approximate_counts(models)).to eq({ Project => 3, Identity => 1 })
- end
- end
-
- describe 'no permission' do
- it 'falls back to standard query' do
- allow(ActiveRecord::Base).to receive(:transaction).and_raise(PG::InsufficientPrivilege)
-
- expect(Project).to receive(:count).and_call_original
- expect(Identity).to receive(:count).and_call_original
- expect(described_class.approximate_counts(models)).to eq({ Project => 3, Identity => 1 })
- end
- end
-
- describe 'when some reltuples have been updated' do
- it 'counts projects in the fast way' do
- expect(reltuples_strategy).to receive(:count).and_return({ Project => 3 })
-
- expect(Project).not_to receive(:count).and_call_original
- expect(Identity).to receive(:count).and_call_original
- expect(described_class.approximate_counts(models)).to eq({ Project => 3, Identity => 1 })
- end
- end
-
- # TODO: This covers two parts: reltuple strategy itself and the fallback
- # TODO: Add spec that covers strategy details for reltuple strategy
- describe 'when all reltuples have been updated' do
- #before do
- #ActiveRecord::Base.connection.execute('ANALYZE projects')
- #ActiveRecord::Base.connection.execute('ANALYZE identities')
- #end
-
- it 'counts models with the standard way' do
- allow(reltuples_strategy).to receive(:count).and_return({ Project => 3, Identity => 1 })
- expect(Project).not_to receive(:count)
- expect(Identity).not_to receive(:count)
-
- expect(described_class.approximate_counts(models)).to eq({ Project => 3, Identity => 1 })
- end
- end
- end
end
describe Gitlab::Database::Count::ExactCountStrategy do
@@ -141,10 +87,23 @@ describe Gitlab::Database::Count do
subject { described_class.new(models).count }
describe '#count' do
- context 'when reltuples is not up to date' do
- it 'returns an empty hash' do
+ context 'when reltuples is up to date' do
+ before do
+ ActiveRecord::Base.connection.execute('ANALYZE projects')
+ ActiveRecord::Base.connection.execute('ANALYZE identities')
+ end
+
+ it 'uses statistics to do the count' do
models.each { |model| expect(model).not_to receive(:count) }
+ expect(subject).to eq({ Project => 3, Identity => 1 })
+ end
+ end
+
+ context 'insufficient permissions' do
+ it 'returns an empty hash' do
+ allow(ActiveRecord::Base).to receive(:transaction).and_raise(PG::InsufficientPrivilege)
+
expect(subject).to eq({})
end
end