2016-11-14 09:55:31 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe 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
|
|
|
|
context "non-existing project" do
|
|
|
|
let(:request) { build_request('foo', 'bar') }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2017-05-01 16:46:30 -04: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) }
|
|
|
|
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') }
|
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2016-11-14 09:55:31 -05:00
|
|
|
end
|
|
|
|
|
2017-05-01 16:46:30 -04: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
|