Welcome to mirror list, hosted at ThFree Co, Russian Federation.

wiki_routing_spec.rb « routing « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 94349dbaa74f6d34d6b642b3b0bc6eddc33021b9 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# frozen_string_literal: true

require 'spec_helper'

# We build URIs to wiki pages manually in various places (most notably
# in markdown generation). To ensure these do not get out of sync, these
# tests verify that our path generation assumptions are sound.
describe 'Wiki path generation assumptions' do
  set(:project) { create(:project, :public, :repository) }

  let(:project_wiki) { ProjectWiki.new(project, project.owner) }
  let(:some_page_name) { 'some-wiki-page' }
  let(:wiki_page) do
    create(:wiki_page, wiki: project_wiki, attrs: { title: some_page_name })
  end

  describe 'WikiProject#wiki_page_path', 'routing' do
    it 'is consistent with routing to wiki#show' do
      uri = URI.parse(project_wiki.wiki_page_path)
      path = ::File.join(uri.path, some_page_name)

      expect(get('/' + path)).to route_to('projects/wiki_pages#show',
                                          id: some_page_name,
                                          namespace_id: project.namespace.to_param,
                                          project_id: project.to_param)
    end
  end

  describe 'project_wiki_path', 'routing' do
    describe 'GET' do
      it 'routes to the :show action' do
        path = project_wiki_path(project, wiki_page)

        expect(get('/' + path)).to route_to('projects/wiki_pages#show',
                                            id: wiki_page.slug,
                                            namespace_id: project.namespace.to_param,
                                            project_id: project.to_param)
      end
    end
  end

  describe 'project_wiki_pages_new_path', 'routing' do
    describe 'GET' do
      it 'routes to the :new action' do
        path = project_wiki_pages_new_path(project)

        expect(get('/' + path)).to route_to('projects/wiki_pages#new',
                                            namespace_id: project.namespace.to_param,
                                            project_id: project.to_param)
      end
    end
  end

  # Early versions of the wiki paths routed all wiki pages at
  # /wikis/:id - this test exists to guarantee that we support
  # old URIs that may be out there, saved in bookmarks, on other wikis, etc.
  describe 'legacy route support', type: 'request' do
    let(:path) { ::File.join(project_wikis_path(project), some_page_name) }

    before do
      get(path)
    end

    it 'routes to new wiki paths' do
      dest = project_wiki_path(project, wiki_page)

      expect(response).to redirect_to(dest)
    end

    context 'the page is nested in a directory' do
      let(:some_page_name) { 'some-dir/some-deep-dir/some-page' }
      let(:path) { ::File.join(project_wikis_path(project), some_page_name) }

      it 'still routes correctly' do
        dest = project_wiki_path(project, wiki_page)

        expect(response).to redirect_to(dest)
      end
    end

    context 'the user requested the old history path' do
      let(:some_page_name) { 'some-dir/some-deep-dir/some-page' }
      let(:path) { ::File.join(project_wikis_path(project), some_page_name, 'history') }

      it 'redirects to the new history path' do
        dest = project_wiki_history_path(project, wiki_page)

        expect(response).to redirect_to(dest)
      end
    end

    context 'the user requested the old edit path' do
      let(:some_page_name) { 'some-dir/some-deep-dir/some-page' }
      let(:path) { ::File.join(project_wikis_path(project), some_page_name, 'edit') }

      it 'redirects to the new history path' do
        dest = project_wiki_edit_path(project, wiki_page)

        expect(response).to redirect_to(dest)
      end
    end
  end
end