BigW Consortium Gitlab

group_routing_spec.rb 5.25 KB
Newer Older
1 2
require 'spec_helper'

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
describe "Groups", "routing" do
  let(:group_path) { 'complex.group-namegit' }
  let!(:group) { create(:group, path: group_path) }

  it "to #show" do
    expect(get("/groups/#{group_path}")).to route_to('groups#show', id: group_path)
  end

  it "also supports nested groups" do
    nested_group = create(:group, parent: group)
    expect(get("/#{group_path}/#{nested_group.path}")).to route_to('groups#show', id: "#{group_path}/#{nested_group.path}")
  end

  it "also display group#show on the short path" do
    expect(get("/#{group_path}")).to route_to('groups#show', id: group_path)
  end

  it "to #activity" do
21
    expect(get("/groups/#{group_path}/-/activity")).to route_to('groups#activity', id: group_path)
22 23 24
  end

  it "to #issues" do
25
    expect(get("/groups/#{group_path}/-/issues")).to route_to('groups#issues', id: group_path)
26 27 28 29 30 31
  end

  it "to #members" do
    expect(get("/groups/#{group_path}/-/group_members")).to route_to('groups/group_members#index', group_id: group_path)
  end

32 33 34
  it "to #labels" do
    expect(get("/groups/#{group_path}/-/labels")).to route_to('groups/labels#index', group_id: group_path)
  end
35

36 37 38
  it "to #milestones" do
    expect(get("/groups/#{group_path}/-/milestones")).to route_to('groups/milestones#index', group_id: group_path)
  end
39

40
  describe 'legacy redirection' do
41
    describe 'labels' do
42
      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/labels", "/groups/complex.group-namegit/-/labels" do
43 44
        let(:resource) { create(:group, parent: group, path: 'labels') }
      end
45 46 47 48 49 50

      context 'when requesting JSON' do
        it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/labels.json", "/groups/complex.group-namegit/-/labels.json" do
          let(:resource) { create(:group, parent: group, path: 'labels') }
        end
      end
51 52 53
    end

    describe 'group_members' do
54
      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/group_members", "/groups/complex.group-namegit/-/group_members" do
55 56
        let(:resource) { create(:group, parent: group, path: 'group_members') }
      end
57 58
    end

59 60 61 62 63 64 65 66 67 68
    describe 'avatar' do
      it 'routes to the avatars controller' do
        expect(delete("/groups/#{group_path}/-/avatar"))
          .to route_to(group_id: group_path,
                       controller: 'groups/avatars',
                       action: 'destroy')
      end
    end

    describe 'milestones' do
69
      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/milestones", "/groups/complex.group-namegit/-/milestones" do
70 71
        let(:resource) { create(:group, parent: group, path: 'milestones') }
      end
72 73 74 75 76 77 78 79 80 81 82

      context 'nested routes' do
        include RSpec::Rails::RequestExampleGroup

        let(:milestone) { create(:milestone, group: group) }

        it 'redirects the nested routes' do
          request = get("/groups/#{group_path}/milestones/#{milestone.id}/merge_requests")
          expect(request).to redirect_to("/groups/#{group_path}/-/milestones/#{milestone.id}/merge_requests")
        end
      end
83 84

      context 'with a query string' do
85
        it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/milestones?hello=world", "/groups/complex.group-namegit/-/milestones?hello=world" do
86 87 88
          let(:resource) { create(:group, parent: group, path: 'milestones') }
        end

89
        it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/milestones?milestones=/milestones", "/groups/complex.group-namegit/-/milestones?milestones=/milestones" do
90 91 92
          let(:resource) { create(:group, parent: group, path: 'milestones') }
        end
      end
93
    end
94 95

    describe 'edit' do
96
      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/edit", "/groups/complex.group-namegit/-/edit" do
97 98 99 100 101 102 103 104
        let(:resource) do
          pending('still rejected because of the wildcard reserved word')
          create(:group, parent: group, path: 'edit')
        end
      end
    end

    describe 'issues' do
105
      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/issues", "/groups/complex.group-namegit/-/issues" do
106 107 108 109 110
        let(:resource) { create(:group, parent: group, path: 'issues') }
      end
    end

    describe 'merge_requests' do
111
      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/merge_requests", "/groups/complex.group-namegit/-/merge_requests" do
112 113 114 115 116
        let(:resource) { create(:group, parent: group, path: 'merge_requests') }
      end
    end

    describe 'projects' do
117
      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/projects", "/groups/complex.group-namegit/-/projects" do
118 119 120 121 122
        let(:resource) { create(:group, parent: group, path: 'projects') }
      end
    end

    describe 'activity' do
123
      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/activity", "/groups/complex.group-namegit/-/activity" do
124 125 126
        let(:resource) { create(:group, parent: group, path: 'activity') }
      end

127
      it_behaves_like 'redirecting a legacy path', "/groups/activity/activity", "/groups/activity/-/activity" do
128 129 130 131
        let!(:parent) { create(:group, path: 'activity') }
        let(:resource) { create(:group, parent: parent, path: 'activity') }
      end
    end
132 133
  end
end