File: user_activity_shared_examples.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (75 lines) | stat: -rw-r--r-- 1,924 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true

RSpec.shared_examples 'updating of user activity' do |paths_to_visit|
  let(:user) { create(:user, last_activity_on: nil) }

  before do
    group = create(:group, name: 'group')
    project = create(:project, :public, namespace: group, path: 'project')

    create(:issue, project: project, iid: 10)
    create(:merge_request, source_project: project, iid: 15)

    project.add_maintainer(user)
  end

  context 'without an authenticated user' do
    it 'does not set the last activity cookie' do
      get "/group/project"

      expect(response.cookies['user_last_activity_on']).to be_nil
    end
  end

  context 'with an authenticated user' do
    before do
      login_as(user)
    end

    context 'with a POST request' do
      it 'does not set the last activity cookie' do
        post "/group/project/archive"

        expect(response.cookies['user_last_activity_on']).to be_nil
      end
    end

    paths_to_visit.each do |path|
      context "on GET to #{path}" do
        it 'updates the last activity date' do
          expect(Users::ActivityService).to receive(:new).and_call_original

          get path

          expect(user.last_activity_on).to eq(Date.today)
        end

        context 'when last_activity_on is nil' do
          before do
            user.update_attribute(:last_activity_on, nil)
          end

          it 'updates the last activity date' do
            expect(user.last_activity_on).to be_nil

            get path

            expect(user.last_activity_on).to eq(Date.today)
          end
        end

        context 'when last_activity_on is stale' do
          before do
            user.update_attribute(:last_activity_on, 2.days.ago.to_date)
          end

          it 'updates the last activity date' do
            get path

            expect(user.last_activity_on).to eq(Date.today)
          end
        end
      end
    end
  end
end