forked from cotabo/cotabo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | |||
|
|||
} | |||
} |