summaryrefslogtreecommitdiff
path: root/spec/workers
diff options
context:
space:
mode:
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