Browse files

Don't write to MappedBoolean if value hasn't changed. Closes #1121

  • Loading branch information...
1 parent 9de55fc commit 9a0a4e88d258b7cd25ec01ad7cba801afb8dd196 @jeppenejsum jeppenejsum committed Sep 30, 2011
View
7 persistence/mapper/src/main/scala/net/liftweb/mapper/MappedBoolean.scala
@@ -46,8 +46,11 @@ abstract class MappedBoolean[T<:Mapper[T]](val fieldOwner: T) extends MappedFiel
protected[mapper] def doneWithSave() {orgData = data}
protected def real_i_set_!(value : Boolean) : Boolean = {
- dirty_?(data.map(_ != value) openOr true)
- data = Full(value)
+ val boxed = Full(value)
+ if (boxed != data) {
+ data = boxed
+ dirty_?(true)
+ }
value
}
override def readPermission_? = true
View
64 persistence/mapper/src/test/scala/net/liftweb/mapper/MappedBooleanSpec.scala
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2010-2011 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 mapper
+
+import org.specs.Specification
+
+import common._
+
+
+/**
+ * Systems under specification for MappedDate.
+ */
+object MappedBooleanSpec extends Specification("MappedBoolean Specification") {
+ val provider = DbProviders.H2MemoryProvider
+
+ private def ignoreLogger(f: => AnyRef): Unit = ()
+ def setupDB {
+ provider.setupDB
+ Schemifier.destroyTables_!!(ignoreLogger _, Dog2, User)
+ Schemifier.schemify(true, ignoreLogger _, Dog2, User)
+ }
+
+ "MappedBoolean" should {
+ "not be marked dirty on read" in {
+ setupDB
+ val charlie = Dog2.create
+ charlie.isDog(true).save
+
+ val read = Dog2.find(charlie.dog2id).open_!
+ read.dirty_? must_== false
+ }
+
+ "be marked dirty on update if value has changed" in {
+ setupDB
+ val charlie = Dog2.create
+ charlie.save
+
+ val read = Dog2.find(charlie.dog2id).open_!
+ read.dirty_? must_== false
+ read.isDog(false)
+ read.dirty_? must_== false
+
+ read.isDog(true)
+ read.isDog(true)
+ read.dirty_? must_== true
+ }
+ }
+}
+
View
4 persistence/mapper/src/test/scala/net/liftweb/mapper/MappedDecimalSpec.scala
@@ -41,7 +41,6 @@ object MappedDecimalSpec extends Specification("MappedDecimal Specification") {
val charlie = Dog.create
charlie.price(42.42).save
- println("Reading")
val read = Dog.find(charlie.id).open_!
read.dirty_? must_== false
}
@@ -52,7 +51,8 @@ object MappedDecimalSpec extends Specification("MappedDecimal Specification") {
charlie.price(42.42).save
val read = Dog.find(charlie.id).open_!
-// read.dirty_? must_== false
+ read.dirty_? must_== false
+ read.price(100.42)
read.price(100.42)
read.dirty_? must_== true
}

0 comments on commit 9a0a4e8

Please sign in to comment.