Skip to content

Instantly share code, notes, and snippets.

View robfletcher's full-sized avatar

Rob Fletcher robfletcher

View GitHub Profile
import groovy.transform.*
import org.junit.*
import org.openqa.selenium.*
import org.openqa.selenium.support.ui.*
import org.openqa.selenium.firefox.*
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
class AutocompleteTests {
class GreetingController {
def index = {
[message: message(code: "greeting.message", args: [params.name])]
}
}
@robfletcher
robfletcher / chgrails.sh
Created November 23, 2010 15:11
bash script to change current Grails symlink
#! /bin/sh
VERSION=$1
GRAILS_DIR=/opt/grails-$VERSION
GRAILS_SYMLINK=/opt/grails
if [[ ! -d $GRAILS_DIR ]]; then
echo "Error: $GRAILS_DIR does not exist"
exit 1
fi
if [[ -e $GRAILS_SYMLINK ]]; then
@robfletcher
robfletcher / layout.html
Created March 3, 2011 19:13
A really simple boilerplate for a common page layout where the content sits in a central column with header and nav above and footer below. The column is always at least as high as the browser viewport.
<!doctype html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Centered column with fixed footer</title>
<meta name="author" content="Rob Fletcher">
@robfletcher
robfletcher / DatabaseSchemaSpec.groovy
Created August 18, 2011 16:27
Example of data-driving a Spock specification using database metadata
import grails.plugin.spock.IntegrationSpec
import java.sql.Connection
import javax.sql.DataSource
import spock.lang.*
class DatabaseSchemaSpec extends IntegrationSpec {
@Shared def dataSource
@Shared List<String> tableNames
@robfletcher
robfletcher / gist:1486156
Created December 16, 2011 14:06
Geb module methods demonstrating how to wait for jQuery animation to complete
void next() {
nextButton.click()
waitForAnimationComplete()
}
private void waitForAnimationComplete() {
waitFor {
js.exec(this.firstElement(), "return \$(arguments[0]).find(':animated').length == 0")
}
}
@robfletcher
robfletcher / VertxHandler.groovy
Created May 10, 2012 00:16
A Spock extension for automatically registering and unregistering handlers on the Vert.x event bus
package co.freeside.spock.vertx
import org.spockframework.runtime.extension.ExtensionAnnotation
import java.lang.annotation.*
/**
* Add this annotation to any specification fields that should be registered as Vert.x event bus handlers during test
* execution. The field will be registered on the event bus before each feature method and unregistered afterwards. If
* the field is `@Shared` it will be registered and unregistered at the start and end of the spec.
*
@robfletcher
robfletcher / build.gradle
Created May 16, 2012 08:12
Template Gradle build for projects using Groovy with embedded vert.x
apply plugin: 'groovy'
repositories {
mavenCentral()
// vertxHome must be defined in gradle.properties
flatDir { dirs "${vertxHome}/lib/jars" }
}
dependencies {
groovy 'org.codehaus.groovy:groovy:1.8.6'
@robfletcher
robfletcher / _Events.groovy
Created June 20, 2012 16:39
Automatically display last deployment time in your Cloud Foundry app
eventCfUpdateStart = {
metadata.'cf.last.deployed' = new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
metadata.persist()
}
UserRole.withCriteria {
createAlias 'user', 'u'
projections {
property 'u.username'
}
eq 'role', role
}