2008-07-05 01:56:09 +02:00
|
|
|
require File.dirname(__FILE__) + '/spec_helper'
|
2008-03-18 19:37:10 +01:00
|
|
|
|
|
|
|
describe CouchRest do
|
|
|
|
|
|
|
|
before(:each) do
|
2008-07-05 01:56:09 +02:00
|
|
|
@cr = CouchRest.new(COUCHHOST)
|
2008-03-18 19:37:10 +01:00
|
|
|
begin
|
2008-07-05 01:56:09 +02:00
|
|
|
@db = @cr.database(TESTDB)
|
2008-07-19 21:25:02 +02:00
|
|
|
@db.delete! rescue nil
|
2008-03-19 16:57:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
begin
|
2008-07-19 21:25:02 +02:00
|
|
|
@db.delete! rescue nil
|
2008-03-18 19:37:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "getting info" do
|
|
|
|
it "should list databases" do
|
|
|
|
@cr.databases.should be_an_instance_of(Array)
|
|
|
|
end
|
|
|
|
it "should get info" do
|
2008-05-15 02:27:21 +02:00
|
|
|
@cr.info["couchdb"].should == "Welcome"
|
2008-03-18 19:37:10 +01:00
|
|
|
@cr.info.class.should == Hash
|
|
|
|
end
|
|
|
|
end
|
2008-06-15 20:43:05 +02:00
|
|
|
|
|
|
|
describe "description" do
|
|
|
|
it "should restart" do
|
|
|
|
@cr.restart!
|
|
|
|
end
|
|
|
|
end
|
2008-03-18 19:37:10 +01:00
|
|
|
|
|
|
|
describe "initializing a database" do
|
|
|
|
it "should return a db" do
|
2008-07-05 01:56:09 +02:00
|
|
|
db = @cr.database(TESTDB)
|
2008-03-18 19:37:10 +01:00
|
|
|
db.should be_an_instance_of(CouchRest::Database)
|
|
|
|
db.host.should == @cr.uri
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "successfully creating a database" do
|
|
|
|
it "should start without a database" do
|
2008-07-05 01:56:09 +02:00
|
|
|
@cr.databases.should_not include(TESTDB)
|
2008-03-18 19:37:10 +01:00
|
|
|
end
|
|
|
|
it "should return the created database" do
|
2008-07-05 01:56:09 +02:00
|
|
|
db = @cr.create_db(TESTDB)
|
2008-03-18 19:37:10 +01:00
|
|
|
db.should be_an_instance_of(CouchRest::Database)
|
|
|
|
end
|
|
|
|
it "should create the database" do
|
2008-07-05 01:56:09 +02:00
|
|
|
db = @cr.create_db(TESTDB)
|
|
|
|
@cr.databases.should include(TESTDB)
|
2008-03-18 19:37:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "failing to create a database because the name is taken" do
|
|
|
|
before(:each) do
|
2008-07-05 01:56:09 +02:00
|
|
|
db = @cr.create_db(TESTDB)
|
2008-03-18 19:37:10 +01:00
|
|
|
end
|
|
|
|
it "should start with the test database" do
|
2008-07-05 01:56:09 +02:00
|
|
|
@cr.databases.should include(TESTDB)
|
2008-03-18 19:37:10 +01:00
|
|
|
end
|
|
|
|
it "should PUT the database and raise an error" do
|
|
|
|
lambda{
|
2008-07-05 01:56:09 +02:00
|
|
|
@cr.create_db(TESTDB)
|
2008-03-18 19:37:10 +01:00
|
|
|
}.should raise_error(RestClient::Request::RequestFailed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|