From f7109e398a8df15d533c1f83e29be6c6658c7a48 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 19 Nov 2024 12:15:21 -0800 Subject: [PATCH] Better handle modeling predictions for items with *no* data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doesn't generally happen, but did the other day when I rolled back some of the database's SWF asset records but kept the items—and it was a bit confusing that the homepage marked them as fully modeled! --- app/models/item.rb | 4 ++++ spec/models/item_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index 8be75718..4b7a4feb 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -291,6 +291,10 @@ class Item < ApplicationRecord # This might just be a species-specific item. Let's be conservative in # our prediction, though we'll revise it if we see another body ID. compatible_body_ids + elsif compatible_body_ids.size == 0 + # If somehow we have this item, but not any modeling data for it (weird!), + # consider it to fit all standard pet types until shown otherwise. + PetType.basic.distinct.pluck(:body_id).sort else # First, find our compatible pet types, then pair each body ID with its # color. (As an optimization, we omit standard colors, other than the diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index b8434aae..1b640742 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -29,11 +29,11 @@ RSpec.describe Item do describe "an item without any modeling data" do subject(:item) { items(:straw_hat) } - pending("is not fully modeled") { should_not be_predicted_fully_modeled } + it("is not fully modeled") { should_not be_predicted_fully_modeled } it("has no compatible body IDs") do expect(item.compatible_body_ids).to be_empty end - pending("predicts all standard bodies are compatible") do + it("predicts all standard bodies are compatible") do expect(item.predicted_missing_body_ids).to contain_exactly(1, 2, 3) end end