From 1e690d9f6c7f660007cd89700486002cc4a28d2f Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 12 Oct 2023 18:05:01 -0700 Subject: [PATCH] Fix old find_or_initialize_by methods I missed this in the Rails upgrades, oops! --- app/models/neopets_user.rb | 2 +- app/models/pet.rb | 10 +++++----- app/models/pet_state.rb | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/neopets_user.rb b/app/models/neopets_user.rb index 72649baf..56b6c066 100644 --- a/app/models/neopets_user.rb +++ b/app/models/neopets_user.rb @@ -50,7 +50,7 @@ class NeopetsUser pets_data = envelope.messages[0].data.body raise NotFound if pets_data == false - pets = pets_data.map { |pet| Pet.find_or_initialize_by_name(pet['name']) } + pets = pets_data.map { |pet| Pet.find_or_initialize_by(name: pet['name']) } items = pets.each(&:load!).map(&:items).flatten item_ids = items.map(&:id) item_quantities = {} diff --git a/app/models/pet.rb b/app/models/pet.rb index 1c1df6f8..16e682a6 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -31,9 +31,9 @@ class Pet < ApplicationRecord pet_data = viewer_data[:custom_pet] - self.pet_type = PetType.find_or_initialize_by_species_id_and_color_id( - pet_data[:species_id].to_i, - pet_data[:color_id].to_i + self.pet_type = PetType.find_or_initialize_by( + species_id: pet_data[:species_id].to_i, + color_id: pet_data[:color_id].to_i ) self.pet_type.body_id = pet_data[:body_id] self.pet_type.origin_pet = self @@ -166,13 +166,13 @@ class Pet < ApplicationRecord end def self.load(name, options={}) - pet = Pet.find_or_initialize_by_name(name) + pet = Pet.find_or_initialize_by(name: name) pet.load!(options) pet end def self.from_viewer_data(viewer_data, options={}) - pet = Pet.find_or_initialize_by_name(viewer_data[:custom_pet][:name]) + pet = Pet.find_or_initialize_by(name: viewer_data[:custom_pet][:name]) pet.use_viewer_data(viewer_data, options) pet end diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb index 867de11e..22913aff 100644 --- a/app/models/pet_state.rb +++ b/app/models/pet_state.rb @@ -162,10 +162,10 @@ class PetState < ApplicationRecord if pet_type.new_record? pet_state = self.new :swf_asset_ids => swf_asset_ids_str else - pet_state = self.find_or_initialize_by_pet_type_id_and_swf_asset_ids( - pet_type.id, - swf_asset_ids_str - ) + pet_state = self.find_or_initialize_by( + pet_type_id: pet_type.id, + swf_asset_ids: swf_asset_ids_str + ) end existing_swf_assets = SwfAsset.biology_assets.includes(:zone). find_all_by_remote_id(swf_asset_ids)