diff options
author | James Lopez <james@jameslopez.es> | 2016-11-25 17:10:25 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-04-14 15:20:55 +0200 |
commit | 3cb84e06b7a118fb46b4e1e0d4885026c9d4a4d1 (patch) | |
tree | ef622687724fd429f6f7fb02a19a022550bf8608 /spec/services/users | |
parent | 2951a8543ef97ceb1bcaca5f5140d822729c950b (diff) | |
download | gitlab-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/users')
-rw-r--r-- | spec/services/users/activity_service_spec.rb | 34 |
1 files changed, 25 insertions, 9 deletions
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 |