got view queries happening correctly
This commit is contained in:
parent
32ffbfe019
commit
19a70ffd7d
7 changed files with 106 additions and 60 deletions
|
@ -418,6 +418,9 @@ describe CouchRest::Database do
|
|||
@db.delete doc
|
||||
lambda{@db.get @docid}.should raise_error
|
||||
end
|
||||
it "should fail without an _id" do
|
||||
lambda{@db.delete({"not"=>"a real doc"})}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
it "should list documents" do
|
||||
|
|
|
@ -2,22 +2,13 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
|
||||
describe CouchRest::Design do
|
||||
|
||||
# before(:each) do
|
||||
# @db = reset_test_db!
|
||||
# end
|
||||
|
||||
describe "defining a view" do
|
||||
# before(:each) do
|
||||
# @design_docs = @db.documents :startkey => "_design/",
|
||||
# :endkey => "_design/\u9999"
|
||||
# end
|
||||
it "should add a view to the design doc" do
|
||||
@des = CouchRest::Design.new
|
||||
method = @des.view_by :name
|
||||
method.should == "by_name"
|
||||
@des["views"]["by_name"].should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "with an unsaved view" do
|
||||
|
@ -25,9 +16,9 @@ describe CouchRest::Design do
|
|||
@des = CouchRest::Design.new
|
||||
method = @des.view_by :name
|
||||
end
|
||||
it "should accept a slug" do
|
||||
@des.slug = "mytest"
|
||||
@des.slug.should == "mytest"
|
||||
it "should accept a name" do
|
||||
@des.name = "mytest"
|
||||
@des.name.should == "mytest"
|
||||
end
|
||||
it "should not save on view definition" do
|
||||
@des.rev.should be_nil
|
||||
|
@ -37,6 +28,21 @@ describe CouchRest::Design do
|
|||
end
|
||||
end
|
||||
|
||||
describe "saving" do
|
||||
before(:each) do
|
||||
@des = CouchRest::Design.new
|
||||
method = @des.view_by :name
|
||||
@des.database = reset_test_db!
|
||||
end
|
||||
it "should fail without a name" do
|
||||
lambda{@des.save}.should raise_error(ArgumentError)
|
||||
end
|
||||
it "should work with a name" do
|
||||
@des.name = "myview"
|
||||
@des.save
|
||||
end
|
||||
end
|
||||
|
||||
describe "when it's saved" do
|
||||
before(:each) do
|
||||
@db = reset_test_db!
|
||||
|
@ -45,11 +51,8 @@ describe CouchRest::Design do
|
|||
@des.database = @db
|
||||
method = @des.view_by :name
|
||||
end
|
||||
it "should become angry when saved without a slug" do
|
||||
lambda{@des.save}.should raise_error
|
||||
end
|
||||
it "should by queryable when it's saved" do
|
||||
@des.slug = "mydesign"
|
||||
@des.name = "mydesign"
|
||||
@des.save
|
||||
res = @des.view :by_name
|
||||
res["rows"][0]["key"].should == "x"
|
||||
|
@ -73,9 +76,9 @@ describe CouchRest::Design do
|
|||
it "should be a Design" do
|
||||
@des.should be_an_instance_of CouchRest::Design
|
||||
end
|
||||
it "should have a slug" do
|
||||
@des.slug.should == "test"
|
||||
@des.slug = "supertest"
|
||||
it "should have a modifiable name" do
|
||||
@des.name.should == "test"
|
||||
@des.name = "supertest"
|
||||
@des.id.should == "_design/supertest"
|
||||
end
|
||||
it "should by queryable" do
|
||||
|
@ -83,4 +86,45 @@ describe CouchRest::Design do
|
|||
res["rows"][0]["key"].should == "a"
|
||||
end
|
||||
end
|
||||
|
||||
describe "a view with default options" do
|
||||
before(:all) do
|
||||
@db = reset_test_db!
|
||||
@des = CouchRest::Design.new
|
||||
@des.name = "test"
|
||||
method = @des.view_by :name, :descending => true
|
||||
@des.database = @db
|
||||
@des.save
|
||||
@db.bulk_save([{"name" => "a"},{"name" => "z"}])
|
||||
end
|
||||
it "should save them" do
|
||||
@d2 = @db.get(@des.id)
|
||||
@d2["views"]["by_name"]["couchrest-defaults"].should == {"descending"=>true}
|
||||
end
|
||||
it "should use them" do
|
||||
res = @des.view :by_name
|
||||
res["rows"].first["key"].should == "z"
|
||||
end
|
||||
it "should override them" do
|
||||
res = @des.view :by_name, :descending => false
|
||||
res["rows"].first["key"].should == "a"
|
||||
end
|
||||
end
|
||||
|
||||
describe "a view with multiple keys" do
|
||||
before(:all) do
|
||||
@db = reset_test_db!
|
||||
@des = CouchRest::Design.new
|
||||
@des.name = "test"
|
||||
method = @des.view_by :name, :age
|
||||
@des.database = @db
|
||||
@des.save
|
||||
@db.bulk_save([{"name" => "a", "age" => 2},{"name" => "a", "age" => 4},{"name" => "z", "age" => 9}])
|
||||
end
|
||||
it "should work" do
|
||||
res = @des.view :by_name_and_age
|
||||
res["rows"].first["key"].should == ["a",2]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -44,7 +44,7 @@ describe CouchRest::Document, "saving using a database" do
|
|||
@db = reset_test_db!
|
||||
@resp = @db.save(@doc)
|
||||
end
|
||||
it "should get the database" do
|
||||
it "should apply the database" do
|
||||
@doc.database.should == @db
|
||||
end
|
||||
it "should get id and rev" do
|
||||
|
@ -67,9 +67,30 @@ describe "getting from a database" do
|
|||
it "should have a database" do
|
||||
@doc.database.should == @db
|
||||
end
|
||||
it "should be saveable" do
|
||||
it "should be saveable and resavable" do
|
||||
@doc["more"] = "keys"
|
||||
@doc.save
|
||||
@db.get(@resp['id'])["more"].should == "keys"
|
||||
@doc["more"] = "these keys"
|
||||
@doc.save
|
||||
@db.get(@resp['id'])["more"].should == "these keys"
|
||||
end
|
||||
end
|
||||
|
||||
describe "destroying a document from a db" do
|
||||
before(:all) do
|
||||
@db = reset_test_db!
|
||||
@resp = @db.save({
|
||||
"key" => "value"
|
||||
})
|
||||
@doc = @db.get @resp['id']
|
||||
end
|
||||
it "should make it disappear" do
|
||||
@doc.destroy
|
||||
lambda{@db.get @resp['id']}.should raise_error
|
||||
end
|
||||
it "should error when there's no db" do
|
||||
@doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
|
||||
lambda{@doc.destroy}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
__END__
|
||||
class Basic < CouchRest::Model
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue