diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 85a6e6dffc60f898fbeff9b3e419167c837f33c9..d3af8c30f5283d224f46399ccc04bf0889bedf2c 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -67,7 +67,7 @@ class Form::AdminSettings KEYS.each do |key| value = instance_variable_get("@#{key}") - if UPLOAD_KEYS.include?(key) + if UPLOAD_KEYS.include?(key) && !value.nil? upload = SiteUpload.where(var: key).first_or_initialize(var: key) upload.update(file: value) else diff --git a/app/models/site_upload.rb b/app/models/site_upload.rb index 14d68376727619d8e448c53b851ce392f922283a..cf10b30fc98ee3d23d0d3433b38834584c702eb8 100644 --- a/app/models/site_upload.rb +++ b/app/models/site_upload.rb @@ -18,6 +18,7 @@ class SiteUpload < ApplicationRecord has_attached_file :file validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/ + validates :file, presence: true validates :var, presence: true, uniqueness: true before_save :set_meta diff --git a/spec/fabricators/assets/TEAPOT b/spec/fabricators/assets/TEAPOT new file mode 100644 index 0000000000000000000000000000000000000000..e624ecb4cc87a58076dfa94bf578d875dd327446 --- /dev/null +++ b/spec/fabricators/assets/TEAPOT @@ -0,0 +1,6 @@ +This "Utah teapot" photograph is licensed under the Creative Commons +Attribution-Share Alike 3.0 Unported license: + https://creativecommons.org/licenses/by-sa/3.0/deed.en + +Original source of work: + https://commons.wikimedia.org/wiki/File:Utah_teapot_simple_2.png diff --git a/spec/fabricators/assets/utah_teapot.png b/spec/fabricators/assets/utah_teapot.png new file mode 100644 index 0000000000000000000000000000000000000000..6708361e5aceffc71c344a5266486b707bc6a1d2 Binary files /dev/null and b/spec/fabricators/assets/utah_teapot.png differ diff --git a/spec/fabricators/site_upload_fabricator.rb b/spec/fabricators/site_upload_fabricator.rb index 4a171486f67029d59e1503e63a3163118abfa713..2efc57e2803010f4f247d80dc41e4460794992e4 100644 --- a/spec/fabricators/site_upload_fabricator.rb +++ b/spec/fabricators/site_upload_fabricator.rb @@ -1,2 +1,3 @@ Fabricator(:site_upload) do + file { File.open(File.join(Rails.root, 'spec', 'fabricators', 'assets', 'utah_teapot.png')) } end