route_spec.rb 1.6 KB
Newer Older
1 2 3
require 'spec_helper'

describe Route, models: true do
4
  let!(:group) { create(:group, path: 'gitlab', name: 'gitlab') }
5 6 7 8 9 10 11 12 13 14 15 16
  let!(:route) { group.route }

  describe 'relationships' do
    it { is_expected.to belong_to(:source) }
  end

  describe 'validations' do
    it { is_expected.to validate_presence_of(:source) }
    it { is_expected.to validate_presence_of(:path) }
    it { is_expected.to validate_uniqueness_of(:path) }
  end

17
  describe '#rename_descendants' do
18 19 20
    let!(:nested_group) { create(:group, path: 'test', name: 'test', parent: group) }
    let!(:deep_nested_group) { create(:group, path: 'foo', name: 'foo', parent: nested_group) }
    let!(:similar_group) { create(:group, path: 'gitlab-org', name: 'gitlab-org') }
21

22 23
    context 'path update' do
      before { route.update_attributes(path: 'bar') }
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
      it "updates children routes with new path" do
        expect(described_class.exists?(path: 'bar')).to be_truthy
        expect(described_class.exists?(path: 'bar/test')).to be_truthy
        expect(described_class.exists?(path: 'bar/test/foo')).to be_truthy
        expect(described_class.exists?(path: 'gitlab-org')).to be_truthy
      end
    end

    context 'name update' do
      before { route.update_attributes(name: 'bar') }

      it "updates children routes with new path" do
        expect(described_class.exists?(name: 'bar')).to be_truthy
        expect(described_class.exists?(name: 'bar / test')).to be_truthy
        expect(described_class.exists?(name: 'bar / test / foo')).to be_truthy
        expect(described_class.exists?(name: 'gitlab-org')).to be_truthy
      end
42 43 44
    end
  end
end