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
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170518231126_fix_wrongly_renamed_routes.rb')
describe FixWronglyRenamedRoutes, truncate: true do
let(:subject) { described_class.new }
let(:broken_namespace) do
namespace = create(:group, name: 'apiis')
namespace.route.update_attribute(:path, 'api0is')
namespace
end
describe '#wrongly_renamed' do
it "includes routes that have names that don't match their namespace" do
broken_namespace
_other_namespace = create(:group, name: 'api0')
expect(subject.wrongly_renamed.map(&:id))
.to contain_exactly(broken_namespace.route.id)
end
end
describe "#paths_and_corrections" do
it 'finds the wrong path and gets the correction from the namespace' do
broken_namespace
namespace = create(:group, name: 'uploads-test')
namespace.route.update_attribute(:path, 'uploads0-test')
expected_result = [
{ 'namespace_path' => 'apiis', 'path' => 'api0is' },
{ 'namespace_path' => 'uploads-test', 'path' => 'uploads0-test' }
]
expect(subject.paths_and_corrections).to include(*expected_result)
end
end
describe '#routes_in_namespace_query' do
it 'includes only the required routes' do
namespace = create(:group, path: 'hello')
project = create(:project, namespace: namespace)
_other_namespace = create(:group, path: 'hello0')
result = Route.where(subject.routes_in_namespace_query('hello'))
expect(result).to contain_exactly(namespace.route, project.route)
end
end
describe '#up' do
let(:broken_project) do
project = create(:project, namespace: broken_namespace, path: 'broken-project')
project.route.update_attribute(:path, 'api0is/broken-project')
project
end
it 'renames incorrectly named routes' do
broken_project
subject.up
expect(broken_project.route.reload.path).to eq('apiis/broken-project')
expect(broken_namespace.route.reload.path).to eq('apiis')
end
it "doesn't touch namespaces that look like something that should be renamed" do
namespace = create(:group, path: 'api0')
subject.up
expect(namespace.route.reload.path).to eq('api0')
end
end
end