fix (potential) problems with empty file_extensions
This commit is contained in:
@ -264,7 +264,7 @@ $(document).on('turbolinks:load', function () {
|
|||||||
var inferFileAttributes = function () {
|
var inferFileAttributes = function () {
|
||||||
$(document).on('change', 'input[type="file"]', function () {
|
$(document).on('change', 'input[type="file"]', function () {
|
||||||
var filename = $(this).val().split(/\\|\//g).pop();
|
var filename = $(this).val().split(/\\|\//g).pop();
|
||||||
var file_extension = '.' + filename.split('.')[1];
|
var file_extension = filename.includes('.') ? '.' + filename.split('.')[1] : '';
|
||||||
var file_type = findFileTypeByFileExtension(file_extension);
|
var file_type = findFileTypeByFileExtension(file_extension);
|
||||||
var name = filename.split('.')[0];
|
var name = filename.split('.')[0];
|
||||||
var parent = $(this).parents('li');
|
var parent = $(this).parents('li');
|
||||||
|
@ -26,7 +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}
|
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
|
||||||
|
@ -101,8 +101,8 @@ module ProformaService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def file_type(extension)
|
def file_type(extension)
|
||||||
FileType.find_or_create_by(file_extension: extension.presence) do |file_type|
|
FileType.find_or_create_by(file_extension: extension) do |file_type|
|
||||||
file_type.name = extension[1..]
|
file_type.name = "Imported #{extension}"
|
||||||
file_type.user = @user
|
file_type.user = @user
|
||||||
file_type.indent_size = 4
|
file_type.indent_size = 4
|
||||||
file_type.editor_mode = 'ace/mode/plain_text'
|
file_type.editor_mode = 'ace/mode/plain_text'
|
||||||
|
@ -157,6 +157,24 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
expect { convert_to_exercise_service.save! }.to change(Exercise, :count).by(1)
|
expect { convert_to_exercise_service.save! }.to change(Exercise, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when file is a Makefile' do
|
||||||
|
let(:filename) { "#{path}Makefile" }
|
||||||
|
|
||||||
|
it 'creates an exercise with a file with a Filetype, that has the correct attributes' do
|
||||||
|
expect(convert_to_exercise_service.files.first).to have_attributes(
|
||||||
|
file_type: be_a(FileType).and(have_attributes(file_extension: '', name: 'Imported'))
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when FileType for Makefile exists' do
|
||||||
|
let!(:makefile_filetype) { create(:makefile) }
|
||||||
|
|
||||||
|
it 'creates an exercise with a file with a Filetype, that has the correct attributes' do
|
||||||
|
expect(convert_to_exercise_service.files.first).to have_attributes(file_type: makefile_filetype)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when file is a main_file' do
|
context 'when file is a main_file' do
|
||||||
let(:meta_data) do
|
let(:meta_data) do
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user