debian-mirror-gitlab/spec/services/users/activity_service_spec.rb

74 lines
2 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Users::ActivityService do
2018-11-18 11:00:15 +05:30
include ExclusiveLeaseHelpers
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
let(:user) { create(:user, last_activity_on: last_activity_on) }
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
subject { described_class.new(user, 'type') }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
describe '#execute', :clean_gitlab_redis_shared_state do
2017-08-17 22:00:37 +05:30
context 'when last activity is nil' do
2018-11-18 11:00:15 +05:30
let(:last_activity_on) { nil }
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
it 'updates last_activity_on for the user' do
expect { subject.execute }
.to change(user, :last_activity_on).from(last_activity_on).to(Date.today)
2017-08-17 22:00:37 +05:30
end
2018-11-18 11:00:15 +05:30
end
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
context 'when last activity is in the past' do
let(:last_activity_on) { Date.today - 1.week }
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
it 'updates last_activity_on for the user' do
expect { subject.execute }
.to change(user, :last_activity_on)
.from(last_activity_on)
.to(Date.today)
2017-08-17 22:00:37 +05:30
end
2018-11-18 11:00:15 +05:30
end
context 'when a bad object is passed' do
let(:fake_object) { double(username: 'hello') }
it 'does not record activity' do
service = described_class.new(fake_object, 'pull')
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
expect(service).not_to receive(:record_activity)
service.execute
2017-08-17 22:00:37 +05:30
end
2018-11-18 11:00:15 +05:30
end
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
context 'when last activity is today' do
let(:last_activity_on) { Date.today }
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
it 'does not update last_activity_on' do
expect { subject.execute }.not_to change(user, :last_activity_on)
2017-08-17 22:00:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
context 'when in GitLab read-only instance' do
2018-11-18 11:00:15 +05:30
let(:last_activity_on) { nil }
2018-03-17 18:26:18 +05:30
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
2018-11-18 11:00:15 +05:30
it 'does not update last_activity_on' do
expect { subject.execute }.not_to change(user, :last_activity_on)
2018-03-17 18:26:18 +05:30
end
end
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
context 'when a lease could not be obtained' do
let(:last_activity_on) { nil }
it 'does not update last_activity_on' do
stub_exclusive_lease_taken("acitvity_service:#{user.id}", timeout: 1.minute.to_i)
expect { subject.execute }.not_to change(user, :last_activity_on)
end
end
2017-08-17 22:00:37 +05:30
end
end