From 0261d021379f903d66cc56e727adbda796c28938 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 19 Nov 2024 17:00:47 -0800 Subject: [PATCH] Downgrade most item validations to be *not nil*, rather than present Been running into the item "Hanging Plushie Grundo Background Item" not being modelable, because TNT seem to have left its description blank! Let's be less picky about what data we take in, but keep the intention of these validations: to ensure that *we* don't make a mistake and forget a field when importing items! --- app/models/item.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index 49aec183..a65a9352 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -23,8 +23,13 @@ class Item < ApplicationRecord has_many :dyeworks_variants, class_name: "Item", inverse_of: :dyeworks_base_item - validates_presence_of :name, :description, :thumbnail_url, :rarity, :price, - :zones_restrict + # We require a name field. A number of other fields must be *specified*: they + # can't be nil, to help ensure we aren't forgetting any fields when importing + # items. But sometimes they happen to be blank (e.g. when TNT leaves an item + # description empty, oops), in which case we want to accept that reality! + validates_presence_of :name + validates :description, :thumbnail_url, :rarity, :price, :zones_restrict, + exclusion: {in: [nil], message: "must be specified"} attr_writer :current_body_id, :owned, :wanted