Permalink
Browse files

Unit and integration testing

  • Loading branch information...
1 parent 2144f71 commit a6c82f26290004939358a54213888c302d4c08d8 Alvaro Sanchez-Mariscal committed Apr 23, 2012
@@ -10,7 +10,6 @@ class SeoFriendlyUrlsGrailsPlugin {
"grails-app/views/error.gsp"
]
- // TODO Fill in these fields
def title = "Seo Friendly URL's Plugin" // Headline display name of the plugin
def author = "Álvaro Sánchez-Mariscal"
def authorEmail = "alvaro.sanchez@salenda.es"
@@ -41,35 +40,13 @@ Useful if you want SEO-friendly URL's like /book/the-lord-of-the-rings instead o
// Online location of the plugin's browseable source code.
def scm = [ url: "http://github.com/alvarosanchez/seo-friendly-urls" ]
-
- def doWithWebDescriptor = { xml ->
- // TODO Implement additions to web.xml (optional), this event occurs before
- }
-
- def doWithSpring = {
- // TODO Implement runtime spring config (optional)
- }
-
+
def doWithDynamicMethods = { ctx ->
- // TODO Implement registering dynamic methods to classes (optional)
- }
-
- def doWithApplicationContext = { applicationContext ->
- // TODO Implement post initialization spring config (optional)
- }
-
- def onChange = { event ->
- // TODO Implement code that is executed when any artefact that this plugin is
- // watching is modified and reloaded. The event contains: event.source,
- // event.application, event.manager, event.ctx, and event.plugin.
+ def friendlyUrlService = ctx.friendlyUrlService
+
+ String.metaClass.asFriendlyUrl = { ->
+ friendlyUrlService.sanitizeWithDashes(delegate)
+ }
}
- def onConfigChange = { event ->
- // TODO Implement code that is executed when the project configuration changes.
- // The event is the same as for 'onChange'.
- }
-
- def onShutdown = { event ->
- // TODO Implement code that is executed when the application shuts down (optional)
- }
}
@@ -15,7 +15,7 @@ grails.project.dependency.resolution = {
grailsCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
- //mavenCentral()
+ mavenCentral()
//mavenLocal()
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
@@ -33,5 +33,6 @@ grails.project.dependency.resolution = {
":release:1.0.0") {
export = false
}
+ test ":spock:0.6"
}
}
@@ -3,6 +3,8 @@ package es.salenda.plugins.seo.friendly.urls
import java.util.regex.Pattern
class FriendlyUrlService {
+
+ static transactional = false
/**
* This method transforms the text passed as an argument to a text without spaces,
@@ -0,0 +1,20 @@
+package es.salenda.plugins.seo.friendly.urls
+
+import grails.plugin.spock.IntegrationSpec
+
+class FriendlyUrlServiceIntegrationSpec extends IntegrationSpec {
+
+ def "String dynamic method is injected"() {
+ setup:
+ def friendlyUrlService = new FriendlyUrlService()
+
+ expect:
+ string.asFriendlyUrl() == friendlyUrlService.sanitizeWithDashes(string)
+ string.asFriendlyUrl() == "the-lord-of-the-rings"
+
+ where:
+ string = "The Lord of the Rings"
+ }
+
+
+}
@@ -0,0 +1,23 @@
+package es.salenda.plugins.seo.friendly.urls
+
+import grails.plugin.spock.UnitSpec
+
+class FriendlyUrlServiceSpec extends UnitSpec {
+
+ def "when using service method strings are sanitized"() {
+ setup:
+ def friendlyUrlService = new FriendlyUrlService()
+
+ expect:
+ friendlyUrlService.sanitizeWithDashes(string) == sanitized
+
+ where:
+ string | sanitized
+ "The Lord of the Rings" | "the-lord-of-the-rings" //Basics
+ "Raúl González Blanco" | "raul-gonzalez-blanco" //Accents
+ "España" | "espana" //N-tilde chars
+ "Los 3 Mosqueteros" | "los-3-mosqueteros" //Numbers
+ "Real Madrid® C.F." | "real-madrid-cf" //Edge cases
+ }
+
+}

0 comments on commit a6c82f2

Please sign in to comment.