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
Validation Errors and Rollback | |
A common use case is to rollback a transaction if there are validation errors. For example consider this service: | |
import grails.validation.ValidationException | |
class AuthorService { | |
void updateAge(id, int age) { | |
def author = Author.get(id) | |
author.age = age | |
if (!author.validate()) { |
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
// Setup | |
private mockTagLibRender() { | |
tagLib.metaClass.render = { Map attrs -> | |
render = attrs | |
} | |
} | |
// Utilization | |
given: | |
mockTagLibRender() |
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
/** | |
* This script restarts a remote tomcat instance | |
* Usage: groovy restartRemoteTomcat.groovy or groovy restartRemoteTomcat.groovy remoteServer remoteUser pathToTomcatBinDirectory | |
* Example: groovy restartRemoteTomcat myServer username "/home/username/apache-tomcat-7.0.39/bin/" | |
*/ | |
@Grapes([ | |
@Grab('org.apache.ant:ant:1.8.3'), | |
@Grab(group = 'ant', module = 'ant-jsch', version = '1.6.5'), | |
@Grab(group = 'com.jcraft', module = 'jsch', version = '0.1.48'), |
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
service.metaClass.runAsync = { it() } | |
// The first line basically says ‘take the code within the runAsync closure, and just execute it’. | |
// http://fbflex.wordpress.com/2011/10/26/grails-quick-tip-testing-spock-interactions-wrapped-by-the-executor-plugin/ |
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
TwitterReaderService twitterReaderServiceMock = Mock(TwitterReaderService) | |
def setup() { | |
controller.twitterReaderService = twitterReaderServiceMock | |
} |
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
def mimeType = grailsMimeUtility.getMimeTypeForExtension(extension) | |
println mimeType.name |
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
def errorMessages = ex.errors.collect { g.message(error:it) } |
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
git push -u origin your_branch |
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
// A form with associated inputs | |
<g:form action="seed"> | |
<g:each in="${teams}" status="i" var="team"> | |
<input type="hidden" name="teams.${i}.id" value="${team.id}"> | |
<input type="text" size="2" name="teams.${i}.seed" value="${team.seed}"> | |
</g:each> |
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
def countRows = db.firstRow("select count(*) as numberOfRows from languages") | |
assert 4 == countRows.numberOfRows |
NewerOlder