get views
This commit is contained in:
parent
dfff6f3d8b
commit
c3b6e3e2d0
|
@ -10,19 +10,15 @@ class CouchRest
|
||||||
end
|
end
|
||||||
|
|
||||||
def documents
|
def documents
|
||||||
view "_all_docs"
|
CouchRest.get "#{@root}/_all_docs"
|
||||||
end
|
end
|
||||||
|
|
||||||
def temp_view func
|
def temp_view func
|
||||||
# CouchRest.post "#{@root}/_temp_view", func
|
|
||||||
# headers: {"Content-Type": "text/javascript"},
|
|
||||||
# ripping from CouchRest because leaky abstraction.
|
|
||||||
# payload = JSON.unparse doc if doc
|
|
||||||
JSON.parse(RestClient.post("#{@root}/_temp_view", func, {"Content-Type" => "text/javascript"}))
|
JSON.parse(RestClient.post("#{@root}/_temp_view", func, {"Content-Type" => "text/javascript"}))
|
||||||
end
|
end
|
||||||
|
|
||||||
def view name
|
def view name
|
||||||
CouchRest.get "#{@root}/#{name}"
|
CouchRest.get "#{@root}/_view/#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get id
|
def get id
|
||||||
|
|
|
@ -30,6 +30,24 @@ describe CouchRest::Database do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "select from an existing view" do
|
||||||
|
before(:each) do
|
||||||
|
r = @db.save({"_id" => "_design/first", "views" => {"test" => "function(doc){for(var w in doc){ if(!w.match(/^_/))map(w,doc[w])}}"}})
|
||||||
|
@db.bulk_save([
|
||||||
|
{"wild" => "and random"},
|
||||||
|
{"mild" => "yet local"},
|
||||||
|
{"another" => ["set","of","keys"]}
|
||||||
|
])
|
||||||
|
end
|
||||||
|
it "should have the view" do
|
||||||
|
@db.get('_design/first')['views']['test'].should == "function(doc){for(var w in doc){ if(!w.match(/^_/))map(w,doc[w])}}"
|
||||||
|
end
|
||||||
|
it "should list from the view" do
|
||||||
|
rs = @db.view('first/test')
|
||||||
|
rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "GET (document by id) when the doc exists" do
|
describe "GET (document by id) when the doc exists" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@r = @db.save({'lemons' => 'from texas', 'and' => 'spain'})
|
@r = @db.save({'lemons' => 'from texas', 'and' => 'spain'})
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title></title>
|
<title>CouchRest - a simple CouchDB Client</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>
|
<h1>
|
||||||
CouchRest - a simple CouchDB Client
|
CouchRest - a simple CouchDB Client
|
||||||
</h1>
|
</h1>
|
||||||
<p>
|
<p>
|
||||||
The stuff
|
CouchDB is sweet. It doesn't take much Ruby to make it easy.
|
||||||
</p>
|
</p>
|
||||||
|
<h2>Sweet and easy.</h2>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue