Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: lift/framework
...
head fork: lift/framework
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
10 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/Fixtures.scala
@@ -25,7 +25,7 @@ import common._
import json._
import json.ext.{EnumSerializer, JsonBoxSerializer}
import http.SHtml
-import util.FieldError
+import util.{FieldError, Helpers}
import java.math.MathContext
import scala.xml.Text
@@ -421,3 +421,11 @@ class JObjectFieldTestRecord private () extends MongoRecord[JObjectFieldTestReco
object JObjectFieldTestRecord extends JObjectFieldTestRecord with MongoMetaRecord[JObjectFieldTestRecord] {
override def formats = allFormats
}
+
+class CustomFieldName private () extends MongoRecord[CustomFieldName] with ObjectIdPk[CustomFieldName] {
+ def meta = CustomFieldName
+
+ object customField extends StringField(this, 256)
+}
+
+object CustomFieldName extends CustomFieldName with MongoMetaRecord[CustomFieldName]
View
15 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoRecordSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2013 WorldWide Conferencing, LLC
+ * Copyright 2010-2014 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.
@@ -31,7 +31,9 @@ import http.{S, LiftSession}
import http.js.JsExp
import json._
import JsonDSL._
+import util.Helpers.snakify
+import net.liftweb.record.RecordRules
import net.liftweb.record.field.Countries
import com.mongodb._
@@ -918,6 +920,15 @@ class MongoRecordSpec extends Specification with MongoTestKit {
rec.dirty_? must_== false
}
}
+
+ "support custom field name" in {
+ RecordRules.fieldName.doWith(snakify _) {
+ val rec = CustomFieldName.createRecord
+ rec.customField.name must_== "custom_field"
+ rec.save
+
+ CustomFieldName.find(rec.id.get) must_== Full(rec)
+ }
+ }
}
}
-
View
2  persistence/record/src/main/scala/net/liftweb/record/Field.scala
@@ -56,7 +56,7 @@ trait BaseField extends FieldIdentifier with util.BaseField {
/**
* The text name of this field
*/
- def name: String = fieldName
+ def name: String = RecordRules.fieldName.vend.apply(fieldName)
/**
* Can the value of this field be read without obscuring the result?
View
34 persistence/record/src/main/scala/net/liftweb/record/RecordRules.scala
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013 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 record
+
+import http.Factory
+import util.Helpers._
+
+object RecordRules extends Factory {
+ /**
+ * Calculate the name of a field based on the name
+ * of the Field. Must be set in Boot before any code
+ * that touches the MetaRecord.
+ *
+ * To get snake_case, use this:
+ *
+ * RecordRules.fieldName.default.set((name) => StringHelpers.snakify(name))
+ */
+ val fieldName = new FactoryMaker[(String) => String]((name: String) => name) {}
+}
View
4 persistence/record/src/test/scala/net/liftweb/record/Fixtures.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2012 WorldWide Conferencing, LLC
+ * Copyright 2010-2014 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.
@@ -33,7 +33,7 @@ class BasicTestRecord private () extends Record[BasicTestRecord] {
object field1 extends StringField(this,10)
object field2 extends StringField(this,10)
- object field3 extends StringField(this,10)
+ object fieldThree extends StringField(this,10)
}
object BasicTestRecord extends BasicTestRecord with MetaRecord[BasicTestRecord] {
View
46 persistence/record/src/test/scala/net/liftweb/record/RecordRulesSpec.scala
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2014 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 record
+
+import common._
+import http.{LiftSession, S}
+import util.Helpers._
+
+import org.specs2.mutable._
+import org.specs2.specification.Fragment
+
+import fixtures._
+
+
+/**
+ * Systems under specification for RecordField.
+ */
+object RecordRulesSpec extends Specification {
+ "Record Rules Specification".title
+ sequential
+
+ "RecordRules" should {
+ "snakify custom field name" in {
+ RecordRules.fieldName.doWith(snakify _) {
+ val rec = BasicTestRecord.createRecord
+
+ rec.fieldThree.name must_== "field_three"
+ }
+ }
+ }
+}
View
4 persistence/record/src/test/scala/net/liftweb/record/RecordSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2012 WorldWide Conferencing, LLC
+ * Copyright 2010-2014 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.
@@ -352,7 +352,7 @@ object RecordSpec extends Specification {
"basic record" should {
"order fields according to fieldOrder" in {
- BasicTestRecord.metaFields must_== List(BasicTestRecord.field2, BasicTestRecord.field1, BasicTestRecord.field3)
+ BasicTestRecord.metaFields must_== List(BasicTestRecord.field2, BasicTestRecord.field1, BasicTestRecord.fieldThree)
}
}
}

No commit comments for this range

Something went wrong with that request. Please try again.