2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2017-12-08 12:42:43 -05:00
|
|
|
|
|
|
|
describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
describe '.fetch_message' do
|
2017-12-08 12:42:43 -05:00
|
|
|
context 'with a redirect message queue' do
|
2018-01-22 13:10:56 -05:00
|
|
|
it 'returns the redirect message' do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_moved = described_class.new(project, user, 'http', 'foo/bar')
|
|
|
|
project_moved.add_message
|
2017-12-08 12:42:43 -05:00
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(described_class.fetch_message(user.id, project.id)).to eq(project_moved.message)
|
2017-12-08 12:42:43 -05:00
|
|
|
end
|
|
|
|
|
2018-01-22 13:10:56 -05:00
|
|
|
it 'deletes the redirect message from redis' do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_moved = described_class.new(project, user, 'http', 'foo/bar')
|
|
|
|
project_moved.add_message
|
2017-12-08 12:42:43 -05:00
|
|
|
|
|
|
|
expect(Gitlab::Redis::SharedState.with { |redis| redis.get("redirect_namespace:#{user.id}:#{project.id}") }).not_to be_nil
|
2018-01-26 09:28:08 -05:00
|
|
|
described_class.fetch_message(user.id, project.id)
|
2017-12-08 12:42:43 -05:00
|
|
|
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
|
2018-01-22 13:10:56 -05:00
|
|
|
it 'returns nil' do
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(described_class.fetch_message(1, 2)).to be_nil
|
2017-12-08 12:42:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
describe '#add_message' do
|
2018-01-22 13:10:56 -05:00
|
|
|
it 'queues a redirect message' do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_moved = described_class.new(project, user, 'http', 'foo/bar')
|
|
|
|
expect(project_moved.add_message).to eq("OK")
|
2017-12-08 12:42:43 -05:00
|
|
|
end
|
2017-12-24 12:35:30 -05:00
|
|
|
|
2018-01-22 13:10:56 -05:00
|
|
|
it 'handles anonymous clones' do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_moved = described_class.new(project, nil, 'http', 'foo/bar')
|
2017-12-24 12:35:30 -05:00
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(project_moved.add_message).to eq(nil)
|
2017-12-24 12:35:30 -05:00
|
|
|
end
|
2017-12-08 12:42:43 -05:00
|
|
|
end
|
|
|
|
|
2018-01-26 09:28:08 -05:00
|
|
|
describe '#message' do
|
2018-03-05 07:02:36 -05:00
|
|
|
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}'.
|
2017-12-08 12:42:43 -05:00
|
|
|
|
2018-03-05 07:02:36 -05:00
|
|
|
Please update your Git remote:
|
2017-12-08 12:42:43 -05:00
|
|
|
|
2018-03-05 07:02:36 -05:00
|
|
|
git remote set-url origin #{project.http_url_to_repo}
|
|
|
|
MSG
|
2017-12-08 12:42:43 -05:00
|
|
|
|
2018-03-05 07:02:36 -05:00
|
|
|
expect(project_moved.message).to eq(message)
|
2017-12-08 12:42:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|