You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by jd...@apache.org on 2026/04/08 04:36:21 UTC

(grails-core) 01/03: GRAILS-11661 - fix unit test metaclass cleanup issue

This is an automated email from the ASF dual-hosted git repository.

jdaugherty pushed a commit to branch GRAILS-11661
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 264eb6e9d65502a6d3387f17eac8fb272387e129
Author: Jeff Scott Brown <jb...@pivotal.io>
AuthorDate: Thu Aug 14 23:03:30 2014 -0500

    GRAILS-11661 - fix unit test metaclass cleanup issue
    
    This is related to the change made at https://github.com/grails/grails-core/commit/1885351d2be8f74076f2c83edcbc048c5bcfd9d7.  The change in this commit changes the runtime to fire a resetGrailsApplication event in addition to the after event.  I am not yet sure if this is the correct thing to do.  Pending investigation.
---
 .../test/runtime/TestRuntimeJunitAdapter.groovy    |  1 +
 .../mixin/DomainClassMetaClassCleanupSpec.groovy   | 34 ++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/grails-plugin-testing/src/main/groovy/grails/test/runtime/TestRuntimeJunitAdapter.groovy b/grails-plugin-testing/src/main/groovy/grails/test/runtime/TestRuntimeJunitAdapter.groovy
index 9246c4a449..77796f8f35 100644
--- a/grails-plugin-testing/src/main/groovy/grails/test/runtime/TestRuntimeJunitAdapter.groovy
+++ b/grails-plugin-testing/src/main/groovy/grails/test/runtime/TestRuntimeJunitAdapter.groovy
@@ -110,6 +110,7 @@ class TestRuntimeJunitAdapter {
     }
 
     protected void after(TestRuntime runtime, Object testInstance, Description description, Throwable throwable) {
+        runtime.publishEvent("resetGrailsApplication", [testInstance: testInstance, description: description, throwable: throwable], [immediateDelivery: true, reverseOrderDelivery: true])
         runtime.publishEvent("after", [testInstance: testInstance, description: description, throwable: throwable], [immediateDelivery: true, reverseOrderDelivery: true])
     }
 
diff --git a/grails-test-suite-uber/src/test/groovy/grails/test/mixin/DomainClassMetaClassCleanupSpec.groovy b/grails-test-suite-uber/src/test/groovy/grails/test/mixin/DomainClassMetaClassCleanupSpec.groovy
new file mode 100644
index 0000000000..c3483be67a
--- /dev/null
+++ b/grails-test-suite-uber/src/test/groovy/grails/test/mixin/DomainClassMetaClassCleanupSpec.groovy
@@ -0,0 +1,34 @@
+package grails.test.mixin
+
+import grails.persistence.Entity
+import spock.lang.Issue
+import spock.lang.Specification
+
+@TestFor(SomeDomainClass)
+class DomainClassMetaClassCleanupSpec extends Specification {
+
+    @Issue('GRAILS-11661')
+    void 'test adding one method'() {
+        when:
+        SomeDomainClass.metaClass.static.one = {}
+        
+        then:
+        SomeDomainClass.metaClass.hasMetaMethod('one')
+        !SomeDomainClass.metaClass.hasMetaMethod('two')
+    }
+
+    @Issue('GRAILS-11661')
+    void 'test adding another method'() {
+        when:
+        SomeDomainClass.metaClass.static.two = {}
+        
+        then:
+        !SomeDomainClass.metaClass.hasMetaMethod('one')
+        SomeDomainClass.metaClass.hasMetaMethod('two')
+    }
+}
+
+@Entity
+class SomeDomainClass {
+    
+}