Skip to content

Commit

Permalink
moved find scope tests in with other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
circulon committed Sep 11, 2024
1 parent 10e6478 commit 43a80e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
25 changes: 0 additions & 25 deletions tests/mysql/model/test_model_scopes.py

This file was deleted.

27 changes: 20 additions & 7 deletions tests/mysql/scopes/test_soft_delete.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import inspect
import unittest

import pendulum

from tests.integrations.config.database import DATABASES
from src.masoniteorm.models import Model
from src.masoniteorm.query import QueryBuilder
from src.masoniteorm.query.grammars import MySQLGrammar
from src.masoniteorm.scopes import SoftDeleteScope
from tests.utils import MockConnectionFactory

from src.masoniteorm.models import Model
from src.masoniteorm.scopes import SoftDeletesMixin
from tests.User import User


class UserSoft(Model, SoftDeletesMixin):
__dry__ = True

__table__ = "users"

class UserSoftArchived(Model, SoftDeletesMixin):
__dry__ = True

__deleted_at__ = "archived_at"
__table__ = "users"

Expand Down Expand Up @@ -52,7 +50,7 @@ def test_restore(self):
self.assertEqual(sql, builder.restore().to_sql())

def test_force_delete_with_wheres(self):
sql = "DELETE FROM `user_softs` WHERE `user_softs`.`active` = '1'"
sql = "DELETE FROM `users` WHERE `users`.`active` = '1'"
builder = self.get_builder().set_global_scope(SoftDeleteScope())
self.assertEqual(
sql, UserSoft.where("active", 1).force_delete(query=True).to_sql()
Expand All @@ -69,9 +67,24 @@ def test_only_trashed(self):
self.assertEqual(sql, builder.only_trashed().to_sql())

def test_only_trashed_on_model(self):
sql = "SELECT * FROM `user_softs` WHERE `user_softs`.`deleted_at` IS NOT NULL"
sql = "SELECT * FROM `users` WHERE `users`.`deleted_at` IS NOT NULL"
self.assertEqual(sql, UserSoft.only_trashed().to_sql())

def test_can_change_column(self):
sql = "SELECT * FROM `users` WHERE `users`.`archived_at` IS NOT NULL"
self.assertEqual(sql, UserSoftArchived.only_trashed().to_sql())

def test_find_with_global_scope(self):
find_sql = UserSoft.find("1", query=True).to_sql()
raw_sql = """SELECT * FROM `users` WHERE `users`.`id` = '1' AND `users`.`deleted_at` IS NULL"""
self.assertEqual(find_sql, raw_sql)

def test_find_with_trashed_scope(self):
find_sql = UserSoft.with_trashed().find("1", query=True).to_sql()
raw_sql = """SELECT * FROM `users` WHERE `users`.`id` = '1'"""
self.assertEqual(find_sql, raw_sql)

def test_find_with_only_trashed_scope(self):
find_sql = UserSoft.only_trashed().find("1", query=True).to_sql()
raw_sql = """SELECT * FROM `users` WHERE `users`.`deleted_at` IS NOT NULL AND `users`.`id` = '1'"""
self.assertEqual(find_sql, raw_sql)

0 comments on commit 43a80e5

Please sign in to comment.