2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Constraints::UserUrlConstrainer do
|
2017-08-17 22:00:37 +05:30
|
|
|
let!(:user) { create(:user, username: 'dz') }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#matches?' do
|
|
|
|
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
|
|
|
|
|
|
|
|
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) }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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') }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { expect(subject.matches?(request)).to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_request(username, method = 'GET')
|
|
|
|
double(:request,
|
|
|
|
'get?': (method == 'GET'),
|
|
|
|
params: { username: username })
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
end
|