Skip to content

Commit

Permalink
Provide fixture feature as scalaikejdbc-play-fixture-plugin
Browse files Browse the repository at this point in the history
for compatibility for scalikejdbc-play-plugin.
  • Loading branch information
tototoshi committed Apr 1, 2013
1 parent 00d7810 commit 248b31d
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 11 deletions.
32 changes: 31 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,35 @@ object ScalikeJDBCProjects extends Build {
)
) dependsOn(scalikejdbc)

lazy val scalikejdbcPlayFixturePlugin = Project(
id = "play-fixture-plugin",
base = file("scalikejdbc-play-fixture-plugin"),
settings = Defaults.defaultSettings ++ Seq(
sbtPlugin := false,
organization := _organization,
name := "scalikejdbc-play-fixture-plugin",
version := _version,
crossScalaVersions := Seq("2.10.0"),
resolvers ++= _resolvers,
libraryDependencies ++= Seq(
"play" %% "play" % "2.1.0" % "provided",
"play" %% "play-test" % "2.1.0" % "test",
"com.h2database" % "h2" % "[1.3,)" % "test"
),
testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "sequential", "true"),
publishTo <<= version { (v: String) => _publishTo(v) },
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { x => false },
pomExtra := _pomExtra,
scalacOptions ++= _scalacOptions
)
).dependsOn(
scalikejdbcPlayPlugin
).aggregate(
scalikejdbcPlayPlugin
)

lazy val scalikejdbcPlayPluginTestZentasks = {
val appName = "play-plugin-test-zentasks"
val appVersion = "1.0"
Expand All @@ -257,10 +286,11 @@ object ScalikeJDBCProjects extends Build {
"Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots"
)
).dependsOn(
scalikejdbcPlayPlugin,
scalikejdbcPlayFixturePlugin,
scalikejdbcInterpolation
).aggregate(
scalikejdbcPlayPlugin,
scalikejdbcPlayFixturePlugin,
scalikejdbcInterpolation
)
}
Expand Down
1 change: 1 addition & 0 deletions scalikejdbc-play-fixture-plugin/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalariformSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2013 Toshiyuki Takahashi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package scalikejdbc

import play.api._

/**
* The Play fixture plugin
*/
class FixturePlugin(implicit app: Application) extends Plugin
with FixtureSupport {

override def onStart(): Unit = {
if (Play.isTest || Play.isDev) {
loadFixtures()
}
}

override def onStop(): Unit = {
if (Play.isTest || Play.isDev) {
cleanFixtures()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FixtureSupportSpec extends Specification with BeforeAfterExample {
"db.secondary.user" -> "l",
"db.secondary.password" -> "g"
),
additionalPlugins = Seq("scalikejdbc.PlayPlugin")
additionalPlugins = Seq("scalikejdbc.PlayPlugin", "scalikejdbc.FixturePlugin")
)

"FixtureSupport" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import play.api._
/**
* The Play plugin to use ScalikeJDBC
*/
class PlayPlugin(implicit app: Application) extends Plugin
with FixtureSupport {
class PlayPlugin(implicit app: Application) extends Plugin {

import PlayPlugin._

Expand Down Expand Up @@ -90,16 +89,9 @@ class PlayPlugin(implicit app: Application) extends Plugin

opt("closeAllOnStop", "enabled")(playConfig).foreach { enabled => closeAllOnStop = enabled.toBoolean }

if (Play.isTest || Play.isDev) {
loadFixtures()
}
}

override def onStop(): Unit = {
if (Play.isTest || Play.isDev) {
cleanFixtures()
}

if (closeAllOnStop) {
ConnectionPool.closeAll()
registeredPoolNames.clear()
Expand Down
1 change: 1 addition & 0 deletions scalikejdbc-play-plugin/test/zentasks/conf/play.plugins
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
777:scalikejdbc.PlayPlugin
888:scalikejdbc.FixturePlugin

0 comments on commit 248b31d

Please sign in to comment.