summaryrefslogtreecommitdiff
path: root/spec/models
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/models
parent6867eff1f997a881cd3ea64109f7ba2d4b42fde4 (diff)
downloadgitlab-ce-060c842402c00f830a810702600cbe39dfa6cf62.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/users_statistics_spec.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/models/users_statistics_spec.rb b/spec/models/users_statistics_spec.rb
new file mode 100644
index 00000000000..fc23bed711f
--- /dev/null
+++ b/spec/models/users_statistics_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe UsersStatistics do
+ describe '.create_current_stats!' do
+ before do
+ create_list(:user_highest_role, 4)
+ create_list(:user_highest_role, 2, :guest)
+ create_list(:user_highest_role, 3, :reporter)
+ create_list(:user_highest_role, 4, :developer)
+ create_list(:user_highest_role, 3, :maintainer)
+ create_list(:user_highest_role, 2, :owner)
+ create_list(:user, 2, :bot)
+ create_list(:user, 1, :blocked)
+
+ allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false)
+ end
+
+ context 'when successful' do
+ it 'creates an entry with the current statistics values' do
+ expect(described_class.create_current_stats!).to have_attributes(
+ without_groups_and_projects: 4,
+ with_highest_role_guest: 2,
+ with_highest_role_reporter: 3,
+ with_highest_role_developer: 4,
+ with_highest_role_maintainer: 3,
+ with_highest_role_owner: 2,
+ bots: 2,
+ blocked: 1
+ )
+ end
+ end
+
+ context 'when unsuccessful' do
+ it 'raises an ActiveRecord::RecordInvalid exception' do
+ allow(UsersStatistics).to receive(:create!).and_raise(ActiveRecord::RecordInvalid)
+
+ expect { described_class.create_current_stats! }.to raise_error(ActiveRecord::RecordInvalid)
+ end
+ end
+ end
+end