2016-10-06 09:59:22 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-08 07:56:54 -05:00
|
|
|
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) }
|
|
|
|
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
|
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
|