debian-mirror-gitlab/spec/workers/users/create_statistics_worker_spec.rb

34 lines
943 B
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Users::CreateStatisticsWorker do
2020-04-22 19:07:51 +05:30
describe '#perform' do
subject { described_class.new.perform }
before do
2021-10-27 15:23:28 +05:30
allow(UsersStatistics.connection).to receive(:transaction_open?).and_return(false)
2020-04-22 19:07:51 +05:30
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