2016-11-14 14:55:31 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe ProjectUrlConstrainer do
|
2017-08-02 19:55:11 +00:00
|
|
|
let!(:project) { create(:project) }
|
2016-11-14 14:55:31 +00:00
|
|
|
let!(:namespace) { project.namespace }
|
|
|
|
|
|
|
|
describe '#matches?' do
|
|
|
|
context 'valid request' do
|
2017-02-23 23:55:01 +00:00
|
|
|
let(:request) { build_request(namespace.full_path, project.path) }
|
2016-11-14 14:55:31 +00: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 23:55:01 +00:00
|
|
|
let(:request) { build_request(namespace.full_path, project.path + '.git') }
|
2016-11-14 14:55:31 +00:00
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2017-05-01 20:46:30 +00: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 14:55:31 +00:00
|
|
|
end
|
|
|
|
|
2017-05-01 20:46:30 +00:00
|
|
|
def build_request(namespace, project, method = 'GET')
|
|
|
|
double(:request,
|
|
|
|
'get?': (method == 'GET'),
|
|
|
|
params: { namespace_id: namespace, id: project })
|
2016-11-14 14:55:31 +00:00
|
|
|
end
|
|
|
|
end
|