Skip to content

Commit

Permalink
Merge pull request #120 from tablecheck/rename-models
Browse files Browse the repository at this point in the history
Rename PersonAuto etc --> PersonAutosave
  • Loading branch information
johnnyshields authored May 6, 2024
2 parents 69493c2 + 2fc5bee commit 5b4975b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
38 changes: 19 additions & 19 deletions spec/mongoid/association/auto_save_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -102,15 +102,15 @@
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

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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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) }
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class PersonAuto
class PersonAutosave
include Mongoid::Document
include Mongoid::Attributes::Dynamic
attr_accessor :mode
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5b4975b

Please sign in to comment.