summaryrefslogtreecommitdiff
path: root/spec/workers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-08 00:09:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-08 00:09:30 +0000
commit060c842402c00f830a810702600cbe39dfa6cf62 (patch)
tree743bd65ac0c1d4d6518ae8cdd4af5718ec7fb890 /spec/workers
parent6867eff1f997a881cd3ea64109f7ba2d4b42fde4 (diff)
downloadgitlab-ce-060c842402c00f830a810702600cbe39dfa6cf62.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/users/create_statistics_worker_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/workers/users/create_statistics_worker_spec.rb b/spec/workers/users/create_statistics_worker_spec.rb
new file mode 100644
index 00000000000..3b2b72a832d
--- /dev/null
+++ b/spec/workers/users/create_statistics_worker_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Users::CreateStatisticsWorker do
+ describe '#perform' do
+ subject { described_class.new.perform }
+
+ before do
+ allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false)
+ end
+
+ context 'when successful' do
+ it 'create an users statistics entry' do
+ expect { subject }.to change { UsersStatistics.count }.from(0).to(1)
+ end
+ end
+
+ context 'when unsuccessful' do
+ it 'logs an error' do
+ users_statistics = build(:users_statistics)
+ users_statistics.errors.add(:base, 'This is an error')
+ exception = ActiveRecord::RecordInvalid.new(users_statistics)
+
+ allow(UsersStatistics).to receive(:create_current_stats!).and_raise(exception)
+
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(exception).and_call_original
+
+ subject
+ end
+ end
+ end
+end