2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-06 09:59:22 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Constraints::GroupUrlConstrainer do
|
2016-11-07 08:16:04 -05:00
|
|
|
let!(:group) { create(:group, path: 'gitlab') }
|
2016-10-06 09:59:22 -04:00
|
|
|
|
2016-11-07 08:16:04 -05:00
|
|
|
describe '#matches?' do
|
2016-11-14 09:55:31 -05:00
|
|
|
context 'valid request' do
|
|
|
|
let(:request) { build_request(group.path) }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_truthy }
|
|
|
|
end
|
|
|
|
|
2016-10-31 07:00:53 -04:00
|
|
|
context 'valid request for nested group' do
|
|
|
|
let!(:nested_group) { create(:group, path: 'nested', parent: group) }
|
|
|
|
let!(:request) { build_request('gitlab/nested') }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_truthy }
|
|
|
|
end
|
|
|
|
|
2017-04-05 09:41:00 -04:00
|
|
|
context 'valid request for nested group with reserved top level name' do
|
|
|
|
let!(:nested_group) { create(:group, path: 'api', parent: group) }
|
|
|
|
let!(:request) { build_request('gitlab/api') }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_truthy }
|
|
|
|
end
|
|
|
|
|
2016-11-14 09:55:31 -05:00
|
|
|
context 'invalid request' do
|
|
|
|
let(:request) { build_request('foo') }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
2016-11-07 08:16:04 -05:00
|
|
|
end
|
2017-05-01 16:46:30 -04:00
|
|
|
|
|
|
|
context 'when the request matches a redirect route' do
|
|
|
|
context 'for a root group' do
|
|
|
|
let!(:redirect_route) { group.redirect_routes.create!(path: 'gitlabb') }
|
|
|
|
|
|
|
|
context 'and is a GET request' do
|
|
|
|
let(:request) { build_request(redirect_route.path) }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and is NOT a GET request' do
|
|
|
|
let(:request) { build_request(redirect_route.path, 'POST') }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a nested group' do
|
|
|
|
let!(:nested_group) { create(:group, path: 'nested', parent: group) }
|
|
|
|
let!(:redirect_route) { nested_group.redirect_routes.create!(path: 'gitlabb/nested') }
|
|
|
|
let(:request) { build_request(redirect_route.path) }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
2016-11-07 08:16:04 -05:00
|
|
|
end
|
|
|
|
|
2017-05-01 16:46:30 -04:00
|
|
|
def build_request(path, method = 'GET')
|
|
|
|
double(:request,
|
|
|
|
'get?': (method == 'GET'),
|
|
|
|
params: { id: path })
|
2016-10-06 09:59:22 -04:00
|
|
|
end
|
|
|
|
end
|