Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from websudos/release/enums
Adding enumeration support.
- Loading branch information
Showing
12 changed files
with
142 additions
and
25 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
15 changes: 15 additions & 0 deletions
15
morpheus-mysql/src/test/scala/com/websudos/morpheus/mysql/Samplers.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.websudos.morpheus.mysql | ||
|
||
import com.websudos.morpheus.mysql.tables.{TestEnumeration, EnumerationRecord} | ||
import com.websudos.util.testing._ | ||
|
||
trait Samplers { | ||
implicit object EnumerationRecordSampler extends Sample[EnumerationRecord] { | ||
def sample: EnumerationRecord = { | ||
EnumerationRecord( | ||
id = gen[Int], | ||
enum = oneOf(TestEnumeration) | ||
) | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...sql/src/test/scala/com/websudos/morpheus/mysql/db/specialized/EnumerationColumnTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.websudos.morpheus.mysql.db.specialized | ||
|
||
import com.websudos.morpheus.mysql.{Samplers, _} | ||
import com.websudos.morpheus.mysql.db.MySQLSuite | ||
import com.websudos.morpheus.mysql.tables.{TestEnumeration, EnumerationRecord, EnumerationTable} | ||
import com.websudos.util.testing._ | ||
import org.scalatest.FlatSpec | ||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.duration._ | ||
|
||
class EnumerationColumnTest extends FlatSpec with MySQLSuite with Samplers { | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
Await.result(EnumerationTable.create.ifNotExists.engine(InnoDB).future(), 5.seconds) | ||
} | ||
|
||
implicit val enumPrimitive: SQLPrimitive[TestEnumeration#Value] = { | ||
enumToQueryConditionPrimitive(TestEnumeration) | ||
} | ||
|
||
it should "store a record with an enumeration defined inside it" in { | ||
val record = gen[EnumerationRecord] | ||
|
||
val chain = for { | ||
store <- EnumerationTable.insert | ||
.value(_.id, record.id) | ||
.value(_.enum, record.enum) | ||
.future() | ||
get <- EnumerationTable.select.where(_.id eqs record.id).one | ||
} yield get | ||
|
||
whenReady(chain) { | ||
res => { | ||
res.value shouldEqual record | ||
} | ||
} | ||
|
||
} | ||
} |
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