I have created a simple Rspec test to verfiy if a model created has been deleted. However, the test fails because the model still exists. Can anyone provide any assistance on how to determine if the record was actually deleted?
RSpec.describe Person, type: :model do
let(:person) {
Person.create(
name: "Adam",
serial_number: "1"
)
}
it "destroys associated relationships when person destroyed" do
person.destroy
expect(person).to be_empty()
end
end
There is no way to retrieve the deleted records in CRM. If the auditing is enabled you can retrieve the audit history and create the records back. Unfortunately options to restore specific records are not available yet, you would need to restore a backup point to get the records again .
The quickest and easiest way to find out if your record has been expunged is to visit the court where your case was held and ask to see the records. You know that your record is clean if the court does not have your records or if it approves your request. The question is, who else has the documents?
A shared user is not able to delete any recordings or videos. If you are sharing account access at an owner level, there is no way to see the activity of these other devices. You can, however, control mobile device access through the Control Center in the Ring app.
As Giselle mentioned there isn't a way to retrieve the deleted records and you would have to restore a backup to do that. The reply is solely my personal opinion.
You have two choices. You can test that
a record was removed from the database
it "removes a record from the database" do
expect { person.destroy }.to change { Person.count }.by(-1)
end
but that doesn't tell you which record was removed.
Or that the exact record does not exist in the database anymore
it "removes the record from the database" do
person.destroy
expect { person.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
or
it "removes the record from the database" do
person.destroy
expect(Person.exists?(person.id)).to be false
end
But that does not make sure that the record existed before.
A combination of both could be:
it "removes a record from the database" do
expect { person.destroy }.to change { Person.count }.by(-1)
expect { person.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
When you delete a record from a database, an object still persists in memory. That's why expect(person).to be_empty()
fails.
RSpec has the change
matcher. ActiveRecord has the persisted?
method. It returns false if a record is not persisted in a database.
it "destroys associated relationships when rtu destroyed" do
expect { person.destroy }.to change(Person, :count).by(-1)
expect(person.persisted?).to be_falsey
end
destroy
is a method of a framework. As far as I know, you don't need to test its methods.
I think the following is a nice way to test a specific record has been removed with one expectation, while ensuring your testing the result of the action and not just the state of your test subject.
it "removes the record from the database" do
expect { person.destroy }.to change { Person.exists?(person.id) }.to(false)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With