mirror of
https://github.com/gitlabhq/gitlabhq.git
synced 2025-07-25 17:08:32 +00:00
Add latest changes from gitlab-org/gitlab@17-11-stable-ee
This commit is contained in:
@ -8,8 +8,21 @@ module Pages
|
||||
|
||||
alias_method :upload, :model
|
||||
|
||||
def filename
|
||||
trim_filename_if_needed(super)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Trims filename to 60 characters from the front if it exceeds that length
|
||||
def trim_filename_if_needed(filename)
|
||||
return if filename.nil?
|
||||
return filename if filename.length <= 60
|
||||
|
||||
# Take the last 60 characters
|
||||
filename[-60..]
|
||||
end
|
||||
|
||||
def dynamic_segment
|
||||
Gitlab::HashedPath.new('pages_deployments', model.id, root_hash: model.project_id)
|
||||
end
|
||||
|
@ -59,4 +59,39 @@ RSpec.describe Pages::DeploymentUploader, feature_category: :pages do
|
||||
expect(File.exist?(file.path)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#trim_filename_if_needed' do
|
||||
where(:input_filename, :expected_output, :description) do
|
||||
[
|
||||
['short_filename.zip', 'short_filename.zip', 'under 60 characters'],
|
||||
["#{'a' * 70}.zip", "#{'a' * 70}.zip"[-60..], 'over 60 characters'],
|
||||
["#{'a' * 56}.zip", "#{'a' * 56}.zip", 'exactly 60 characters'],
|
||||
['very_long_file_name_with_underscores_and_numbers_123456789_and_more_text.tar.gz',
|
||||
'very_long_file_name_with_underscores_and_numbers_123456789_and_more_text.tar.gz'[-60..],
|
||||
'complex with multi-part extension']
|
||||
]
|
||||
end
|
||||
|
||||
with_them do
|
||||
it "correctly trims filename when #{params[:description]}" do
|
||||
result = uploader.send(:trim_filename_if_needed, input_filename)
|
||||
|
||||
expect(result).to eq(expected_output)
|
||||
|
||||
if input_filename.length > 60
|
||||
expect(result.length).to eq(60)
|
||||
else
|
||||
expect(result).to eq(input_filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "handles nil input by returning nil" do
|
||||
expect(uploader.send(:trim_filename_if_needed, nil)).to be_nil
|
||||
end
|
||||
|
||||
it "handles empty string by returning empty string" do
|
||||
expect(uploader.send(:trim_filename_if_needed, "")).to eq("")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user