BigW Consortium Gitlab

project_url_constrainer_spec.rb 1.53 KB
Newer Older
1 2
require 'spec_helper'

3
describe ProjectUrlConstrainer do
4
  let!(:project) { create(:project) }
5 6 7 8
  let!(:namespace) { project.namespace }

  describe '#matches?' do
    context 'valid request' do
9
      let(:request) { build_request(namespace.full_path, project.path) }
10 11 12 13 14 15 16 17 18 19 20 21

      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 }
      end

      context "project id ending with .git" do
22
        let(:request) { build_request(namespace.full_path, project.path + '.git') }
23 24 25 26

        it { expect(subject.matches?(request)).to be_falsey }
      end
    end
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

    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) }
        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') }
        it { expect(subject.matches?(request)).to be_falsey }
      end
    end
42 43
  end

44 45 46 47
  def build_request(namespace, project, method = 'GET')
    double(:request,
      'get?': (method == 'GET'),
      params: { namespace_id: namespace, id: project })
48 49
  end
end