Skip to content

Commit

Permalink
Upgrading to grails 2.1 adding spock test for EventService
Browse files Browse the repository at this point in the history
  • Loading branch information
craigburke committed Aug 7, 2012
1 parent 2d9155b commit bce33bf
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 202 deletions.
7 changes: 4 additions & 3 deletions application.properties
@@ -1,7 +1,8 @@
#Grails Metadata file
#Tue Mar 13 21:35:57 EDT 2012
app.grails.version=2.0.1
#Mon Aug 06 11:52:08 EDT 2012
app.grails.version=2.1.0
app.name=google-calendar
app.servlet.version=2.5
app.version=0.1
plugins.cloud-foundry=1.2.1
plugins.cloud-foundry=1.2.2
plugins.spock=0.6
3 changes: 0 additions & 3 deletions grails-app/conf/BuildConfig.groovy
Expand Up @@ -41,9 +41,6 @@ grails.project.dependency.resolution = {

plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.7.1"
runtime ":resources:1.1.5"

build ":tomcat:$grailsVersion"
}
}
5 changes: 2 additions & 3 deletions grails-app/services/com/craigburke/EventService.groovy
Expand Up @@ -160,7 +160,6 @@ class EventService {
}
} else {
switch (event.recurType) {

case EventRecurType.DAILY:
nextOccurrence = findNextDailyOccurrence(event, afterDate)
break
Expand Down Expand Up @@ -223,7 +222,7 @@ class EventService {
boolean occurrenceFound = false

while (!occurrenceFound) {
if (nextOccurrence.toDate() >= afterDate && isOnRecurringDay(event, nextOccurrence.toDate())) {
if (nextOccurrence.toDate() > afterDate && isOnRecurringDay(event, nextOccurrence.toDate())) {
occurrenceFound = true
}
else {
Expand Down Expand Up @@ -284,6 +283,6 @@ class EventService {

private def isOnExcludedDay(Event event, Date date) {
date = (new DateTime(date)).withTime(0, 0, 0, 0).toDate()
event.excludeDays.contains(date)
event.excludeDays?.contains(date)
}
}
159 changes: 0 additions & 159 deletions test/unit/com/craigburke/EventControllerTests.groovy

This file was deleted.

72 changes: 72 additions & 0 deletions test/unit/com/craigburke/EventServiceSpec.groovy
@@ -0,0 +1,72 @@
package com.craigburke

import grails.test.mixin.*
import grails.plugin.spock.*
import spock.lang.*

import org.joda.time.*
import static org.joda.time.DateTimeConstants.*

@TestFor(EventService)
@Mock(Event)
class EventServiceSpec extends UnitSpec {

@Shared DateTime now
@Shared DateTime mondayNextWeek
@Shared DateTime wednesdayNextWeek
@Shared DateTime fridayNextWeek
@Shared DateTime mondayAfterNext

@Shared Event mwfEvent

def setupSpec() {
now = new DateTime()
mondayNextWeek = new DateTime().plusWeeks(1).withDayOfWeek(MONDAY).withTime(0,0,0,0)
wednesdayNextWeek = mondayNextWeek.withDayOfWeek(WEDNESDAY)
fridayNextWeek = mondayNextWeek.withDayOfWeek(FRIDAY)
mondayAfterNext = mondayNextWeek.plusWeeks(1)

mwfEvent = new Event(
title: 'Repeating MWF Event',
startTime: mondayNextWeek.toDate(),
endTime: mondayNextWeek.plusHours(1).toDate(),
location: "Regular location",
recurType: EventRecurType.WEEKLY,
isRecurring: true,
recurDaysOfWeek: [MONDAY, WEDNESDAY, FRIDAY]
)

}

@Unroll("next occurance of weekly event after #afterDate")
def "next occurrence of a weekly event without excluded days"() {
expect:
service.findNextOccurrence(event, afterDate.toDate()) == expectedResult.toDate()

where:
event | afterDate | expectedResult
mwfEvent | now | mondayNextWeek
mwfEvent | mondayNextWeek | wednesdayNextWeek
mwfEvent | wednesdayNextWeek | fridayNextWeek
}

@Unroll("next occurence of weekly event with exclusion after #afterDate")
def "test exclusion of next monday"() {
setup:
mwfEvent.addToExcludeDays(mondayNextWeek.toDate())

expect:
service.findNextOccurrence(event, afterDate.toDate()) == expectedResult.toDate()


where:
event | afterDate | expectedResult
mwfEvent | now | wednesdayNextWeek
mwfEvent | mondayNextWeek | wednesdayNextWeek
mwfEvent | wednesdayNextWeek | fridayNextWeek

}



}
17 changes: 0 additions & 17 deletions test/unit/com/craigburke/EventServiceTests.groovy

This file was deleted.

17 changes: 0 additions & 17 deletions test/unit/com/craigburke/EventTests.groovy

This file was deleted.

0 comments on commit bce33bf

Please sign in to comment.