summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-10-05 16:41:32 +0200
committerRémy Coutable <remy@rymai.me>2017-04-14 15:20:55 +0200
commit2951a8543ef97ceb1bcaca5f5140d822729c950b (patch)
treeff02540e813cd93e8df8a438c9b22cdacc96982e /spec/services
parentb61199ce0ccdfcd11a338778ce300cd15e5f2a43 (diff)
downloadgitlab-ce-2951a8543ef97ceb1bcaca5f5140d822729c950b.tar.gz
Add user activity service and spec. Also added relevant - NOT offline - migration
It uses a user activity table instead of a column in users. Tested with mySQL and postgreSQL
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/event_create_service_spec.rb13
-rw-r--r--spec/services/users/activity_service_spec.rb26
2 files changed, 39 insertions, 0 deletions
diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb
index f2c2009bcbf..54e5c0b236b 100644
--- a/spec/services/event_create_service_spec.rb
+++ b/spec/services/event_create_service_spec.rb
@@ -129,4 +129,17 @@ 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
new file mode 100644
index 00000000000..68399118579
--- /dev/null
+++ b/spec/services/users/activity_service_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe Users::ActivityService, services: true do
+ let(:user) { create(:user) }
+ subject(:service) { described_class.new(user, 'type') }
+
+ describe '#execute' do
+ context 'when last activity is nil' do
+ it 'sets the last activity timestamp' do
+ service.execute
+
+ expect(user.last_activity_at).not_to be_nil
+ end
+ end
+
+ context 'when activity_at is not nil' do
+ it 'updates the activity multiple times' do
+ activity = create(:user_activity, user: user)
+
+ Timecop.travel(activity.last_activity_at + 1.minute) do
+ expect { service.execute }.to change { user.reload.last_activity_at }
+ end
+ end
+ end
+ end
+end