1
0
Fork 0
forked from OpenNeo/impress

Handle invalid Item state a bit better

Catch missing fields in validation before sending it to the DB, and
skip the Dyeworks stuff if the name is missing.

I ran into this looking into `test/trade_activity_test.rb`, which fails
right now because we try to create a boring placeholder item with
minimal fields, which Dyeworks can't call `name.match()` on!

Now, the test fails with a more helpful error about the item being
invalid. Next, I'll fix that!
This commit is contained in:
Emi Matchu 2024-10-21 14:24:45 -07:00
parent 881e63cfbd
commit 540ce08caa
2 changed files with 3 additions and 1 deletions

View file

@ -23,6 +23,8 @@ 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
attr_writer :current_body_id, :owned, :wanted

View file

@ -117,7 +117,7 @@ class Item
)\z
}x
def inferred_dyeworks_base_item
name_match = name.match(DYEWORKS_NAME_PATTERN)
name_match = (name || "").match(DYEWORKS_NAME_PATTERN)
return nil if name_match.nil?
Item.find_by_name(name_match["base"])