add file_extension validation for file_type
This commit is contained in:
@ -26,6 +26,7 @@ class FileType < ApplicationRecord
|
|||||||
validates :indent_size, presence: true, unless: :binary?
|
validates :indent_size, presence: true, unless: :binary?
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :renderable, inclusion: [true, false]
|
validates :renderable, inclusion: [true, false]
|
||||||
|
validates :file_extension, length: { minimum:0, allow_nil: false}
|
||||||
|
|
||||||
%i[audio compressed csv excel image pdf powerpoint video word].each do |type|
|
%i[audio compressed csv excel image pdf powerpoint video word].each do |type|
|
||||||
define_method("#{type}?") do
|
define_method("#{type}?") do
|
||||||
|
@ -186,6 +186,7 @@ FactoryBot.define do
|
|||||||
factory :makefile, class: 'FileType' do
|
factory :makefile, class: 'FileType' do
|
||||||
created_by_admin
|
created_by_admin
|
||||||
editor_mode { 'ace/mode/makefile' }
|
editor_mode { 'ace/mode/makefile' }
|
||||||
|
file_extension { '' }
|
||||||
executable
|
executable
|
||||||
indent_size { 2 }
|
indent_size { 2 }
|
||||||
name { 'Makefile' }
|
name { 'Makefile' }
|
||||||
|
@ -54,4 +54,10 @@ describe FileType do
|
|||||||
it 'validates the presence of a user' do
|
it 'validates the presence of a user' do
|
||||||
expect(file_type.errors[:user]).to be_present
|
expect(file_type.errors[:user]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'validates the presence of the file_extension' do
|
||||||
|
expect(file_type.errors[:file_extension]).to be_present
|
||||||
|
file_type.update(file_extension: '')
|
||||||
|
expect(file_type.errors[:file_extension]).to be_blank
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user