summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-08-09 23:49:12 +0000
committerRobert Speicher <robert@gitlab.com>2016-08-09 23:49:12 +0000
commit480535a16784b404b9c16773805b25cfbe5a7afa (patch)
tree2a9f3216a994ea5ef9ac5de73271b824dcd148f8 /spec
parent3f0737384251501a95bdb601e90592cfd08bc0bc (diff)
parent1e6316172b913b622379675d3d48e6837dfc1843 (diff)
downloadgitlab-ce-480535a16784b404b9c16773805b25cfbe5a7afa.tar.gz
Merge branch 'add-caching-for-project-count' into 'master'
Add a method in Project to return a cached value of total count of projects This is in preparation to address the DB load caused by the counting in gitlab-com/infrastructure#303. See merge request !5746
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_spec.rb14
-rw-r--r--spec/spec_helper.rb7
2 files changed, 21 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 1c3d694075a..9c3b4712cab 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -714,6 +714,20 @@ describe Project, models: true do
it { expect(project.builds_enabled?).to be_truthy }
end
+ describe '.cached_count', caching: true do
+ let(:group) { create(:group, :public) }
+ let!(:project1) { create(:empty_project, :public, group: group) }
+ let!(:project2) { create(:empty_project, :public, group: group) }
+
+ it 'returns total project count' do
+ expect(Project).to receive(:count).once.and_call_original
+
+ 3.times do
+ expect(Project.cached_count).to eq(2)
+ end
+ end
+ end
+
describe '.trending' do
let(:group) { create(:group, :public) }
let(:project1) { create(:empty_project, :public, group: group) }
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 4f3aacf55be..2e2aa7c4fc0 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -42,6 +42,13 @@ RSpec.configure do |config|
config.before(:suite) do
TestEnv.init
end
+
+ config.around(:each, :caching) do |example|
+ caching_store = Rails.cache
+ Rails.cache = ActiveSupport::Cache::MemoryStore.new if example.metadata[:caching]
+ example.run
+ Rails.cache = caching_store
+ end
end
FactoryGirl::SyntaxRunner.class_eval do