project_moved_spec.rb 1.95 KB
Newer Older
1 2 3 4 5 6
require 'rails_helper'

describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do
  let(:user) { create(:user) }
  let(:project) { create(:project) }

7
  describe '.fetch_message' do
8
    context 'with a redirect message queue' do
Tiago Botelho's avatar
Tiago Botelho committed
9
      it 'returns the redirect message' do
10 11
        project_moved = described_class.new(project, user, 'http', 'foo/bar')
        project_moved.add_message
12

13
        expect(described_class.fetch_message(user.id, project.id)).to eq(project_moved.message)
14 15
      end

Tiago Botelho's avatar
Tiago Botelho committed
16
      it 'deletes the redirect message from redis' do
17 18
        project_moved = described_class.new(project, user, 'http', 'foo/bar')
        project_moved.add_message
19 20

        expect(Gitlab::Redis::SharedState.with { |redis| redis.get("redirect_namespace:#{user.id}:#{project.id}") }).not_to be_nil
21
        described_class.fetch_message(user.id, project.id)
22 23 24 25 26
        expect(Gitlab::Redis::SharedState.with { |redis| redis.get("redirect_namespace:#{user.id}:#{project.id}") }).to be_nil
      end
    end

    context 'with no redirect message queue' do
Tiago Botelho's avatar
Tiago Botelho committed
27
      it 'returns nil' do
28
        expect(described_class.fetch_message(1, 2)).to be_nil
29 30 31 32
      end
    end
  end

33
  describe '#add_message' do
Tiago Botelho's avatar
Tiago Botelho committed
34
    it 'queues a redirect message' do
35 36
      project_moved = described_class.new(project, user, 'http', 'foo/bar')
      expect(project_moved.add_message).to eq("OK")
37
    end
38

Tiago Botelho's avatar
Tiago Botelho committed
39
    it 'handles anonymous clones' do
40
      project_moved = described_class.new(project, nil, 'http', 'foo/bar')
41

42
      expect(project_moved.add_message).to eq(nil)
43
    end
44 45
  end

46
  describe '#message' do
47 48 49 50
    it 'returns a redirect message' do
      project_moved = described_class.new(project, user, 'http', 'foo/bar')
      message = <<~MSG
                Project 'foo/bar' was moved to '#{project.full_path}'.
51

52
                Please update your Git remote:
53

54 55
                  git remote set-url origin #{project.http_url_to_repo}
                MSG
56

57
      expect(project_moved.message).to eq(message)
58 59 60
    end
  end
end