From af5187edb69eddce2b31342bb23a444e0d6f4878 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 19 Nov 2024 13:44:31 -0800 Subject: [PATCH] Refactor item modeling spec, in anticipation of Item.is_modeled tests I'm grouping some shared behaviors to pull into the different cases, so that we can check the behaviors of a fully-modeled item vs a not-fully-modeled item in *all* of the relevant cases. Specifically, I'm planning to add `is:modeled` search filters, and creating pending placeholder tests for them! --- spec/models/item_spec.rb | 54 +++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index d0291d40..08d1f8bd 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -36,10 +36,33 @@ RSpec.describe Item do zones_restrict: "", zone:, body_id:) end + 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 + pending("appears in Item.is_modeled") do + expect(Item.is_modeled.find(item.id)).to be_present + end + pending("does not appear in Item.is_not_modeled") do + expect(Item.is_not_modeled.find(item.id)).to be_nil + end + end + + shared_examples "a not-fully-modeled item" do + it("is not fully modeled") { should_not be_predicted_fully_modeled } + pending("does not appear in Item.is_modeled") do + expect(Item.is_modeled.find(item.id)).to be_nil + end + pending("appears in in Item.is_not_modeled") do + expect(Item.is_not_modeled.find(item.id)).to be_present + end + end + describe "an item without any modeling data" do subject(:item) { items(:straw_hat) } - it("is not fully modeled") { should_not be_predicted_fully_modeled } + it_behaves_like "a not-fully-modeled item" it("has no compatible body IDs") do expect(item.compatible_body_ids).to be_empty end @@ -55,13 +78,10 @@ RSpec.describe Item do item.swf_assets << build_item_asset(zones(:wings), body_id: 1) end - it("is considered fully modeled") { should be_predicted_fully_modeled } + it_behaves_like "a fully-modeled item" it("has one compatible body ID") do expect(item.compatible_body_ids).to contain_exactly(1) end - it("predicts no more compatible bodies") do - expect(item.predicted_missing_body_ids).to be_empty - end end describe "an item with two species modeled" do @@ -75,7 +95,7 @@ RSpec.describe Item do item.update_cached_fields end - it("is not fully modeled") { should_not be_predicted_fully_modeled } + it_behaves_like "a not-fully-modeled item" it("has two compatible body IDs") do expect(item.compatible_body_ids).to contain_exactly(1, 2) end @@ -97,13 +117,10 @@ RSpec.describe Item do item.update_cached_fields end - it("is fully modeled") { should be_predicted_fully_modeled } + it_behaves_like "a fully-modeled item" it("is compatible with all standard body IDs") do expect(item.compatible_body_ids).to contain_exactly(1, 2, 3, 4) end - it("predicts no more compatible bodies") do - expect(item.predicted_missing_body_ids).to be_empty - end end describe "an item that fits all pets the same" do @@ -113,13 +130,10 @@ RSpec.describe Item do item.swf_assets << build_item_asset(zones(:background), body_id: 0) end - it("is fully modeled") { should be_predicted_fully_modeled } + it_behaves_like "a fully-modeled item" it("is compatible with all bodies (body ID = 0)") do expect(item.compatible_body_ids).to contain_exactly(0) end - it("predicts no more compatible bodies") do - expect(item.predicted_missing_body_ids).to be_empty - end end describe "an item with one Maraquan pet modeled" do @@ -129,13 +143,10 @@ RSpec.describe Item do item.swf_assets << build_item_asset(zones(:wings), body_id: 11) end - it("is considered fully modeled") { should be_predicted_fully_modeled } + it_behaves_like "a fully-modeled item" it("has one compatible body ID") do expect(item.compatible_body_ids).to contain_exactly(11) end - it("predicts no more compatible bodies") do - expect(item.predicted_missing_body_ids).to be_empty - end end describe "an item with two Maraquan pets modeled" do @@ -149,7 +160,7 @@ RSpec.describe Item do item.update_cached_fields end - it("is not fully modeled") { should_not be_predicted_fully_modeled } + it_behaves_like "a not-fully-modeled item" it("has two compatible body IDs") do expect(item.compatible_body_ids).to contain_exactly(11, 12) end @@ -171,13 +182,10 @@ RSpec.describe Item do item.update_cached_fields end - it("is fully modeled") { should be_predicted_fully_modeled } + it_behaves_like "a fully-modeled item" it("is compatible with all Maraquan body IDs") do expect(item.compatible_body_ids).to contain_exactly(11, 12, 13, 4) end - it("predicts no more compatible bodies") do - expect(item.predicted_missing_body_ids).to be_empty - end end end end