@@ -671,28 +671,31 @@ void tst_SoftDeletes::restore_NotTrashed_OnModel() const
671671 QCOMPARE (user->getAttribute (DELETED_AT).value <QDateTime>(), QDateTime ());
672672 }
673673
674- // Restore
674+ // Restore NOT TRASHED (need to test also this scenario 🤯)
675675 {
676676 auto user = User::withTrashed ()->find (5 );
677677
678678 QVERIFY (user);
679679 QVERIFY (user->exists );
680680 QVERIFY (!user->trashed ());
681681
682- auto timeBeforeRestore = QDateTime::currentDateTimeUtc ();
683- // Reset milliseconds to 0
684- {
685- auto time = timeBeforeRestore.time ();
686- timeBeforeRestore.setTime (QTime (time.hour (), time.minute (), time.second ()));
687- }
682+ /* This is different than others, an updated_at column value must be the same
683+ after the restore() operation because model is NOT dirty (nothing changed),
684+ so nothing will be updated/saved.
685+ It also behaves differently than the TinyBuilder/BuildsSoftDeletes::restore(),
686+ this BuildsSoftDeletes's method will call the SQL UPDATE query even if
687+ the records aren't trashed because of course, the TinyBuilder doesn't track
688+ dirty attributes.
689+ I think this was the reason for occasional failure of this test (5% rate). */
690+ auto timeBeforeRestore = user->getAttribute (UPDATED_AT).value <QDateTime>();
688691
689692 // Restore
690693 QVERIFY (user->restore ());
691694
692695 QVERIFY (user->exists );
693696 QVERIFY (!user->trashed ());
694- QVERIFY (user-> getAttribute (UPDATED_AT). value <QDateTime>() >=
695- timeBeforeRestore);
697+ // They must be EQUAL because NO update was performed
698+ QVERIFY (user-> getAttribute (UPDATED_AT). value <QDateTime>() == timeBeforeRestore);
696699 QCOMPARE (user->getAttribute (DELETED_AT).value <QDateTime>(), QDateTime ());
697700 }
698701
@@ -729,6 +732,9 @@ void tst_SoftDeletes::restore_NotTrashed_OnModel() const
729732
730733void tst_SoftDeletes::restore_NotTrashed_OnTinyBuilder () const
731734{
735+ /* Below, the restore will update the deleted_at column even if the record isn't
736+ trashed, the TinyBuilder doesn't track dirty attributes as a model does. */
737+
732738 // Prepare (restore)
733739 {
734740 auto timeBeforeRestore = QDateTime::currentDateTimeUtc ();
0 commit comments