on the road toward design docs

This commit is contained in:
Chris Anderson 2008-11-08 16:28:58 -08:00
parent 04e818c154
commit 0769c2690f
10 changed files with 454 additions and 189 deletions

View file

@ -21,9 +21,55 @@ describe CouchRest::Document, "[]=" do
end
describe CouchRest::Document, "new" do
before(:each) do
@doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
end
it "should create itself from a Hash" do
@doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
@doc["key"].should == [1,2,3]
@doc["more"].should == "values"
end
it "should not have rev and id" do
@doc.rev.should be_nil
@doc.id.should be_nil
end
it "should freak out when saving without a database" do
lambda{@doc.save}.should raise_error(ArgumentError)
end
end
# move to database spec
describe CouchRest::Document, "saving using a database" do
before(:all) do
@doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
@db = reset_test_db!
@resp = @db.save(@doc)
end
it "should get the database" do
@doc.database.should == @db
end
it "should get id and rev" do
@doc.id.should == @resp["id"]
@doc.rev.should == @resp["rev"]
end
end
describe "getting from a database" do
before(:all) do
@db = reset_test_db!
@resp = @db.save({
"key" => "value"
})
@doc = @db.get @resp['id']
end
it "should return a document" do
@doc.should be_an_instance_of(CouchRest::Document)
end
it "should have a database" do
@doc.database.should == @db
end
it "should be saveable" do
@doc["more"] = "keys"
@doc.save
@db.get(@resp['id'])["more"].should == "keys"
end
end