Navigation Menu

Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Nelson committed Nov 4, 2011
1 parent 4e1dd6d commit 4ad36e7
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 46 deletions.
4 changes: 0 additions & 4 deletions README

This file was deleted.

16 changes: 16 additions & 0 deletions README.md
@@ -0,0 +1,16 @@
# Lift MongoDB Project

[g8](http://github.com/n8han/giter8) template to get a Lift-MongoDB webapp up and running quickly. The template generates a project that uses [Twitter's Bootstrap](http://twitter.github.com/bootstrap/) and implements the [Mongoauth Lift Module](https://github.com/eltimn/lift-mongoauth). It uses SBT 0.11.0 as the build tool. It has not been tested with other versions of SBT.

## Usage

Install giter8 (g8) - [readme](http://github.com/n8han/giter8#readme) for more information.

Install SBT 0.11.x - [Setup](https://github.com/harrah/xsbt/wiki/Setup) for more information.

In a shell, run the following in the parent directory of the new project:

g8 eltimn/lift-mongo
cd <project-name>

Please see the README file in your new project for further instructions on configuring and running your app.
1 change: 1 addition & 0 deletions build.sbt
@@ -0,0 +1 @@
seq(giter8Settings :_*)
6 changes: 0 additions & 6 deletions project/build.properties

This file was deleted.

6 changes: 0 additions & 6 deletions project/build/project.scala

This file was deleted.

1 change: 1 addition & 0 deletions project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("net.databinder" %% "giter8-plugin" % "0.3.0")
5 changes: 0 additions & 5 deletions project/plugins/plugins.scala

This file was deleted.

3 changes: 0 additions & 3 deletions project/plugins/project/build.properties

This file was deleted.

7 changes: 5 additions & 2 deletions src/main/g8/README.markdown → src/main/g8/README.md
Expand Up @@ -25,8 +25,11 @@ This app uses MongoDB. Therefore, you will need to either have it installed loca
This app uses sbt 0.11. To build for the first time, run:

bash\$ sbt
> update
> compile
> container:start

It will be running on http://localhost:8080
It will be running on http://localhost:8080

# User Model

This app implements the [Mongoauth Lift Module](https://github.com/eltimn/lift-mongoauth). The registration and login implementation is based on [research done by Google](http://sites.google.com/site/oauthgoog/UXFedLogin) a few years ago and is similar to Amazon.com and Buy.com. It's different than what most people seem to expect, but it can easily be changed to suit your needs since most of the code is part of your project.
2 changes: 1 addition & 1 deletion src/main/g8/src/main/scala/$package$/config/Sitemap.scala
Expand Up @@ -24,7 +24,7 @@ case class MenuLoc(menu: Menu) {
lazy val fullUrl: String = S.hostAndPath+url
}

object Sitemap {
object Sitemap extends Locs {
import MenuGroups._

// locations (menu entries)
Expand Down
2 changes: 1 addition & 1 deletion src/main/g8/src/main/scala/bootstrap/liftweb/Boot.scala
Expand Up @@ -25,7 +25,7 @@ class Boot extends Loggable {

// init auth-mongo
MongoAuth.authUserMeta.default.set(User)
MongoAuth.loginTokenAfterUrl.default.set(Sitemap.password.path)
MongoAuth.loginTokenAfterUrl.default.set(Sitemap.password.url)
MongoAuth.siteName.default.set("$name$")
MongoAuth.systemEmail.default.set("info@") // TODO: Set me
MongoAuth.systemUsername.default.set("$name$ Staff")
Expand Down
2 changes: 1 addition & 1 deletion src/main/g8/src/main/webapp/login.html
Expand Up @@ -45,7 +45,7 @@
</div>
<div class="clearfix">
<div class="input">
<p><strong>Do you have a Beam Stream password?</strong></p>
<p><strong>Do you have a $name$ password?</strong></p>
</div>
</div>
<div class="clearfix">
Expand Down
18 changes: 10 additions & 8 deletions src/main/g8/src/test/scala/$package$/HtmlSourceSpecs.scala
Expand Up @@ -4,21 +4,23 @@ import java.io.File

import scala.xml.XML

import org.specs.Specification
import org.scalatest.WordSpec
import org.scalatest.matchers.ShouldMatchers

import net.liftweb.common.Full
import net.liftweb.util.Html5

object HtmlSourceSpec extends Specification {
object HtmlSourceSpec extends WordSpec with ShouldMatchers {

"HTML Sources" should {

"be well-formed" in {
/**
* Tests to make sure the project's HTML files are well-formed.
*
* Finds every *.html and *.xml file in src/main/webapp (and its
* subdirectories) and tests to make sure they are well-formed.
*/
* Tests to make sure the project's HTML files are well-formed.
*
* Finds every *.html and *.xml file in src/main/webapp (and its
* subdirectories) and tests to make sure they are well-formed.
*/
var failed: List[File] = Nil

def handledXml(file: String) = file.endsWith(".xml")
Expand Down Expand Up @@ -54,7 +56,7 @@ object HtmlSourceSpec extends Specification {
fail(msg)
}

numFails must_== 0
numFails should equal (0)
}
}
}
48 changes: 48 additions & 0 deletions src/main/g8/src/test/scala/$package$/MongoTestKit.scala
@@ -0,0 +1,48 @@
package $package$

import org.scalatest.{BeforeAndAfter, Spec}

import net.liftweb._
import mongodb._

import com.mongodb.{Mongo, ServerAddress}

/**
* Creates a Mongo instance named after the class.
* Therefore, each Spec class shares the same database.
* Database is dropped after.
*/
trait MongoTestKit extends BeforeAndAfter {
this: Spec =>

def dbName = "test_"+this.getClass.getName
.replace(".", "_")
.toLowerCase

def defaultServer = new ServerAddress("127.0.0.1", 27017)

// If you need more than one db, override this
def dbs: List[(MongoIdentifier, ServerAddress, String)] = List((DefaultMongoIdentifier, defaultServer, dbName))

def debug = false

before {
// define the dbs
dbs foreach { case (id, srvr, name) =>
MongoDB.defineDb(id, new Mongo(srvr), name)
}
}

after {
if (!debug) {
// drop the databases
dbs foreach { case (id, _, _) =>
MongoDB.use(id) { db => db.dropDatabase }
}
}

// clear the mongo instances
MongoDB.close
}
}

@@ -1,24 +1,25 @@
package $package$
package snippet

import org.specs.Specification
import org.specs.specification.Examples
import lib.DependencyFactory

import org.scalatest.WordSpec
import org.scalatest.matchers.ShouldMatchers

import net.liftweb._
import common._
import http._
import util._
import Helpers._
import lib._

object HelloWorldSpec extends Specification {
class HelloWorldSpec extends WordSpec with ShouldMatchers {
val session = new LiftSession("", randomString(20), Empty)
val stableTime = now

override def executeExpectations(ex: Examples, t: => Any): Any = {
override def withFixture(test: NoArgTest) {
S.initIfUninitted(session) {
DependencyFactory.time.doWith(stableTime) {
super.executeExpectations(ex, t)
test()
}
}
}
Expand All @@ -30,9 +31,8 @@ object HelloWorldSpec extends Specification {

val str = hello.render(<span>Welcome to your Lift app at <span id="time">Time goes here</span></span>).toString

str.indexOf(stableTime.toString) must be >= 0
str.indexOf("Welcome to your Lift app at") must be >= 0
str.indexOf(stableTime.toString) should be >= 0
str.indexOf("Welcome to your Lift app at") should be >= 0
}
}
}

0 comments on commit 4ad36e7

Please sign in to comment.