Beispiel #1
0
    def test_global_scope_remove_from_class(self):
        builder = (self.get_builder().set_global_scope(
            SoftDeleteScope()).remove_global_scope(SoftDeleteScope()))

        self.assertEqual(
            builder.where("id", 1).to_sql(),
            "SELECT * FROM `users` WHERE `users`.`id` = '1'",
        )
Beispiel #2
0
    def test_global_scope_from_class(self):
        builder = self.get_builder().set_global_scope(SoftDeleteScope())

        self.assertEqual(
            builder.where("id", 1).to_sql(),
            "SELECT * FROM `users` WHERE `users`.`id` = '1' AND `users`.`deleted_at` IS NULL",
        )
Beispiel #3
0
    def test_global_scope_adds_method(self):
        builder = self.get_builder().set_global_scope(SoftDeleteScope())

        self.assertEqual(builder.with_trashed().to_sql(),
                         "SELECT * FROM `users`")
Beispiel #4
0
 def test_only_trashed(self):
     sql = "SELECT * FROM `users` WHERE `users`.`deleted_at` IS NOT NULL"
     builder = self.get_builder().set_global_scope(SoftDeleteScope())
     self.assertEqual(sql, builder.only_trashed().to_sql())
Beispiel #5
0
 def test_that_trashed_users_are_not_returned_by_default(self):
     sql = "SELECT * FROM `users` WHERE `users`.`deleted_at` IS NULL"
     builder = self.get_builder().set_global_scope(SoftDeleteScope())
     self.assertEqual(sql, builder.to_sql())
Beispiel #6
0
 def test_force_delete_with_wheres(self):
     sql = "DELETE FROM `user_softs` WHERE `user_softs`.`active` = '1'"
     builder = self.get_builder().set_global_scope(SoftDeleteScope())
     self.assertEqual(sql,
                      UserSoft.where("active", 1).force_delete().to_sql())
Beispiel #7
0
 def test_restore(self):
     sql = "UPDATE `users` SET `users`.`deleted_at` = 'None'"
     builder = self.get_builder().set_global_scope(SoftDeleteScope())
     self.assertEqual(sql, builder.restore().to_sql())
Beispiel #8
0
 def test_force_delete(self):
     sql = "DELETE FROM `users`"
     builder = self.get_builder().set_global_scope(SoftDeleteScope())
     self.assertEqual(sql, builder.force_delete().to_sql())
Beispiel #9
0
 def test_with_trashed(self):
     sql = "SELECT * FROM `users`"
     builder = self.get_builder().set_global_scope(SoftDeleteScope())
     self.assertEqual(sql, builder.with_trashed().to_sql())