summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-11-25 17:10:25 +0100
committerRémy Coutable <remy@rymai.me>2017-04-14 15:20:55 +0200
commit3cb84e06b7a118fb46b4e1e0d4885026c9d4a4d1 (patch)
treeef622687724fd429f6f7fb02a19a022550bf8608 /spec/services
parent2951a8543ef97ceb1bcaca5f5140d822729c950b (diff)
downloadgitlab-ce-3cb84e06b7a118fb46b4e1e0d4885026c9d4a4d1.tar.gz
Remove user activities table and use redis instead of PG for recording activities
Refactored specs and added a post deployment migration to remove the activity users table.
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/event_create_service_spec.rb28
-rw-r--r--spec/services/users/activity_service_spec.rb34
2 files changed, 40 insertions, 22 deletions
diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb
index 54e5c0b236b..13c0aac2363 100644
--- a/spec/services/event_create_service_spec.rb
+++ b/spec/services/event_create_service_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe EventCreateService, services: true do
+ include UserActivitiesHelpers
+
let(:service) { EventCreateService.new }
describe 'Issues' do
@@ -111,6 +113,19 @@ describe EventCreateService, services: true do
end
end
+ describe '#push', :redis do
+ let(:project) { create(:empty_project) }
+ let(:user) { create(:user) }
+
+ it 'creates a new event' do
+ expect { service.push(project, user, {}) }.to change { Event.count }
+ end
+
+ it 'updates user last activity' do
+ expect { service.push(project, user, {}) }.to change { user_score }
+ end
+ end
+
describe 'Project' do
let(:user) { create :user }
let(:project) { create(:empty_project) }
@@ -129,17 +144,4 @@ describe EventCreateService, services: true do
it { expect { subject }.to change { Event.count }.from(0).to(1) }
end
end
-
- describe '#push' do
- let(:project) { create(:empty_project) }
- let(:user) { create(:user) }
-
- it 'creates a new event' do
- expect { service.push(project, user, {}) }.to change { Event.count }
- end
-
- it 'updates user last activity' do
- expect { service.push(project, user, {}) }.to change { user.last_activity_at }
- end
- end
end
diff --git a/spec/services/users/activity_service_spec.rb b/spec/services/users/activity_service_spec.rb
index 68399118579..07715ad4ca0 100644
--- a/spec/services/users/activity_service_spec.rb
+++ b/spec/services/users/activity_service_spec.rb
@@ -1,24 +1,40 @@
require 'spec_helper'
describe Users::ActivityService, services: true do
+ include UserActivitiesHelpers
+
let(:user) { create(:user) }
+
subject(:service) { described_class.new(user, 'type') }
- describe '#execute' do
+ describe '#execute', :redis do
context 'when last activity is nil' do
- it 'sets the last activity timestamp' do
+ before do
service.execute
+ end
- expect(user.last_activity_at).not_to be_nil
+ it 'sets the last activity timestamp for the user' do
+ expect(last_hour_members).to eq([user.username])
+ end
+
+ it 'updates the same user' do
+ service.execute
+
+ expect(last_hour_members).to eq([user.username])
+ end
+
+ it 'updates the timestamp of an existing user' do
+ Timecop.freeze(Date.tomorrow) do
+ expect { service.execute }.to change { user_score }.to(Time.now.to_i)
+ end
end
- end
- context 'when activity_at is not nil' do
- it 'updates the activity multiple times' do
- activity = create(:user_activity, user: user)
+ describe 'other user' do
+ it 'updates other user' do
+ other_user = create(:user)
+ described_class.new(other_user, 'type').execute
- Timecop.travel(activity.last_activity_at + 1.minute) do
- expect { service.execute }.to change { user.reload.last_activity_at }
+ expect(last_hour_members).to match_array([user.username, other_user.username])
end
end
end