From 2fc5beed38b7cace90c170a817e050e205ae5cdf Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Mon, 6 May 2024 22:02:17 +0900 Subject: [PATCH] Rename PersonAuto etc --> PersonAutosave --- spec/mongoid/association/auto_save_spec.rb | 38 +++++++++---------- .../{account_auto.rb => account_autosave.rb} | 4 +- .../models/{drug_auto.rb => drug_autosave.rb} | 4 +- .../{person_auto.rb => person_autosave.rb} | 10 ++--- 4 files changed, 28 insertions(+), 28 deletions(-) rename spec/support/models/{account_auto.rb => account_autosave.rb} (93%) rename spec/support/models/{drug_auto.rb => drug_autosave.rb} (55%) rename spec/support/models/{person_auto.rb => person_autosave.rb} (95%) diff --git a/spec/mongoid/association/auto_save_spec.rb b/spec/mongoid/association/auto_save_spec.rb index e5a0e972a..570dac3e2 100644 --- a/spec/mongoid/association/auto_save_spec.rb +++ b/spec/mongoid/association/auto_save_spec.rb @@ -9,16 +9,16 @@ describe '.auto_save' do before(:all) do - PersonAuto.has_many :drugs, class_name: 'DrugAuto', validate: false, autosave: true - PersonAuto.has_one :account, class_name: 'AccountAuto', validate: false, autosave: true + PersonAutosave.has_many :drugs, class_name: 'DrugAutosave', validate: false, autosave: true + PersonAutosave.has_one :account, class_name: 'AccountAutosave', validate: false, autosave: true end after(:all) do - PersonAuto.reset_callbacks(:save) + PersonAutosave.reset_callbacks(:save) end let(:person) do - PersonAuto.new + PersonAutosave.new end context 'when the option is not provided' do @@ -85,11 +85,11 @@ context 'when the relation has already had the autosave callback added' do before do - PersonAuto.has_many :drugs, class_name: 'DrugAuto', validate: false, autosave: true + PersonAutosave.has_many :drugs, class_name: 'DrugAutosave', validate: false, autosave: true end let(:drug) do - DrugAuto.new(name: 'Percocet') + DrugAutosave.new(name: 'Percocet') end it 'does not add the autosave callback twice' do @@ -102,7 +102,7 @@ context 'when the relation is a references many' do let(:drug) do - DrugAuto.new(name: 'Percocet') + DrugAutosave.new(name: 'Percocet') end context 'when saving a new parent document' do @@ -110,7 +110,7 @@ context 'when persistence options are not set on the parent' do before do - PersonAuto.has_many :drugs, class_name: 'DrugAuto', validate: false, autosave: true + PersonAutosave.has_many :drugs, class_name: 'DrugAutosave', validate: false, autosave: true end before do @@ -130,8 +130,8 @@ end after do - PersonAuto.with(database: other_database, &:delete_all) - DrugAuto.with(database: other_database, &:delete_all) + PersonAutosave.with(database: other_database, &:delete_all) + DrugAutosave.with(database: other_database, &:delete_all) end before do @@ -142,7 +142,7 @@ end it 'saves the relation with the persistence options' do - DrugAuto.with(database: other_database) do |drug_class| + DrugAutosave.with(database: other_database) do |drug_class| expect(drug_class.count).to eq(1) end end @@ -165,7 +165,7 @@ context 'when not updating the document' do let(:from_db) do - PersonAuto.find person.id + PersonAutosave.find person.id end before do @@ -183,7 +183,7 @@ context 'when the relation is a references one' do let(:account) do - AccountAuto.new(name: 'Testing') + AccountAutosave.new(name: 'Testing') end context 'when saving a new parent document' do @@ -237,7 +237,7 @@ context 'when not updating the document' do let(:from_db) do - PersonAuto.find person.id + PersonAutosave.find person.id end before do @@ -291,25 +291,25 @@ context 'when it has two relations with autosaves' do let!(:person) do - PersonAuto.create!(drugs: [percocet], account: account) + PersonAutosave.create!(drugs: [percocet], account: account) end let(:from_db) do - PersonAuto.find person.id + PersonAutosave.find person.id end let(:percocet) do - DrugAuto.new(name: 'Percocet') + DrugAutosave.new(name: 'Percocet') end let(:account) do - AccountAuto.new(name: 'Testing') + AccountAutosave.new(name: 'Testing') end context 'when updating one document' do let(:placebo) do - DrugAuto.new(name: 'Placebo') + DrugAutosave.new(name: 'Placebo') end before do diff --git a/spec/support/models/account_auto.rb b/spec/support/models/account_autosave.rb similarity index 93% rename from spec/support/models/account_auto.rb rename to spec/support/models/account_autosave.rb index 781b19663..d1c2873a6 100644 --- a/spec/support/models/account_auto.rb +++ b/spec/support/models/account_autosave.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AccountAuto +class AccountAutosave include Mongoid::Document field :_id, type: String, overwrite: true, default: -> { name.try(:parameterize) } @@ -15,7 +15,7 @@ class AccountAuto embeds_many :memberships belongs_to :creator, class_name: 'User' - belongs_to :person, class_name: 'PersonAuto' + belongs_to :person, class_name: 'PersonAutosave' has_many :alerts, autosave: false has_and_belongs_to_many :agents has_one :comment, validate: false diff --git a/spec/support/models/drug_auto.rb b/spec/support/models/drug_autosave.rb similarity index 55% rename from spec/support/models/drug_auto.rb rename to spec/support/models/drug_autosave.rb index 097dba216..5bf288ed6 100644 --- a/spec/support/models/drug_auto.rb +++ b/spec/support/models/drug_autosave.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -class DrugAuto +class DrugAutosave include Mongoid::Document field :name, type: String field :generic, type: Mongoid::Boolean - belongs_to :person, class_name: 'PersonAuto', inverse_of: nil, counter_cache: true + belongs_to :person, class_name: 'PersonAutosave', inverse_of: nil, counter_cache: true end diff --git a/spec/support/models/person_auto.rb b/spec/support/models/person_autosave.rb similarity index 95% rename from spec/support/models/person_auto.rb rename to spec/support/models/person_autosave.rb index 1136d4aac..e17306e96 100644 --- a/spec/support/models/person_auto.rb +++ b/spec/support/models/person_autosave.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class PersonAuto +class PersonAutosave include Mongoid::Document include Mongoid::Attributes::Dynamic attr_accessor :mode @@ -109,9 +109,9 @@ def extension has_and_belongs_to_many :houses, validate: false has_and_belongs_to_many :ordered_preferences, order: :value.desc, validate: false - has_many :drugs, class_name: 'DrugAuto', validate: false + has_many :drugs, class_name: 'DrugAutosave', validate: false # Must not have dependent: :destroy - has_one :account, class_name: 'AccountAuto', validate: false + has_one :account, class_name: 'AccountAutosave', validate: false has_one :cat, dependent: :nullify, validate: false, primary_key: :username has_one :book, autobuild: true, validate: false has_one :home, dependent: :delete_all, validate: false @@ -123,8 +123,8 @@ def extension dependent: :nullify, validate: false - belongs_to :mother, class_name: 'PersonAuto' - has_many :children, class_name: 'PersonAuto' + belongs_to :mother, class_name: 'PersonAutosave' + has_many :children, class_name: 'PersonAutosave' accepts_nested_attributes_for :addresses accepts_nested_attributes_for :name, update_only: true