debian-mirror-gitlab/spec/lib/constraints/project_url_constrainer_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Constraints::ProjectUrlConstrainer do
2017-09-10 17:25:29 +05:30
let!(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let!(:namespace) { project.namespace }
describe '#matches?' do
context 'valid request' do
let(:request) { build_request(namespace.full_path, project.path) }
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 }
2019-03-13 22:55:13 +05:30
context 'existence_check is false' do
it { expect(subject.matches?(request, existence_check: false)).to be_truthy }
end
2017-08-17 22:00:37 +05:30
end
context "project id ending with .git" do
let(:request) { build_request(namespace.full_path, project.path + '.git') }
it { expect(subject.matches?(request)).to be_falsey }
end
end
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) }
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(namespace.full_path, old_project_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(namespace, project, method = 'GET')
double(:request,
'get?': (method == 'GET'),
params: { namespace_id: namespace, id: project })
end
end