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

jamesfredley pushed a commit to branch add-missing-directories
in repository https://gitbox.apache.org/repos/asf/grails-forge.git

commit 082945275cd0d6a4e98e9b3aad1ea461b055a820
Author: James Fredley <[email protected]>
AuthorDate: Fri May 23 11:58:35 2025 -0400

    Add grails-app/migrations directory to database-migration feature and add 
test coverage for feature
---
 .../feature/migration/DatabaseMigrationPlugin.java |  4 ++
 .../migration/DatabaseMigrationPluginSpec.groovy   | 74 ++++++++++++++++++++++
 2 files changed, 78 insertions(+)

diff --git 
a/grails-forge-core/src/main/java/org/grails/forge/feature/migration/DatabaseMigrationPlugin.java
 
b/grails-forge-core/src/main/java/org/grails/forge/feature/migration/DatabaseMigrationPlugin.java
index ab867fd..a6df51c 100644
--- 
a/grails-forge-core/src/main/java/org/grails/forge/feature/migration/DatabaseMigrationPlugin.java
+++ 
b/grails-forge-core/src/main/java/org/grails/forge/feature/migration/DatabaseMigrationPlugin.java
@@ -20,6 +20,7 @@ import 
org.grails.forge.application.generator.GeneratorContext;
 import org.grails.forge.build.dependencies.Dependency;
 import org.grails.forge.feature.migration.templates.dbMigrationGradle;
 import org.grails.forge.template.RockerWritable;
+import org.grails.forge.template.URLTemplate;
 
 @Singleton
 public class DatabaseMigrationPlugin implements MigrationFeature {
@@ -60,6 +61,9 @@ public class DatabaseMigrationPlugin implements 
MigrationFeature {
                 .groupId("org.apache.grails")
                 .artifactId("grails-data-hibernate5-dbmigration")
                 .implementation());
+
+        final ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
+        generatorContext.addTemplate(srcDirPath, new URLTemplate(srcDirPath + 
"/.gitkeep", classLoader.getResource(".gitkeep")));
     }
 
     private String getSrcDirPath() {
diff --git 
a/grails-forge-core/src/test/groovy/org/grails/forge/feature/migration/DatabaseMigrationPluginSpec.groovy
 
b/grails-forge-core/src/test/groovy/org/grails/forge/feature/migration/DatabaseMigrationPluginSpec.groovy
new file mode 100644
index 0000000..cfb8dfe
--- /dev/null
+++ 
b/grails-forge-core/src/test/groovy/org/grails/forge/feature/migration/DatabaseMigrationPluginSpec.groovy
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.grails.forge.feature.migration
+
+import org.grails.forge.ApplicationContextSpec
+import org.grails.forge.BuildBuilder
+import org.grails.forge.application.ApplicationType
+import org.grails.forge.fixture.CommandOutputFixture
+import org.grails.forge.options.Options
+import org.grails.forge.options.TestFramework
+import spock.lang.Unroll
+
+class DatabaseMigrationPluginSpec extends ApplicationContextSpec implements 
CommandOutputFixture{
+
+    void "test dependencies are present for gradle"() {
+        when:
+        final String template = new BuildBuilder(beanContext)
+                .features(["database-migration"])
+                .render()
+
+        then:
+        template.contains('classpath 
"org.apache.grails:grails-data-hibernate5-dbmigration"')
+        template.contains('implementation 
"org.apache.grails:grails-data-hibernate5-dbmigration"')
+    }
+
+    void "test dependencies are present for buildSrc"() {
+        when:
+        final String template = new BuildBuilder(beanContext)
+                .features(["database-migration"])
+                .renderBuildSrc()
+
+        then:
+        template.contains('implementation 
"org.apache.grails:grails-data-hibernate5-dbmigration"')
+    }
+
+    void "test dependencies are present for buildscript "() {
+        given:
+        final def output = generate(ApplicationType.WEB, new 
Options(TestFramework.SPOCK), ['database-migration'])
+        final def buildGradle = output["build.gradle"]
+
+        expect:
+        buildGradle != null
+        buildGradle.contains('classpath 
"org.apache.grails:grails-data-hibernate5-dbmigration"')
+    }
+
+    @Unroll
+    void "test migrations directory is present"() {
+        when:
+        final def output = generate(applicationType, new 
Options(TestFramework.SPOCK), ['database-migration'])
+
+        then:
+        output.containsKey("grails-app/migrations/.gitkeep")
+
+        where:
+        applicationType << ApplicationType.values()
+    }
+}

Reply via email to