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
6 changed files
with
111 additions
and
14 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
5 changes: 0 additions & 5 deletions
5
src/test/scala/com/wheaties/squealer/generator/FormatoSpec.scala
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...test/scala/com/wheaties/squealer/generator/scala/scalaquery/ScalaQueryGeneratorSpec.scala
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,30 @@ | |||
package com.wheaties.squealer.generator.scala.scalaquery | |||
|
|||
import org.specs2.mutable.Specification | |||
import com.wheaties.squealer.generator.Formato | |||
import com.wheaties.squealer.db.{ColumnDef, IntType, Column, Table} | |||
|
|||
class ScalaQueryGeneratorSpec extends Specification{ | |||
val formato = new Formato{ | |||
def databaseName(name: String) = name | |||
def tableName(name: String) = name | |||
def columnName(name: String) = name | |||
} | |||
|
|||
"writeTable" should{ | |||
val table = Table("foo", None, Column("bar", IntType, None, None, ColumnDef) :: Nil) | |||
val output = ScalaQueryGenerator.writeTable(table, "foo", formato) | |||
|
|||
"produce import statements" in{ | |||
output must contain("import org.scalaquery.ql.basic.BasicTable") and contain("org.scalaquery.ql.TypeMapper._") | |||
} | |||
|
|||
"produce the table object" in{ | |||
output must contain("object foo extends BasicTable[Int]") | |||
} | |||
|
|||
"produce the package the table object is contained" in{ | |||
output must contain("package foo") | |||
} | |||
} | |||
} |
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
73 changes: 73 additions & 0 deletions
73
src/test/scala/com/wheaties/squealer/generator/scala/squeryl/SquerylGeneratorSpec.scala
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,73 @@ | |||
package com.wheaties.squealer.generator.scala.squeryl | |||
|
|||
import org.specs2.mutable.Specification | |||
import com.wheaties.squealer.generator.Formato | |||
import com.wheaties.squealer.db._ | |||
import treehugger.forest._ | |||
|
|||
class SquerylGeneratorSpec extends Specification{ | |||
val formato = new Formato{ | |||
def databaseName(name: String) = name | |||
def tableName(name: String) = name | |||
def columnName(name: String) = name | |||
} | |||
|
|||
"writeTable" should{ | |||
val table = Table("foo", None, Column("bar", IntType, None, None, PrimaryKey) :: Nil) | |||
val output = SquerylGenerator.writeTable(table, "baz", formato) | |||
|
|||
"produce import statements" in{ | |||
output must contain("org.squeryl.PrimitiveTypeMode._") and contain("org.squeryl.annotations.Column") | |||
} | |||
|
|||
"produce the table object" in{ | |||
output must contain("case class foo") | |||
} | |||
|
|||
"produce the package the table object is contained" in{ | |||
output must contain("package baz") | |||
} | |||
} | |||
|
|||
"makeClass" should{ | |||
val table = Table("foo", None, Column("bar", IntType, None, None, NullablePrimaryKey) :: Nil) | |||
val output = SquerylGenerator.makeClass(table.name, table.columns, Nil, formato) | |||
|
|||
"produce a class" in{ | |||
treeToString(output) must contain("class foo") | |||
} | |||
|
|||
"produce the member functions of a class" in{ | |||
treeToString(output) must contain("def id = compositeKey(bar)") and contain("def this = this(Some(0))") | |||
} | |||
} | |||
|
|||
"writeDatabase" should{ | |||
val table = Table("foo", None, Column("bar", IntType, None, None, PrimaryKey) :: Nil) | |||
val db = Database("baz", table :: Nil) | |||
val output = SquerylGenerator.writeDatabase(db, "baz", formato) | |||
|
|||
"produce import statements" in{ | |||
output must contain("org.squeryl.PrimitiveTypeMode._") and contain("org.squery.Schema") | |||
} | |||
|
|||
"handle a schema with one table" in{ | |||
output must contain("object baz extends Schema {\n val foo = table[foo](\"foo\")\n}") | |||
} | |||
|
|||
"handle a schema with multiple tables" in{ | |||
val multi = Database("baz", table :: table.copy(name = "yo") :: Nil) | |||
val output = SquerylGenerator.writeDatabase(multi, "baz", formato) | |||
|
|||
output must contain("object baz extends Schema {\n val foo = table[foo](\"foo\")\n val yo = table[yo](\"yo\")\n}") | |||
} | |||
} | |||
|
|||
"tableDef" should{ | |||
"produce something" in{ | |||
val output = SquerylGenerator.tableDef("foo", formato) | |||
|
|||
treeToString(output) must be_==("val foo = table[foo](\"foo\")") | |||
} | |||
} | |||
} |