Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds further validations #1511

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/dmsf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DmsfFile < ApplicationRecord
scope :deleted, -> { where(deleted: STATUS_DELETED) }

validates :name, dmsf_file_name: true
validates :name, length: { maximum: 255 }
validates :name,
uniqueness: {
scope: %i[dmsf_folder_id project_id deleted],
Expand Down
3 changes: 3 additions & 0 deletions app/models/dmsf_file_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ class DmsfFileRevision < ApplicationRecord
)

validates :title, presence: true
validates :title, length: { maximum: 255 }
validates :major_version, presence: true
validates :name, dmsf_file_name: true
validates :name, length: { maximum: 255 }
validates :disk_filename, length: { maximum: 255 }
validates :description, length: { maximum: 1.kilobyte }
validates :size, dmsf_max_file_size: true

Expand Down
25 changes: 25 additions & 0 deletions test/unit/dmsf_file_revision_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ def setup
@wf1 = DmsfWorkflow.find 1
end

def test_file_title_length_validation
file = DmsfFileRevision.new(title: Array.new(256).map { 'a' }.join,
name: 'Test Revision',
major_version: 1)
assert file.invalid?
assert_equal ['Title is too long (maximum is 255 characters)'], file.errors.full_messages
end

def test_file_name_length_validation
file = DmsfFileRevision.new(name: Array.new(256).map { 'a' }.join,
title: 'Test Revision',
major_version: 1)
assert file.invalid?
assert_equal ['Name is too long (maximum is 255 characters)'], file.errors.full_messages
end

def test_file_disk_filename_length_validation
file = DmsfFileRevision.new(disk_filename: Array.new(256).map { 'a' }.join,
title: 'Test Revision',
name: 'Test Revision',
major_version: 1)
assert file.invalid?
assert_equal ['Disk filename is too long (maximum is 255 characters)'], file.errors.full_messages
end

def test_delete_restore
@revision5.delete commit: false
assert @revision5.deleted?, "File revision #{@revision5.name} hasn't been deleted"
Expand Down
6 changes: 6 additions & 0 deletions test/unit/dmsf_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def setup
@wf2 = DmsfWorkflow.find 2
end

def test_file_name_length_validation
file = DmsfFile.new(name: Array.new(256).map { 'a' }.join)
assert file.invalid?
assert_equal ['Name is too long (maximum is 255 characters)'], file.errors.full_messages
end

def test_project_file_count_differs_from_project_visibility_count
assert_not_same @project1.dmsf_files.all.size, @project1.dmsf_files.visible.all.size
end
Expand Down
Loading