You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Send null instead of ZERO_PARAMETER, otherwise the closure will be created with `it`.
* Fix withoutTenant closure handling, if closure is call with 0 arguments then `callable.call()`.
Copy file name to clipboardExpand all lines: grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/multitenancy/transform/TenantTransform.groovy
Copy file name to clipboardExpand all lines: grails-datastore-gorm/src/test/groovy/grails/gorm/annotation/multitenancy/CurrentTenantTransformSpec.groovy
+97-2Lines changed: 97 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,5 @@
1
1
packagegrails.gorm.annotation.multitenancy
2
2
3
-
importgrails.gorm.multitenancy.TenantService
4
-
importorg.grails.datastore.mapping.core.Datastore
5
3
importspock.lang.Specification
6
4
7
5
/**
@@ -21,6 +19,103 @@ class BookService {
21
19
}
22
20
new BookService()
23
21
22
+
''')
23
+
when:"the list books method is invoked"
24
+
def result = bookService.listBooks()
25
+
26
+
then:"An exception was thrown because GORM is not setup"
27
+
thrown(IllegalStateException)
28
+
29
+
}
30
+
31
+
void"test @CurrentTenant transforms a service class and makes a method in current tenant handling"() {
32
+
given:"A service with @CurrentTenant applied as the class level"
33
+
def bookService =newGroovyShell().evaluate('''
34
+
import grails.gorm.multitenancy.CurrentTenant
35
+
36
+
@CurrentTenant
37
+
class BookService {
38
+
39
+
List listBooks() {
40
+
return ["The Stand"]
41
+
}
42
+
}
43
+
new BookService()
44
+
45
+
''')
46
+
when:"the list books method is invoked"
47
+
def result = bookService.listBooks()
48
+
49
+
then:"An exception was thrown because GORM is not setup"
50
+
thrown(IllegalStateException)
51
+
52
+
}
53
+
54
+
void"test @CurrentTenant transforms a service class and a method marked with @WithoutTenant in no tenant handling"() {
55
+
given:"A service with @CurrentTenant applied as the class level"
56
+
def bookService =newGroovyShell().evaluate('''
57
+
import grails.gorm.multitenancy.CurrentTenant
58
+
import grails.gorm.multitenancy.WithoutTenant
59
+
60
+
@CurrentTenant
61
+
class BookService {
62
+
63
+
@WithoutTenant
64
+
List listBooks() {
65
+
return ["The Stand"]
66
+
}
67
+
}
68
+
new BookService()
69
+
70
+
''')
71
+
when:"the list books method is invoked"
72
+
def result = bookService.listBooks()
73
+
74
+
then:"An exception was thrown because GORM is not setup"
75
+
thrown(IllegalStateException)
76
+
77
+
}
78
+
79
+
void"test @WithoutTenant transforms a service class and makes a method that is wrapped in without tenant handling"() {
80
+
given:"A service with @CurrentTenant applied as the class level"
81
+
def bookService =newGroovyShell().evaluate('''
82
+
import grails.gorm.multitenancy.CurrentTenant
83
+
import grails.gorm.multitenancy.WithoutTenant
84
+
85
+
@WithoutTenant
86
+
class BookService {
87
+
88
+
List listBooks() {
89
+
return ["The Stand"]
90
+
}
91
+
}
92
+
new BookService()
93
+
94
+
''')
95
+
when:"the list books method is invoked"
96
+
def result = bookService.listBooks()
97
+
98
+
then:"An exception was thrown because GORM is not setup"
99
+
thrown(IllegalStateException)
100
+
101
+
}
102
+
103
+
void"test @WithoutTenant transforms a service class and a method marked with @CurrentTenant in current tenant handling"() {
104
+
given:"A service with @CurrentTenant applied as the class level"
0 commit comments