Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 15:09:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 15:09:01 +0300
commit2c2dd5e36c4ed5f09f488be288882d98f9124d12 (patch)
treead4c478bb1c588387a881b26a7db7c3237b9d4f3 /spec/workers
parent2ff184ad761fbfbe25a3d827c8f704349963a8d2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/concerns/cronjob_queue_spec.rb8
-rw-r--r--spec/workers/concerns/worker_context_spec.rb34
2 files changed, 42 insertions, 0 deletions
diff --git a/spec/workers/concerns/cronjob_queue_spec.rb b/spec/workers/concerns/cronjob_queue_spec.rb
index cf4d47b7500..21483d0e4e3 100644
--- a/spec/workers/concerns/cronjob_queue_spec.rb
+++ b/spec/workers/concerns/cronjob_queue_spec.rb
@@ -21,4 +21,12 @@ describe CronjobQueue do
it 'disables retrying of failed jobs' do
expect(worker.sidekiq_options['retry']).to eq(false)
end
+
+ it 'automatically clears project, user and namespace from the context', :aggregate_failues do
+ worker_context = worker.get_worker_context.to_lazy_hash.transform_values(&:call)
+
+ expect(worker_context[:user]).to be_nil
+ expect(worker_context[:root_namespace]).to be_nil
+ expect(worker_context[:project]).to be_nil
+ end
end
diff --git a/spec/workers/concerns/worker_context_spec.rb b/spec/workers/concerns/worker_context_spec.rb
new file mode 100644
index 00000000000..a7d0ba2b8bd
--- /dev/null
+++ b/spec/workers/concerns/worker_context_spec.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe WorkerContext do
+ let(:worker) do
+ Class.new do
+ include WorkerContext
+ end
+ end
+
+ describe '.worker_context' do
+ it 'allows modifying the context for the entire worker' do
+ worker.worker_context(user: build_stubbed(:user))
+
+ expect(worker.get_worker_context).to be_a(Gitlab::ApplicationContext)
+ end
+
+ it 'allows fetches the context from a superclass if none was defined' do
+ worker.worker_context(user: build_stubbed(:user))
+ subclass = Class.new(worker)
+
+ expect(subclass.get_worker_context).to eq(worker.get_worker_context)
+ end
+ end
+
+ describe '#with_context' do
+ it 'allows modifying context when the job is running' do
+ worker.new.with_context(user: build_stubbed(:user, username: 'jane-doe')) do
+ expect(Labkit::Context.current.to_h).to include('meta.user' => 'jane-doe')
+ end
+ end
+ end
+end