Skip to content

Commit

Permalink
Fixed TestConnection. Completed? testsFixed TestConnection. Completed…
Browse files Browse the repository at this point in the history
…? tests..
  • Loading branch information
machisuji committed Jan 12, 2011
1 parent 7adb0f3 commit 3498caa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
40 changes: 38 additions & 2 deletions src/test/scala/org/squeryl/tests/issues/Issue69.scala
Expand Up @@ -24,11 +24,47 @@ class Issue69 extends Specification with TestConnection {
import org.squeryl.PrimitiveTypeMode._
using(session) {
val node = new Node("Root") // has no parent!
from(Graph.nodes)(n => select(n)) must haveSize (0)
val getNodes = from(Graph.nodes)(n => select(n))
getNodes must haveSize (0)
transaction {
Graph.nodes.insert(node)
}
from(Graph.nodes)(n => select(n)) must haveSize (1)
getNodes must haveSize (1)
node.parent must haveSize (0)
node.children must haveSize (0)
}
}

"however, be able to have a parent." in {
import org.squeryl.PrimitiveTypeMode._
using(session) {
val node = new Node("Adam")
val getRoot = from(Graph.nodes)(n => where(n.name === "Root") select(n))
val root = getRoot.head
root.children must haveSize(0)
transaction {
Graph.nodes.insert(node)
node.parent must haveSize (0)
root.children.associate(node)
}
val children = getRoot.head.children.toList
children must haveSize(1)
children(0) mustEqual node
}
}

"let me see ..." in {
import org.squeryl.PrimitiveTypeMode._
using(session) {
val nodes = from(Graph.nodes)(select(_)).toList
println("\tID\tNAME\tPARENT_ID")
nodes.foreach { node =>
print("\t" + node.id + "\t" + node.name + "\t")
val parent = node.parent.headOption
if (parent.isDefined) println(parent.get.id)
else println("-")
}
nodes must haveSize(2)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/scala/org/squeryl/tests/issues/TestConnection.scala
Expand Up @@ -7,8 +7,8 @@ import org.squeryl.{Session, SessionFactory}
import org.squeryl.adapters.H2Adapter

trait TestConnection {
val session = createTestConnection
initSessionFactory(session)
initSessionFactory()
val session = SessionFactory.newSession

def createTestConnection = {
Class.forName("org.h2.Driver");
Expand All @@ -17,7 +17,7 @@ trait TestConnection {
new H2Adapter
)
}
def initSessionFactory(session: Session) {
SessionFactory.concreteFactory = Some(() => session)
def initSessionFactory() {
SessionFactory.concreteFactory = Some(() => createTestConnection)
}
}

0 comments on commit 3498caa

Please sign in to comment.