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
|
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200602013901_cap_designs_filename_length_to_new_limit')
describe CapDesignsFilenameLengthToNewLimit, :migration, schema: 20200528125905 do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:issues) { table(:issues) }
let(:designs) { table(:design_management_designs) }
let(:filename_below_limit) { generate_filename(254) }
let(:filename_at_limit) { generate_filename(255) }
let(:filename_above_limit) { generate_filename(256) }
let!(:namespace) { namespaces.create!(name: 'foo', path: 'foo') }
let!(:project) { projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab', namespace_id: namespace.id) }
let!(:issue) { issues.create!(description: 'issue', project_id: project.id) }
def generate_filename(length, extension: '.png')
name = 'a' * (length - extension.length)
"#{name}#{extension}"
end
def create_design(filename)
designs.create!(
issue_id: issue.id,
project_id: project.id,
filename: filename
)
end
it 'correctly sets filenames that are above the limit' do
[
filename_below_limit,
filename_at_limit,
filename_above_limit
].each(&method(:create_design))
migrate!
expect(designs.find(1).filename).to eq(filename_below_limit)
expect(designs.find(2).filename).to eq(filename_at_limit)
expect(designs.find(3).filename).to eq([described_class::MODIFIED_NAME, 3, described_class::MODIFIED_EXTENSION].join)
end
it 'runs after filename limit has been set' do
# This spec file uses the `schema:` keyword to run these tests
# against a schema version before the one that sets the limit,
# as otherwise we can't create the design data with filenames greater
# than the limit.
#
# For this test, we migrate any skipped versions up to this migration.
migration_context.migrate(20200602013901)
create_design(filename_at_limit)
expect { create_design(filename_above_limit) }.to raise_error(ActiveRecord::StatementInvalid)
end
end
|