From de72db99fac56fa06fccdab443a1c4e44e8fb985 Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Sun, 16 Apr 2017 23:28:26 +0900 Subject: [PATCH] Add presence validation to Import (#1928) ``` *An* `ActiveRecord::StatementInvalid` *occurred while* `POST ` *was processed by* `imports#create` Exception ---------------- PG::NotNullViolation: ERROR: null value in column "type" violates not-null constraint ``` --- app/models/import.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/import.rb b/app/models/import.rb index 3013bc50eb4..85f6ca4bdf5 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -1,13 +1,15 @@ # frozen_string_literal: true class Import < ApplicationRecord + FILE_TYPES = ['text/plain', 'text/csv'].freeze + self.inheritance_column = false + belongs_to :account, required: true + enum type: [:following, :blocking, :muting] - belongs_to :account - - FILE_TYPES = ['text/plain', 'text/csv'].freeze + validates :type, presence: true has_attached_file :data, url: '/system/:hash.:extension', hash_secret: ENV['PAPERCLIP_SECRET'] validates_attachment_content_type :data, content_type: FILE_TYPES