Permalink
Browse files

some tests for gorm table namespace

  • Loading branch information...
1 parent 00c6c62 commit 07a23720a48b09a6e77d645d932dd6d66c1c5b2e @jeffbrown jeffbrown committed May 18, 2012
@@ -31,6 +31,9 @@ grails.gorm.default.constraints = {
beginsWithUpperCaseJ matches: /J.*/
}
+
+grails.gorm.table.prefix.enabled = true
+
// URL Mapping Cache Max Size, defaults to 5000
//grails.urlmapping.cache.maxsize = 1000
@@ -2,7 +2,19 @@ package namespace
class NamespaceInspectorController {
+ def dataSource
def containsBean(String beanName) {
render "Contains bean '${beanName}'? ${grailsApplication.mainContext.containsBean(beanName)}"
}
+
+ def showTableNames() {
+ def conn = dataSource.connection
+ def metaData = conn.metaData
+ def tableResultSet = metaData.getTables(null, null, '%', null)
+ def tableNames = []
+ while(tableResultSet.next()) {
+ tableNames << tableResultSet.getString('TABLE_NAME')
+ }
+ [tableNames: tableNames]
+ }
}
@@ -0,0 +1,8 @@
+package namespace
+
+class PhotoCollection {
+ String name
+ static mapping = {
+ autoImport false
+ }
+}
@@ -0,0 +1,14 @@
+<html>
+<head>
+<meta name="layout" content="main"/>
+<title>Table Names</title>
+</head>
+<body>
+<h2>Table Names</h2>
+<ul>
+<g:each var="tableName" in="${tableNames}">
+<li>${tableName}</li>
+</g:each>
+</ul>
+</body>
+</html>
@@ -0,0 +1,8 @@
+package com.namespaceone
+
+class PhotoCollection {
+ String name
+ static mapping = {
+ autoImport false
+ }
+}
@@ -0,0 +1,8 @@
+package com.namespaceone
+
+class ScrapBook {
+ String name
+ static mapping = {
+ table 'SCRAP_BOOK'
+ }
+}
@@ -0,0 +1,17 @@
+package com.namespaceone
+
+
+
+import grails.test.mixin.*
+import org.junit.*
+
+/**
+ * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
+ */
+@TestFor(PhotoCollection)
+class PhotoCollectionTests {
+
+ void testSomething() {
+ fail "Implement me"
+ }
+}
@@ -0,0 +1,8 @@
+package com.namespacetwo
+
+class PhotoCollection {
+ String name
+ static mapping = {
+ autoImport false
+ }
+}
@@ -0,0 +1,17 @@
+package com.namespacetwo
+
+
+
+import grails.test.mixin.*
+import org.junit.*
+
+/**
+ * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
+ */
+@TestFor(PhotoCollection)
+class PhotoCollectionTests {
+
+ void testSomething() {
+ fail "Implement me"
+ }
+}
@@ -0,0 +1,26 @@
+package grails.functional.tests.gorm
+
+import grails.functional.tests.BaseApplicationSpec
+import groovy.lang.MetaClass;
+
+class NamespacedDomainClassesSpec extends BaseApplicationSpec {
+
+ void 'Test table names'() {
+ when:
+ go 'namespaceInspector/showTableNames'
+
+ then:
+ statusCode == 200
+ title == 'Table Names'
+ $('li', text: 'PHOTO_COLLECTION')
+ $('li', text: 'NAMESPACE_ONE_PHOTO_COLLECTION')
+ $('li', text: 'NAMESPACE_TWO_PHOTO_COLLECTION')
+ $('li', text: 'SCRAP_BOOK')
+ !$('li', text: 'NAMESPACE_ONE_SCRAP_BOOK')
+ }
+
+ @Override
+ String getApplication() {
+ 'kitchen_sink_app'
+ }
+}

0 comments on commit 07a2372

Please sign in to comment.