2024-11-19 12:10:49 -08:00
|
|
|
require_relative '../rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Item do
|
|
|
|
fixtures :items, :colors, :species, :zones
|
|
|
|
|
|
|
|
context "modeling status:" do
|
|
|
|
# Rather than using fixtures of real-world data, we create very specific
|
|
|
|
# pet types, to be able to create small encapsulated test cases where there
|
|
|
|
# are only a few bodies.
|
2024-11-19 13:31:34 -08:00
|
|
|
#
|
|
|
|
# We create some basic color pet types, and some Maraquan pet types—and,
|
|
|
|
# just like irl, the Maraquan Mynci has the same body as the basic Mynci.
|
2024-11-19 12:10:49 -08:00
|
|
|
before do
|
|
|
|
PetType.destroy_all # Make sure no leftovers from e.g. PetType's spec!
|
2024-11-19 13:31:34 -08:00
|
|
|
|
2024-11-19 12:10:49 -08:00
|
|
|
build_pt(colors(:blue), species(:acara), body_id: 1).save!
|
|
|
|
build_pt(colors(:red), species(:acara), body_id: 1).save!
|
2024-11-19 13:31:34 -08:00
|
|
|
build_pt(colors(:blue), species(:blumaroo), body_id: 2).save!
|
|
|
|
build_pt(colors(:green), species(:chia), body_id: 3).save!
|
|
|
|
build_pt(colors(:red), species(:mynci), body_id: 4).save!
|
|
|
|
|
|
|
|
build_pt(colors(:maraquan), species(:acara), body_id: 11).save!
|
|
|
|
build_pt(colors(:maraquan), species(:blumaroo), body_id: 12).save!
|
|
|
|
build_pt(colors(:maraquan), species(:chia), body_id: 13).save!
|
|
|
|
build_pt(colors(:maraquan), species(:mynci), body_id: 4).save!
|
2024-11-19 12:10:49 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def build_pt(color, species, body_id:)
|
|
|
|
PetType.new(color:, species:, body_id:)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_item_asset(zone, body_id:)
|
|
|
|
@remote_id = (@remote_id || 0) + 1
|
2024-11-19 13:32:47 -08:00
|
|
|
url = "https://images.neopets.example/#{@remote_id}.swf"
|
|
|
|
SwfAsset.new(type: "object", remote_id: @remote_id, url:,
|
2024-11-19 12:10:49 -08:00
|
|
|
zones_restrict: "", zone:, body_id:)
|
|
|
|
end
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
shared_examples "a fully-modeled item" do
|
|
|
|
it("is considered fully modeled") { should be_predicted_fully_modeled }
|
|
|
|
it("predicts no more compatible bodies") do
|
|
|
|
expect(item.predicted_missing_body_ids).to be_empty
|
|
|
|
end
|
2024-11-19 15:52:52 -08:00
|
|
|
it("appears in Item.is_modeled") do
|
|
|
|
expect(Item.is_modeled.find_by_id(item.id)).to be_present
|
2024-11-19 13:44:31 -08:00
|
|
|
end
|
2024-11-19 15:52:52 -08:00
|
|
|
it("does not appear in Item.is_not_modeled") do
|
|
|
|
expect(Item.is_not_modeled.find_by_id(item.id)).to be_nil
|
2024-11-19 13:44:31 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "a not-fully-modeled item" do
|
|
|
|
it("is not fully modeled") { should_not be_predicted_fully_modeled }
|
2024-11-19 15:52:52 -08:00
|
|
|
it("does not appear in Item.is_modeled") do
|
|
|
|
expect(Item.is_modeled.find_by_id(item.id)).to be_nil
|
2024-11-19 13:44:31 -08:00
|
|
|
end
|
2024-11-19 15:52:52 -08:00
|
|
|
it("appears in Item.is_not_modeled") do
|
|
|
|
expect(Item.is_not_modeled.find_by_id(item.id)).to be_present
|
2024-11-19 13:44:31 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-11-19 12:10:49 -08:00
|
|
|
describe "an item without any modeling data" do
|
|
|
|
subject(:item) { items(:straw_hat) }
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
it_behaves_like "a not-fully-modeled item"
|
2024-11-19 12:10:49 -08:00
|
|
|
it("has no compatible body IDs") do
|
|
|
|
expect(item.compatible_body_ids).to be_empty
|
|
|
|
end
|
2024-11-19 12:15:21 -08:00
|
|
|
it("predicts all standard bodies are compatible") do
|
2024-11-19 13:31:34 -08:00
|
|
|
expect(item.predicted_missing_body_ids).to contain_exactly(1, 2, 3, 4)
|
2024-11-19 12:10:49 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "an item with one species modeled" do
|
|
|
|
subject(:item) { items(:straw_hat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 1)
|
|
|
|
end
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
it_behaves_like "a fully-modeled item"
|
2024-11-19 12:10:49 -08:00
|
|
|
it("has one compatible body ID") do
|
|
|
|
expect(item.compatible_body_ids).to contain_exactly(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "an item with two species modeled" do
|
|
|
|
subject(:item) { items(:straw_hat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 1)
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 2)
|
|
|
|
end
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
it_behaves_like "a not-fully-modeled item"
|
2024-11-19 12:10:49 -08:00
|
|
|
it("has two compatible body IDs") do
|
|
|
|
expect(item.compatible_body_ids).to contain_exactly(1, 2)
|
|
|
|
end
|
|
|
|
it("predicts remaining standard bodies are compatible") do
|
2024-11-19 13:31:34 -08:00
|
|
|
expect(item.predicted_missing_body_ids).to contain_exactly(3, 4)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "an item with all standard species modeled" do
|
|
|
|
subject(:item) { items(:straw_hat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 1)
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 2)
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 3)
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 4)
|
|
|
|
end
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
it_behaves_like "a fully-modeled item"
|
2024-11-19 13:31:34 -08:00
|
|
|
it("is compatible with all standard body IDs") do
|
|
|
|
expect(item.compatible_body_ids).to contain_exactly(1, 2, 3, 4)
|
|
|
|
end
|
2024-11-19 12:10:49 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "an item that fits all pets the same" do
|
|
|
|
subject(:item) { items(:straw_hat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
item.swf_assets << build_item_asset(zones(:background), body_id: 0)
|
|
|
|
end
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
it_behaves_like "a fully-modeled item"
|
2024-11-19 12:10:49 -08:00
|
|
|
it("is compatible with all bodies (body ID = 0)") do
|
|
|
|
expect(item.compatible_body_ids).to contain_exactly(0)
|
|
|
|
end
|
|
|
|
end
|
2024-11-19 12:18:17 -08:00
|
|
|
|
2024-11-19 13:31:34 -08:00
|
|
|
describe "an item with one Maraquan pet modeled" do
|
|
|
|
subject(:item) { items(:straw_hat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 11)
|
|
|
|
end
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
it_behaves_like "a fully-modeled item"
|
2024-11-19 13:31:34 -08:00
|
|
|
it("has one compatible body ID") do
|
|
|
|
expect(item.compatible_body_ids).to contain_exactly(11)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "an item with two Maraquan pets modeled" do
|
|
|
|
subject(:item) { items(:straw_hat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 11)
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 12)
|
|
|
|
end
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
it_behaves_like "a not-fully-modeled item"
|
2024-11-19 13:31:34 -08:00
|
|
|
it("has two compatible body IDs") do
|
|
|
|
expect(item.compatible_body_ids).to contain_exactly(11, 12)
|
|
|
|
end
|
|
|
|
it("predicts remaining Maraquan body IDs are compatible") do
|
|
|
|
expect(item.predicted_missing_body_ids).to contain_exactly(13, 4)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "an item with all Maraquan species modeled" do
|
|
|
|
subject(:item) { items(:straw_hat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 11)
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 12)
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 13)
|
|
|
|
item.swf_assets << build_item_asset(zones(:wings), body_id: 4)
|
|
|
|
end
|
|
|
|
|
2024-11-19 13:44:31 -08:00
|
|
|
it_behaves_like "a fully-modeled item"
|
2024-11-19 13:31:34 -08:00
|
|
|
it("is compatible with all Maraquan body IDs") do
|
|
|
|
expect(item.compatible_body_ids).to contain_exactly(11, 12, 13, 4)
|
|
|
|
end
|
|
|
|
end
|
2024-11-19 12:10:49 -08:00
|
|
|
end
|
|
|
|
end
|