jdaugherty commented on code in PR #16511:
URL: https://github.com/apache/grails-core/pull/16511#discussion_r4178420520


##########
grails-datamapping-core/src/test/groovy/org/grails/datastore/gorm/multitenancy/MultiTenantEventListenerSpec.groovy:
##########
@@ -249,20 +249,42 @@ class MultiTenantEventListenerSpec extends Specification {
         eventType << [ValidationEvent, PreInsertEvent, PreUpdateEvent]
     }
 
-    void "onApplicationEvent PreInsertEvent prefers an already-set entity 
property over the resolved tenant id"() {
+    @Unroll
+    void "onApplicationEvent #eventType.simpleName replaces a tenant id 
already set on the entity with the current tenant id"() {

Review Comment:
   Fixed in ef29ca6787: the class Javadoc now says that a tenant id already set 
on the entity is kept only when the current id is `ConnectionSource.DEFAULT`.



##########
grails-datamapping-core-test/src/test/groovy/grails/gorm/services/multitenancy/partitioned/PartitionMultiTenancySpec.groovy:
##########
@@ -72,6 +72,32 @@ class PartitionMultiTenancySpec extends Specification {
         System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, '')
     }
 
+    void 'an instance whose tenant id names another tenant is saved under the 
current tenant'() {
+        given: 'a current tenant'
+        System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, '910')
+
+        when: 'a book with the tenant id of another tenant is saved'
+        Book book = Book.withTransaction { new Book(title: 'Inserted', 
tenantId: 911).save(flush: true) }
+
+        then: 'it gets the current tenant, and only the current tenant sees it'
+        book.tenantId == 910
+        Book.withTransaction { Book.countByTitle('Inserted') } == 1
+        Book.withTenant('911') { Book.withTransaction { 
Book.countByTitle('Inserted') } } == 0
+
+        when: 'its tenant id is changed to another tenant and it is saved 
again'
+        Book updated = Book.withTransaction {
+            Book loaded = Book.get(book.id)
+            loaded.tenantId = 911
+            loaded.save(flush: true)
+        }
+
+        then: 'it keeps the current tenant'
+        updated.tenantId == 910

Review Comment:
   Fixed in ef29ca6787: the update half now also checks that the book is 
counted for tenant 910 and not for 911.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to