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:
authorSean McGivern <sean@gitlab.com>2017-04-05 13:24:15 +0300
committerRémy Coutable <remy@rymai.me>2017-04-14 16:20:55 +0300
commit5b698082323e019e47b5c739cdec0300b521340b (patch)
tree49e53d856dc00849b9757993cd83128d0ec1e642 /spec/services/cohorts_service_spec.rb
parent0d7645e1b0312ea0a78401a835785422cc01660d (diff)
Rename user cohorts -> cohorts
Diffstat (limited to 'spec/services/cohorts_service_spec.rb')
-rw-r--r--spec/services/cohorts_service_spec.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/services/cohorts_service_spec.rb b/spec/services/cohorts_service_spec.rb
new file mode 100644
index 00000000000..878e9fcea05
--- /dev/null
+++ b/spec/services/cohorts_service_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe CohortsService do
+ describe '#execute' do
+ def month_start(months_ago)
+ months_ago.months.ago.beginning_of_month.to_date
+ end
+
+ # In the interests of speed and clarity, this example has minimal data.
+ it 'returns a list of user cohorts' do
+ 6.times do |months_ago|
+ months_ago_time = (months_ago * 2).months.ago
+
+ create(:user, created_at: months_ago_time, current_sign_in_at: Time.now)
+ create(:user, created_at: months_ago_time, current_sign_in_at: months_ago_time)
+ end
+
+ create(:user) # this user is inactive and belongs to the current month
+
+ expected = {
+ month_start(11) => { months: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], total: 0, inactive: 0 },
+ month_start(10) => { months: [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], total: 2, inactive: 0 },
+ month_start(9) => { months: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], total: 0, inactive: 0 },
+ month_start(8) => { months: [2, 1, 1, 1, 1, 1, 1, 1, 1], total: 2, inactive: 0 },
+ month_start(7) => { months: [0, 0, 0, 0, 0, 0, 0, 0], total: 0, inactive: 0 },
+ month_start(6) => { months: [2, 1, 1, 1, 1, 1, 1], total: 2, inactive: 0 },
+ month_start(5) => { months: [0, 0, 0, 0, 0, 0], total: 0, inactive: 0 },
+ month_start(4) => { months: [2, 1, 1, 1, 1], total: 2, inactive: 0 },
+ month_start(3) => { months: [0, 0, 0, 0], total: 0, inactive: 0 },
+ month_start(2) => { months: [2, 1, 1], total: 2, inactive: 0 },
+ month_start(1) => { months: [0, 0], total: 0, inactive: 0 },
+ month_start(0) => { months: [2], total: 2, inactive: 1 }
+ }
+
+ expect(described_class.new.execute).to eq(expected)
+ end
+ end
+end