My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package couch.db

import org.scalatest.Spec
import org.scalatest.BeforeAndAfter
import org.scalatest.FeatureSuite
import org.scalatest.matchers.ShouldMatchers

import dispatch.json._
import dispatch.json.Js._
import couch.json._

class ScalaViewServerSpec extends Spec with ShouldMatchers with BeforeAndAfter {
val couch = Couch("127.0.0.1")
val test = Db("test_db")

override def beforeAll {
couch(test.create)
println(couch(test as_str))
println("** created database")
}

override def afterAll {
couch(test.delete)
println("** destroyed database")
}

describe("create records") {
it("should create new records") {
couch(test doc Js("""{"item":"banana","prices":{"Fresh Mart":1.99,"Price Max":0.79,"Banana Montana":4.22}}"""))
couch(test doc Js("""{"item":"apple","prices":{"Fresh Mart":1.59,"Price Max":5.99,"Apples Express":0.79}}"""))
couch(test doc Js("""{"item":"orange","prices":{"Fresh Mart":1.99,"Price Max":3.19,"Citrus Circus":1.09}}"""))
}
}

describe("Create a design document, for scala view") {
val d = DesignDocument("power", null, Map[String, View]())
d.language = "scala"
val mapfn1 = """(doc: dispatch.json.JsValue) => {
val it = couch.json.JsBean.toBean(doc, classOf[couch.json.TestBeans.Item_1])._3;
for (st <- it.prices)
yield(List(it.item, st._2))
}"""

val mapfn2 = """(doc: dispatch.json.JsValue) => {
import dispatch.json.Js._;
val x = Symbol("item") ? dispatch.json.Js.str;
val x(x_) = doc;
val i = Symbol("_id") ? dispatch.json.Js.str;
val i(i_) = doc;
List(List(i_, x_)) ;
}"""

val vi_1 = new View(mapfn1, null)
val vi_2 = new View(mapfn2, null)

var revision: String = null
var nir: (String, String) = null
val de = Doc(test, d._id)

it("creation should be successful") {
d._id should equal("_design/power")
couch(de add d)
val ir = couch(de ># %(Id._id, Id._rev))
ir._1 should equal(d._id)
}
it("query by id should fetch the document") {
val ir = couch(test by_id d._id)
ir._1 should equal(d._id)
val sh = couch(test by_id(d._id, classOf[DesignDocument]))
sh._1 should equal(d._id)
sh._2 should equal(ir._2)
sh._3._id should equal(sh._1)
sh._3._rev should equal(sh._2)
revision = sh._2
}
it("update the document with 2 views") {
val doc = DesignDocument(d._id, revision, Map("power_lunch" -> vi_1, "mega_lunch" -> vi_2))
doc.language = "scala"
couch(de update(doc, revision))
nir = couch(de ># %(Id._id, Id._rev))
nir._1 should equal(d._id)
nir._2 should not equal(revision)
}
it("should fetch 9 rows from view power_lunch") {
val ls1 = couch(test view(
Views builder("power/power_lunch") build))
println(ls1)
ls1.size should equal(9)
}
it("should fetch 3 rows from view mega_lunch") {
val ls1 = couch(test view(
Views builder("power/mega_lunch") build))
println(ls1)
ls1.size should equal(3)
}
}
}
Show details Hide details

Change log

r13 by ghosh.debasish on May 17, 2009   Diff
commit for release 0.3
- bugs fixed
- view server added (map only)
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 3185 bytes, 97 lines
Hosted by Google Code