forked from multi-tenant/grails-multi-tenant-single-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScopedServicesSpec.groovy
63 lines (52 loc) · 2.01 KB
/
ScopedServicesSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package demo
import grails.plugin.spock.IntegrationSpec
import grails.plugin.multitenant.core.Tenant
/**
* Mostly as a smoke test to detect if any multi-tenant
* code affects regular domain classes.
* @author Kim A. Betti
*/
class ScopedServicesSpec extends IntegrationSpec {
def demoService
def anotherDemoService
def "tenant scope is working from config"() {
given: "each tenant set a val on service"
Tenant.withTenantId 1, {
assert "none" == demoService.touchedByTenant
demoService.touchedByTenant = "Tenant-1"
}
Tenant.withTenantId 2, {
assert "none" == demoService.touchedByTenant
demoService.touchedByTenant = "Tenant-2"
}
expect: "we should get values that were set"
Tenant.withTenantId 1, {
println demoService.touchedByTenant
"Tenant-1" == demoService.touchedByTenant
}
Tenant.withTenantId 2, {
println demoService.touchedByTenant
"Tenant-2" == demoService.touchedByTenant
}
}
def "tenant scope is working in service"() {
given: "each tenant set a val on service"
Tenant.withTenantId 1, {
assert "none" == anotherDemoService.touchedByTenant
anotherDemoService.touchedByTenant = "Tenant-1"
}
Tenant.withTenantId 2, {
assert "none" == anotherDemoService.touchedByTenant
anotherDemoService.touchedByTenant = "Tenant-2"
}
expect: "we should get values that were set"
Tenant.withTenantId 1, {
println anotherDemoService.touchedByTenant
"Tenant-1" == anotherDemoService.touchedByTenant
}
Tenant.withTenantId 2, {
println anotherDemoService.touchedByTenant
"Tenant-2" == anotherDemoService.touchedByTenant
}
}
}