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::UserUrlConstrainer do
|
2016-11-14 09:55:31 -05:00
|
|
|
let!(:user) { create(:user, username: 'dz') }
|
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(user.username) }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid request' do
|
|
|
|
let(:request) { build_request('foo') }
|
|
|
|
|
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
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) { user.namespace.redirect_routes.create!(path: 'foo') }
|
|
|
|
|
|
|
|
context 'and is a GET request' do
|
|
|
|
let(:request) { build_request(redirect_route.path) }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2017-05-01 16:46:30 -04:00
|
|
|
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') }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2017-05-01 16:46:30 -04:00
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2016-11-07 08:16:04 -05:00
|
|
|
end
|
|
|
|
|
2017-05-01 16:46:30 -04:00
|
|
|
def build_request(username, method = 'GET')
|
|
|
|
double(:request,
|
|
|
|
'get?': (method == 'GET'),
|
|
|
|
params: { username: username })
|
2016-10-06 09:59:22 -04:00
|
|
|
end
|
|
|
|
end
|