From 28bd6ecca4fb527b362de5b018d6119959c336f8 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 25 Oct 2024 13:47:23 -0700 Subject: [PATCH] Test that modeling items twice doesn't affect them or their assets --- spec/models/pet_spec.rb | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/spec/models/pet_spec.rb b/spec/models/pet_spec.rb index 92f5eaa5..cbe392e5 100644 --- a/spec/models/pet_spec.rb +++ b/spec/models/pet_spec.rb @@ -109,6 +109,16 @@ RSpec.describe Pet, type: :model do expect { new_pet.save! }.not_to change { pet_state.attributes } end end + + describe "its biology assets" do + subject(:biology_assets) { new_pet.pet_state.swf_assets } + + they("already exist") { should all be_persisted } + they("are the same as before") { should eq pet.pet_state.swf_assets } + they("are not changed when saving the pet") do + expect { new_pet.save! }.not_to change { biology_assets.map(&:attributes) } + end + end end end @@ -246,6 +256,61 @@ RSpec.describe Pet, type: :model do ) end end + + context "when modeled a second time" do + before { pet.save! } + subject!(:new_pet) { Pet.load("matts_bat") } + + describe "its pet type" do + subject(:pet_type) { new_pet.pet_type } + + it("already exists") { should be_persisted } + it("is the same as before") { should eq pet.pet_type } + it "is not changed when saving the pet" do + expect { new_pet.save! }.not_to change { pet_type.attributes } + end + end + + describe "its pet state" do + subject(:pet_state) { new_pet.pet_state } + + it("already exists") { should be_persisted } + it("is the same as before") { should eq pet.pet_state } + it "is not changed when saving the pet" do + expect { new_pet.save! }.not_to change { pet_state.attributes } + end + end + + describe "its biology assets" do + subject(:biology_assets) { new_pet.pet_state.swf_assets } + + they("already exist") { should all be_persisted } + they("are the same as before") { should eq pet.pet_state.swf_assets } + they("are not changed when saving the pet") do + expect { new_pet.save! }.not_to change { biology_assets.map(&:attributes) } + end + end + + describe "its items" do + subject(:items) { new_pet.items } + + they("already exist") { should all be_persisted } + they("are the same as before") { should eq pet.items } + they("are not changed when saving the pet") do + expect { new_pet.save! }.not_to change { items.map(&:attributes) } + end + end + + describe "its item assets" do + subject(:item_assets) { new_pet.items.map(&:swf_assets).flatten(1) } + + they("already exist") { should all be_persisted } + they("are the same as before") { should eq pet.items.map(&:swf_assets).flatten(1) } + they("are not changed when saving the pet") do + expect { new_pet.save! }.not_to change { item_assets.map(&:attributes) } + end + end + end end end end