forked from multi-tenant/grails-multi-tenant-single-db
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup and fix tests. merge into all spock tests
- Loading branch information
Showing
3 changed files
with
63 additions
and
68 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} | ||
|
||
|
||
|
||
} |