Permalink
Browse files

fix custom class name logic.

  • Loading branch information...
robey committed Apr 12, 2013
1 parent 4bf44de commit b6d471e438dc1e2fc737b18374b570ba7b5212b7
Showing with 13 additions and 12 deletions.
  1. +2 −2 src/fauna/schema.coffee
  2. +3 −3 test/test_fauna_client.coffee
  3. +8 −7 test/test_schema.coffee
View
@@ -51,7 +51,7 @@ class ClassMetadata
# if a fauna class name isn't manually set, assume it's the lowercase
# version of the js class name + "s" (User -> users)
@className = @jsClass.toString().match(/function (\w+)/)[1].toLowerCase() + "s"
- @className
+ if @native then @className else "classes/#{@className}"
metadataForClass = (c) ->
@@ -88,6 +88,7 @@ class CustomEventSet extends EventSetWrapper
# builtin wrapper for "sets" class, with some helpers.
class EventSet extends Class
@faunaClass "sets"
+ @native()
toArray: ->
###
@@ -146,7 +147,6 @@ class Schema
inflate: (resource) ->
className = resource["class"]
- if className[0...8] == "classes/" then className = className[8...]
fclass = @classes[className]
obj = if fclass? then new fclass() else new Object()
@setFaunaData(obj, className, resource)
@@ -183,15 +183,15 @@ data2 =
]
references:
spooky:
- class: "cats"
+ class: "classes/cats"
data: { name: "Spooky" }
references: { friend: "commie" }
commie:
- class: "cats"
+ class: "classes/cats"
data: { name: "Commie" }
references: {}
simba:
- class: "cats"
+ class: "classes/cats"
data: { name: "Simba" }
references: { friend: "spooky" }
View
@@ -8,6 +8,7 @@ Q = require("q")
describe "Schema", ->
it "can turn a fauna object into js", ->
class User extends fauna.Class
+ @native()
@field "email"
username: -> @email.split("@")[0]
@@ -27,15 +28,15 @@ describe "Schema", ->
class Message extends fauna.Class
s = new fauna.Schema()
s.addPrototypes Message
- Object.keys(s.classes).should.eql [ "sets", "messages" ]
+ Object.keys(s.classes).should.eql [ "sets", "classes/messages" ]
it "can manually override the class name in fauna", ->
class Message extends fauna.Class
@faunaClass "msgs"
s = new fauna.Schema()
s.addPrototypes Message
- s.classNameFor(new Message()).should.eql("msgs")
- Object.keys(s.classes).should.eql [ "sets", "msgs" ]
+ s.classNameFor(new Message()).should.eql("classes/msgs")
+ Object.keys(s.classes).should.eql [ "sets", "classes/msgs" ]
it "can identify the fauna class for an object", ->
class Cat extends fauna.Class
@@ -44,7 +45,7 @@ describe "Schema", ->
s = new fauna.Schema()
s.addPrototypes Cat
- s.classNameFor(commie).should.eql("cats")
+ s.classNameFor(commie).should.eql("classes/cats")
it "serializes a created object correctly", ->
class Cat extends fauna.Class
@@ -71,7 +72,7 @@ describe "Schema", ->
result
Cat.getInstances(fakeFauna, count: 5).should.eql(result)
- rv.should.eql([ "cats", { count: 5 }])
+ rv.should.eql([ "classes/cats", { count: 5 }])
it "preserves the deleted flag", ->
resource =
@@ -94,7 +95,7 @@ describe "Schema", ->
s = new fauna.Schema()
s.addPrototypes Cat, User
- s.metadataForClassName("cats").native.should.eql(false)
+ s.metadataForClassName("classes/cats").native.should.eql(false)
s.metadataForClassName("users").native.should.eql(true)
it "can store config data", ->
@@ -103,7 +104,7 @@ describe "Schema", ->
@data whiskers: true, lives: 9
s = new fauna.Schema()
s.addPrototypes Cat
- s.metadataForClassName("cats").data.should.eql { whiskers: true, lives: 9 }
+ s.metadataForClassName("classes/cats").data.should.eql { whiskers: true, lives: 9 }
describe "EventSet", ->

0 comments on commit b6d471e

Please sign in to comment.