Better handle modeling predictions for items with *no* data

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!
This commit is contained in:
Emi Matchu 2024-11-19 12:15:21 -08:00
parent f90380c4e6
commit f7109e398a
2 changed files with 6 additions and 2 deletions

View file

@ -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

View file

@ -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