diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-19 17:48:31 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-19 17:48:31 +0300 |
commit | 40a972057da58dd5c15cf0f0b2952f264dba0076 (patch) | |
tree | c454dd64d0e8af557ad9bf71337ad5c4014efbef /spec/services/users | |
parent | a9da37434af6d44c5f851affd4bd69b370760e8e (diff) | |
parent | 5f570690d4cf5635eb41ec43f21bdf21f79c5dda (diff) |
Merge branch 'usage-ping-port' into 'master'
Usage ping port
Closes #27750
See merge request !10481
Diffstat (limited to 'spec/services/users')
-rw-r--r-- | spec/services/users/activity_service_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/services/users/activity_service_spec.rb b/spec/services/users/activity_service_spec.rb new file mode 100644 index 00000000000..8d67ebe3231 --- /dev/null +++ b/spec/services/users/activity_service_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Users::ActivityService, services: true do + include UserActivitiesHelpers + + let(:user) { create(:user) } + + subject(:service) { described_class.new(user, 'type') } + + describe '#execute', :redis do + context 'when last activity is nil' do + before do + service.execute + end + + it 'sets the last activity timestamp for the user' do + expect(last_hour_user_ids).to eq([user.id]) + end + + it 'updates the same user' do + service.execute + + expect(last_hour_user_ids).to eq([user.id]) + end + + it 'updates the timestamp of an existing user' do + Timecop.freeze(Date.tomorrow) do + expect { service.execute }.to change { user_activity(user) }.to(Time.now.to_i.to_s) + end + end + + describe 'other user' do + it 'updates other user' do + other_user = create(:user) + described_class.new(other_user, 'type').execute + + expect(last_hour_user_ids).to match_array([user.id, other_user.id]) + end + end + end + end + + def last_hour_user_ids + Gitlab::UserActivities.new. + select { |k, v| v >= 1.hour.ago.to_i.to_s }. + map { |k, _| k.to_i } + end +end |