Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2b913a56a1
Fetching contributors…

Cannot retrieve contributors at this time

127 lines (111 sloc) 4.468 kb
/*
* Copyright 2012 WorldWide Conferencing, LLC
*
* 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 net.liftweb
package mongodb
package record
import org.specs2.execute.Result
/**
* Systems under specification for MongoRecord.
*/
class MongoRecordLifecycleSpec extends MongoTestSpecification {
import fixtures._
"MongoRecordLifecycle callbacks" should {
def testOneHarness(scope: String, f: LifecycleTestRecord => HarnessedLifecycleCallbacks): Result = {
("be called before validation when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).beforeValidationHarness = () => triggered = true
rec.foreachCallback(_.beforeValidation)
triggered must_== true
}
("be called after validation when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).afterValidationHarness = () => triggered = true
rec.foreachCallback(_.afterValidation)
triggered must_== true
}
("be called around validate when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggeredBefore = false
var triggeredAfter = false
f(rec).beforeValidationHarness = () => triggeredBefore = true
f(rec).afterValidationHarness = () => triggeredAfter = true
rec.validate must_== Nil
triggeredBefore must_== true
triggeredAfter must_== true
}
("be called before save when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).beforeSaveHarness = () => triggered = true
rec.foreachCallback(_.beforeSave)
triggered must_== true
}
("be called before create when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).beforeCreateHarness = () => triggered = true
rec.foreachCallback(_.beforeCreate)
triggered must_== true
}
("be called before update when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).beforeUpdateHarness = () => triggered = true
rec.foreachCallback(_.beforeUpdate)
triggered must_== true
}
("be called after save when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).afterSaveHarness = () => triggered = true
rec.foreachCallback(_.afterSave)
triggered must_== true
}
("be called after create when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).afterCreateHarness = () => triggered = true
rec.foreachCallback(_.afterCreate)
triggered must_== true
}
("be called after update when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).afterUpdateHarness = () => triggered = true
rec.foreachCallback(_.afterUpdate)
triggered must_== true
}
("be called before delete when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).beforeDeleteHarness = () => triggered = true
rec.foreachCallback(_.beforeDelete)
triggered must_== true
}
("be called after delete when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
f(rec).afterDeleteHarness = () => triggered = true
rec.foreachCallback(_.afterDelete)
triggered must_== true
}
success
}
testOneHarness("the field level", rec => rec.stringFieldWithCallbacks: HarnessedLifecycleCallbacks)
}
}
Jump to Line
Something went wrong with that request. Please try again.