Skip to content

Commit

Permalink
* Added ColorService plus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coiouhkc committed Feb 6, 2012
1 parent 2d115f4 commit 580c778
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 4 deletions.
30 changes: 30 additions & 0 deletions .classpath
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@
<attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/> <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="BuildConfig.groovy|*DataSource.groovy|UrlMappings.groovy|Config.groovy|BootStrap.groovy|spring/resources.groovy" kind="src" path=".link_to_grails_plugins/class-diagram-0.5.2/grails-app/conf">
<attributes>
<attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/class-diagram-0.5.2/grails-app/controllers">
<attributes>
<attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/class-diagram-0.5.2/grails-app/i18n">
<attributes>
<attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/class-diagram-0.5.2/grails-app/services">
<attributes>
<attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/class-diagram-0.5.2/grails-app/views">
<attributes>
<attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/class-diagram-0.5.2/src/groovy">
<attributes>
<attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="BuildConfig.groovy|*DataSource.groovy|UrlMappings.groovy|Config.groovy|BootStrap.groovy|spring/resources.groovy" kind="src" path=".link_to_grails_plugins/export-1.1.1/grails-app/conf"> <classpathentry excluding="BuildConfig.groovy|*DataSource.groovy|UrlMappings.groovy|Config.groovy|BootStrap.groovy|spring/resources.groovy" kind="src" path=".link_to_grails_plugins/export-1.1.1/grails-app/conf">
<attributes> <attributes>
<attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/> <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
Expand Down
4 changes: 3 additions & 1 deletion .settings/org.eclipse.core.resources.prefs
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,13 @@
#Mon Feb 06 13:40:54 CET 2012 #Mon Feb 06 14:27:51 CET 2012
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//.link_to_grails_plugins/atmosphere-0.4.2.1/grails-app/i18n=UTF-8 encoding//.link_to_grails_plugins/atmosphere-0.4.2.1/grails-app/i18n=UTF-8
encoding//.link_to_grails_plugins/atmosphere-0.4.2.1/grails-app/i18n/messages.properties=UTF-8 encoding//.link_to_grails_plugins/atmosphere-0.4.2.1/grails-app/i18n/messages.properties=UTF-8
encoding//.link_to_grails_plugins/cache-headers-1.1.5/grails-app/i18n=UTF-8 encoding//.link_to_grails_plugins/cache-headers-1.1.5/grails-app/i18n=UTF-8
encoding//.link_to_grails_plugins/cache-headers-1.1.5/grails-app/i18n/messages.properties=UTF-8 encoding//.link_to_grails_plugins/cache-headers-1.1.5/grails-app/i18n/messages.properties=UTF-8
encoding//.link_to_grails_plugins/cached-resources-1.0/grails-app/i18n=UTF-8 encoding//.link_to_grails_plugins/cached-resources-1.0/grails-app/i18n=UTF-8
encoding//.link_to_grails_plugins/cached-resources-1.0/grails-app/i18n/messages.properties=UTF-8 encoding//.link_to_grails_plugins/cached-resources-1.0/grails-app/i18n/messages.properties=UTF-8
encoding//.link_to_grails_plugins/class-diagram-0.5.2/grails-app/i18n=UTF-8
encoding//.link_to_grails_plugins/class-diagram-0.5.2/grails-app/i18n/messages.properties=UTF-8
encoding//.link_to_grails_plugins/export-1.1.1/grails-app/i18n=UTF-8 encoding//.link_to_grails_plugins/export-1.1.1/grails-app/i18n=UTF-8
encoding//.link_to_grails_plugins/export-1.1.1/grails-app/i18n/messages.properties=UTF-8 encoding//.link_to_grails_plugins/export-1.1.1/grails-app/i18n/messages.properties=UTF-8
encoding//.link_to_grails_plugins/jcaptcha-1.2.1/grails-app/i18n=UTF-8 encoding//.link_to_grails_plugins/jcaptcha-1.2.1/grails-app/i18n=UTF-8
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ by creating you board and view is with 2 different browser sessions and collabor


Further features that we plan to implement in the futre Further features that we plan to implement in the futre
------------------------------------- -------------------------------------
* Full-text search on Tasks (board specific)
* RSS feeds for all updates on a Board * RSS feeds for all updates on a Board
* Support for Swimlanes on boards * Support for Swimlanes on boards
* Flow improvement / Bottleneck suggestions based on historical data of a board * Flow improvement / Bottleneck suggestions based on historical data of a board
Expand Down
4 changes: 3 additions & 1 deletion application.properties
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,8 @@
#Grails Metadata file #Grails Metadata file
#Mon Feb 06 13:40:26 CET 2012 #Mon Feb 06 14:51:42 CET 2012
app.grails.version=2.0.0 app.grails.version=2.0.0
app.name=cotabo app.name=cotabo
app.servlet.version=2.4 app.servlet.version=2.4
app.version=0.0.1 app.version=0.0.1
plugins.class-diagram=0.5.2
plugins.create-domain-uml=0.5
1 change: 0 additions & 1 deletion grails-app/conf/BuildConfig.groovy
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ grails.project.dependency.resolution = {
//compile //compile
compile ':export:1.1.1' compile ':export:1.1.1'
compile ":cache-headers:1.1.5" compile ":cache-headers:1.1.5"
compile ":spring-security-core:1.2.7"


//build //build
build ":tomcat:$grailsVersion" build ":tomcat:$grailsVersion"
Expand Down
3 changes: 3 additions & 0 deletions grails-app/domain/org/cotabo/TaskColor.groovy
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.cotabo


class TaskColor { class TaskColor {


// TODO: named property Board

static belongsTo = [Task, Board] static belongsTo = [Task, Board]
static hasMany = [tasks : Task] static hasMany = [tasks : Task]


Expand All @@ -14,6 +16,7 @@ class TaskColor {


String name String name
String color String color
boolean active


@Override @Override
public String toString(){ public String toString(){
Expand Down
48 changes: 48 additions & 0 deletions grails-app/services/org/cotabo/ColorService.groovy
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.cotabo

class ColorService {

static transactional = true

def create(TaskColor color){
color.active = true
color.save(flush:true)
return color
}

def read(def name){
return TaskColor.findByName(name)
}

def update(TaskColor color){
color.save(flush:true)
}

def delete(TaskColor color){
color.active = false
}

def assign(Task task, TaskColor color) {
task.addToColors(color)
task.save(flush:true)
color.save(flush:true)
}

def unassign(Task task, TaskColor color) {
task.removeFromColors(color)
task.save(flush:true)
color.save(flush:true)
}

def assign(Board board, TaskColor color) {
board.addToColors(color)
board.save(flush:true)
color.save(flush:true)
}

def unassign(Board board, TaskColor color) {
board.removeFromColors(color)
board.save(flush:true)
color.save(flush:true)
}
}
134 changes: 134 additions & 0 deletions test/unit/org/cotabo/ColorServiceTests.groovy
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,134 @@
package org.cotabo

import grails.test.mixin.domain.DomainClassUnitTestMixin

/**
* See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
*/
@TestFor(ColorService)
@TestMixin(DomainClassUnitTestMixin)
class ColorServiceTests {

void testCreate() {
mockDomain(TaskColor)

def taskColor = [name:"Tag for Me", color:"#123456"] as TaskColor
def service = new ColorService()

service.create(taskColor)

assertNotNull TaskColor.findByName("Tag for Me")
assertNull TaskColor.findByColor("123456")
assertNotNull TaskColor.findByColor("#123456")

taskColor = TaskColor.findByName("Tag for Me")

assertNotNull taskColor.id
assertTrue taskColor.active

}

void testRead() {
mockDomain(TaskColor)

def taskColor = [name:"Tag for Me", color:"#123456"] as TaskColor
def service = new ColorService()

service.create(taskColor)
taskColor = service.read("Tag for Me")

assertNotNull taskColor.id
assertTrue taskColor.active
assertEquals taskColor.name, "Tag for Me"
assertEquals taskColor.color, "#123456"
}

void testUpdate() {
mockDomain(TaskColor)

def taskColor = [name:"Tag for Me", color:"#123456"] as TaskColor
def service = new ColorService()

service.create(taskColor)
taskColor = service.read("Tag for Me")

taskColor.name = "Tag for Me was here"
service.update(taskColor)

taskColor = TaskColor.findByColor("#123456")

assertNotNull taskColor.id
assertTrue taskColor.active
assertEquals taskColor.name, "Tag for Me was here"
assertEquals taskColor.color, "#123456"
}

void testDelete() {
mockDomain(TaskColor)

def taskColor = [name:"Tag for Me", color:"#123456"] as TaskColor
def service = new ColorService()

service.create(taskColor)
taskColor = service.read("Tag for Me")

service.delete(taskColor)

taskColor = TaskColor.findByColor("#123456")

assertNotNull taskColor

assertNotNull taskColor.id
assertFalse taskColor.active
assertEquals taskColor.name, "Tag for Me"
assertEquals taskColor.color, "#123456"
}

void testAssignColorBoard() {
mockDomain(TaskColor)
mockDomain(Board)

def board = [name: "test board", columns:[]] as Board
def taskColor = [name:"Tag for Me", color:"#123456"] as TaskColor

def service = new ColorService()
service.assign(board, taskColor)

assertNotNull TaskColor.findByName("Tag for Me")
assertNotNull Board.findByName("test board")

board = Board.findByName("test board")
taskColor = TaskColor.findByName("Tag for Me")

assertNotNull board.colors
assertTrue board.colors.size()>0
//assertNotNull taskColor.board //taskColor has no property board

assertNotNull Board.list().collect{taskColor in it.colors}
assertTrue Board.list().collect{taskColor in it.colors}.size()>0
//assertNotNull TaskColor.findByBoard(board) // taskColor has not property board
}

void testUnassignColorBoard() {
mockDomain(TaskColor)
mockDomain(Board)

def board = [name: "test board", columns:[]] as Board
def taskColor = [name:"Tag for Me", color:"#123456"] as TaskColor

def service = new ColorService()
service.assign(board, taskColor)

service.unassign(board, taskColor)

board = Board.findByName("test board")
taskColor = TaskColor.findByName("Tag for Me")

assertNotNull board.colors
assertEquals 0, board.colors.size()

assertNotNull Board.list().collect{taskColor in it.colors}
assertEquals 0, Board.list().count{taskColor in it.colors}

}
}

0 comments on commit 580c778

Please sign in to comment.