summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Drozdov <idrozdov@gitlab.com>2019-08-30 08:56:04 +0300
committerIgor Drozdov <idrozdov@gitlab.com>2019-09-02 16:01:41 +0300
commit626945a63e9cf3e46ced29bb08cbaa3db08f0478 (patch)
tree5a793f5c18273c1103de01500896323a14b013de
parent60fd42172fcf790b3cb612a3403227d4a97035a6 (diff)
downloadgitlab-ce-id-project-for-in-tests.tar.gz
Stub DetectRepositoryLanguagesWorker for all testsid-project-for-in-tests
It performs an expensive operation, but isn't required in most of tests
-rw-r--r--app/models/repository.rb4
-rw-r--r--spec/requests/api/projects_spec.rb2
-rw-r--r--spec/spec_helper.rb6
-rw-r--r--spec/support/helpers/project_forks_helper.rb2
4 files changed, 13 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 7882b2b3036..5cb4b56a114 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -456,6 +456,10 @@ class Repository
def after_import
expire_content_cache
+ # This call is stubbed in tests due to being an expensive operation
+ # It can be reenabled for specific tests via:
+ #
+ # allow(DetectRepositoryLanguagesWorker).to receive(:perform_async).and_call_original
DetectRepositoryLanguagesWorker.perform_async(project.id)
end
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 5465fe0c366..550c7d135a6 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -5,6 +5,8 @@ shared_examples 'languages and percentages JSON response' do
let(:expected_languages) { project.repository.languages.map { |language| language.values_at(:label, :value)}.to_h }
before do
+ allow(DetectRepositoryLanguagesWorker).to receive(:perform_async).and_call_original
+
allow(project.repository).to receive(:languages).and_return(
[{ value: 66.69, label: "Ruby", color: "#701516", highlight: "#701516" },
{ value: 22.98, label: "JavaScript", color: "#f1e05a", highlight: "#f1e05a" },
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index bd504f1553b..6ce76af556f 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -148,6 +148,12 @@ RSpec.configure do |config|
.with(:force_autodevops_on_by_default, anything)
.and_return(false)
+ # Stub this call due to being an expensive operation
+ # It can be reenabled for specific tests via:
+ #
+ # allow(DetectRepositoryLanguagesWorker).to receive(:perform_async).and_call_original
+ allow(DetectRepositoryLanguagesWorker).to receive(:perform_async).and_return(true)
+
Gitlab::ThreadMemoryCache.cache_backend.clear
end
diff --git a/spec/support/helpers/project_forks_helper.rb b/spec/support/helpers/project_forks_helper.rb
index b2d22853e4c..90d0d1845fc 100644
--- a/spec/support/helpers/project_forks_helper.rb
+++ b/spec/support/helpers/project_forks_helper.rb
@@ -45,7 +45,7 @@ module ProjectForksHelper
# not reset the @exists variable of this forked_project.repository
# so we have to explicitly call this method to clear the @exists variable.
# of the instance we're returning here.
- forked_project.repository.after_import
+ forked_project.repository.expire_content_cache
end
forked_project