2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-14 09:55:31 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-08 07:56:54 -05:00
|
|
|
describe Constraints::ProjectUrlConstrainer do
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project) { create(:project) }
|
2016-11-14 09:55:31 -05:00
|
|
|
let!(:namespace) { project.namespace }
|
|
|
|
|
|
|
|
describe '#matches?' do
|
|
|
|
context 'valid request' do
|
2017-02-23 18:55:01 -05:00
|
|
|
let(:request) { build_request(namespace.full_path, project.path) }
|
2016-11-14 09:55:31 -05:00
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid request' do
|
2019-11-08 10:06:21 -05:00
|
|
|
context "non-existing project" do
|
|
|
|
let(:request) { build_request('foo', 'bar') }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
|
|
|
|
context 'existence_check is false' do
|
|
|
|
it { expect(subject.matches?(request, existence_check: false)).to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-14 09:55:31 -05:00
|
|
|
context "project id ending with .git" do
|
2017-02-23 18:55:01 -05:00
|
|
|
let(:request) { build_request(namespace.full_path, project.path + '.git') }
|
2016-11-14 09:55:31 -05:00
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2019-11-08 10:06:21 -05:00
|
|
|
|
|
|
|
context 'when the request matches a redirect route' do
|
|
|
|
let(:old_project_path) { 'old_project_path' }
|
|
|
|
let!(:redirect_route) { project.redirect_routes.create!(path: "#{namespace.full_path}/#{old_project_path}") }
|
|
|
|
|
|
|
|
context 'and is a GET request' do
|
|
|
|
let(:request) { build_request(namespace.full_path, old_project_path) }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2019-11-08 10:06:21 -05:00
|
|
|
it { expect(subject.matches?(request)).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and is NOT a GET request' do
|
|
|
|
let(:request) { build_request(namespace.full_path, old_project_path, 'POST') }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2019-11-08 10:06:21 -05:00
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2016-11-14 09:55:31 -05:00
|
|
|
end
|
|
|
|
|
2019-11-08 10:06:21 -05:00
|
|
|
def build_request(namespace, project, method = 'GET')
|
|
|
|
double(:request,
|
|
|
|
'get?': (method == 'GET'),
|
|
|
|
params: { namespace_id: namespace, id: project })
|
2016-11-14 09:55:31 -05:00
|
|
|
end
|
|
|
|
end
|