summaryrefslogtreecommitdiff
path: root/spec/routing/group_routing_spec.rb
blob: b3e55f5e3c9f6811e4bd8a957ac41ad58826488a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'spec_helper'

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
    expect(get("/groups/#{group_path}/activity")).to route_to('groups#activity', id: group_path)
  end

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

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

  describe 'legacy redirection' do
    shared_examples 'canonical groups route' do |path|
      it "#{path} routes to the correct controller" do
        expect(get("/groups/#{group_path}/-/#{path}"))
          .to route_to(group_id: group_path,
                       controller: "groups/#{path}",
                       action: 'index')
      end

      it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/#{path}", "/groups/complex.group-namegit/-/#{path}/" do
        let(:resource) { create(:group, parent: group, path: path) }
      end
    end

    describe 'labels' do
      it_behaves_like 'canonical groups route', 'labels'
    end

    describe 'group_members' do
      it_behaves_like 'canonical groups route', 'group_members'
    end

    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
      it_behaves_like 'canonical groups route', 'milestones'

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