Skip to content

Commit

Permalink
Merge branch '3.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Oct 1, 2015
2 parents 5eb5b81 + 9672f95 commit e898915
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 13 deletions.
Expand Up @@ -43,15 +43,24 @@ class SynchronousPromiseFactory extends AbstractPromiseFactory {

@Override
def <T> Promise<T> createPromise(Closure<T>... closures) {
Promise<T> promise
if (closures.length == 1) {
return new SynchronousPromise<T>(closures[0])
promise = new SynchronousPromise<T>(closures[0])
} else {
def promiseList = new PromiseList()
for(p in closures) {
promiseList << p
}
promise = promiseList
}

def promiseList = new PromiseList()
for(p in closures) {
promiseList << p
try {
promise.get()
} catch (e) {
// ignore
}
return promiseList

return promise
}

@Override
Expand Down
Expand Up @@ -17,6 +17,7 @@ package grails.async

import grails.async.decorator.PromiseDecorator
import org.grails.async.factory.SynchronousPromiseFactory
import spock.lang.Issue
import spock.lang.Specification

/**
Expand Down Expand Up @@ -135,12 +136,24 @@ class SynchronousPromiseFactorySpec extends Specification {

void "Test promise chaining with exception"() {
when:"A promise is chained"
def promise = Promises.createPromise { 1 + 1 }
promise = promise.then { it * 2 } then { throw new RuntimeException("bad")} then { it + 6 }
def val = promise.get()
def promise = Promises.createPromise { 1 + 1 }
promise = promise.then { it * 2 } then { throw new RuntimeException("bad")} then { it + 6 }
def val = promise.get()

then:'the chain is executed'
thrown RuntimeException
val == null
thrown RuntimeException
val == null
}

@Issue("GRAILS-9229")
void "Test promise is executed without calling get"() {
given:
Closure callable = Mock(Closure)

when:"A promise is created"
Promises.createPromise(callable)

then:'the closure is executed'
1 * callable.call()
}
}
}
Expand Up @@ -167,7 +167,7 @@ class FormatTagLib implements TagLibrary {
}
String type = attrs.type?.toString()?.toUpperCase()
def formatName = attrs.formatName
def format = attrs.format
String format = attrs.format
def timeZone = attrs.timeZone
if (timeZone != null) {
if (!(timeZone instanceof TimeZone)) {
Expand Down
Expand Up @@ -197,7 +197,7 @@ class UrlMappingsUnitTestMixin extends ControllerUnitTestMixin {
if (mapping) mappingInfos << mapping
}
else {
mappingInfos = mappingsHolder.matchAll(url)
mappingInfos = mappingsHolder.matchAll(url, request.method)
}

if (mappingInfos.size() == 0) throw new AssertionFailedError("url '$url' did not match any mappings")
Expand Down
@@ -1,13 +1,15 @@
package grails.test.mixin

import grails.artefact.Artefact
import grails.rest.RestfulController
import grails.test.mixin.web.UrlMappingsUnitTestMixin
import grails.web.Action
import junit.framework.AssertionFailedError
import junit.framework.ComparisonFailure

import org.junit.Test
import org.springframework.web.context.WebApplicationContext
import spock.lang.Issue

/**
* Tests for the UrlMappingsTestMixin class
Expand Down Expand Up @@ -154,6 +156,42 @@ class UrlMappingsTestMixinTests {
dateParam = new Date(1)
}
}

@Test
@Issue('https://github.com/grails/grails-core/issues/9065')
void testResourcesUrlMapping() {
mockController(PersonController)
mockUrlMappings(ResourceTestUrlMappings)

request.method = 'GET'
assertForwardUrlMapping('/person', controller: 'person', action: 'index')
assertForwardUrlMapping('/person/create', controller: 'person', action: 'create')
assertForwardUrlMapping('/person/personId', controller: 'person', action: 'show') {
id = 'personId'
}
assertForwardUrlMapping('/person/personId/edit', controller: 'person', action: 'edit') {
id = 'personId'
}

request.method = 'POST'
assertForwardUrlMapping('/person', controller: 'person', action: 'save')

request.method = 'PUT'
assertForwardUrlMapping('/person/personId', controller: 'person', action: 'update') {
id = 'personId'
}

request.method = 'PATCH'
assertForwardUrlMapping('/person/personId', controller: 'person', action: 'patch') {
id = 'personId'
}

request.method = 'DELETE'
assertForwardUrlMapping('/person/personId', controller: 'person', action: 'delete') {
id = 'personId'
}

}
}

class AnotherUrlMappings {
Expand Down Expand Up @@ -211,3 +249,16 @@ class GRAILS9110UrlMappings {
}
}
}

@Artefact("Controller")
class PersonController extends RestfulController<String> {
PersonController() {
super(''.class)
}
}

class ResourceTestUrlMappings {
static mappings = {
'/person'(resources: 'person')
}
}
@@ -1,5 +1,8 @@
package org.grails.web.taglib

import org.grails.buffer.StreamCharBuffer
import spock.lang.Issue

import java.text.DecimalFormatSymbols

import org.grails.taglib.GrailsTagException
Expand Down Expand Up @@ -36,6 +39,17 @@ class FormatTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals 'X', template, [somebool: false]
}

@Issue('https://github.com/grails/grails-core/issues/9159')
void testFormatDateWithStreamCharBufferFormat() {
def calender = new GregorianCalendar(1980,1,3)
def format = 'yyyy-MM-dd'
def buffer = new StreamCharBuffer()
buffer.writer.append(format)
def template = '<g:formatDate format="${format}" date="${date}"/>'
assertOutputEquals("1980-02-03", template, [date:calender.getTime(), format: buffer])
}


void testFormatDate() {
def calender = new GregorianCalendar(1980,1,3)
def template = '<g:formatDate format="yyyy-MM-dd" date="${date}"/>'
Expand Down

0 comments on commit e898915

Please sign in to comment.