Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

finish out classes.

  • Loading branch information...
commit 1945393709598fe869d26f0b92165f05d0a7bcee 1 parent 9376d6f
@robey authored
Showing with 51 additions and 0 deletions.
  1. +3 −0  src/fauna/fauna_client.coffee
  2. +48 −0 test/test_classes.coffee
View
3  src/fauna/fauna_client.coffee
@@ -154,6 +154,9 @@ class FaunaClient
class _Classes
get: requirePublisher asEventArray -> @rest("get", "classes")
getByName: requireTokenOrPublisher asObject (name) -> @rest("get", "classes/#{name}/config")
+ create: requirePublisher asObject (name, data) -> @rest("put", "classes/#{name}/config", data)
+ deleteByName: requirePublisher (name) -> @rest("delete", "classes/#{name}/config")
+ getStats: requirePublisher asObject (name) -> @rest("get", "classes/#{name}/stats")
# wrapper to allow easy testing of the decorators
class _Testing
View
48 test/test_classes.coffee
@@ -30,10 +30,47 @@ describe "FaunaClient.classes", ->
r = -> f.classes.getByName("magical_creatures")
withSuccessfulRequest(JSON.parse(data2), r).then ([ resp, requests ]) ->
requests.length.should.eql(1)
+ requests[0].method.should.eql("GET")
requests[0].url.should.match(/\/classes\/magical_creatures\/config/)
resp.name.should.eql "magical_creatures"
resp.desc.should.eql "Any of many mysterious beasts."
+ it "create", futureTest ->
+ f = new fauna.FaunaClient()
+ class ClassConfig extends fauna.Class
+ @faunaClass "config"
+ @field "desc"
+ f.addPrototypes ClassConfig
+ f.setPublisherKey("qqq")
+ r = -> f.classes.create("magical_creatures", desc: "Any of many mysterious beasts.")
+ withSuccessfulRequest(JSON.parse(data2), r).then ([ resp, requests ]) ->
+ requests.length.should.eql(1)
+ requests[0].method.should.eql("PUT")
+ requests[0].url.should.match(/\/classes\/magical_creatures\/config/)
+ resp.name.should.eql "magical_creatures"
+ resp.desc.should.eql "Any of many mysterious beasts."
+
+ it "deleteByName", futureTest ->
+ f = new fauna.FaunaClient()
+ f.setPublisherKey("qqq")
+ r = -> f.classes.deleteByName("ordinary_creatures")
+ handler = (options) -> [ null, 204, null ]
+ fauna.Rest.withRequestHandler(handler, r).then ([ resp, requests ]) ->
+ requests.length.should.eql(1)
+ requests[0].method.should.eql("DELETE")
+ requests[0].url.should.match(/\/classes\/ordinary_creatures\/config/)
+
+ it "getStats", futureTest ->
+ f = new fauna.FaunaClient()
+ f.setPublisherKey("qqq")
+ r = -> f.classes.getStats("magical_creatures")
+ withSuccessfulRequest(JSON.parse(data3), r).then ([ resp, requests ]) ->
+ requests.length.should.eql(1)
+ requests[0].method.should.eql("GET")
+ requests[0].url.should.match(/\/classes\/magical_creatures\/stats/)
+ resp.instances.should.eql(1)
+ resp["sets/config"].should.eql(0)
+
data1 = """
{
@@ -98,3 +135,14 @@ data2 = """
}
}
"""
+
+data3 = """
+{
+ "resource" : {
+ "ref" : "classes/magical_creatures/stats",
+ "class" : "classes/stats",
+ "instances" : 1,
+ "sets/config" : 0
+ }
+}
+"""
Please sign in to comment.
Something went wrong with that request. Please try again.