Patching in fixes for missing uri scheme in CouchRest.parse and adding support for continuous replication

This commit is contained in:
sauy7 2010-03-10 10:24:28 +01:00 committed by Will Leinweber
parent 0d0a8ae6b8
commit 3c314e14d0
5 changed files with 98 additions and 99 deletions

View file

@ -46,137 +46,74 @@ describe CouchRest do
it "should parse just a dbname" do
db = CouchRest.parse "my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5984"
db[:host].should == "http://127.0.0.1:5984"
end
it "should parse a host and db" do
db = CouchRest.parse "127.0.0.1/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1"
end
it "should parse a host and db with http" do
db = CouchRest.parse "https://127.0.0.1/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1"
end
it "should parse a host with a port and db" do
db = CouchRest.parse "127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
end
it "should parse a host with a port and db with http" do
db = CouchRest.parse "http://127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
end
it "should parse a host with a port and db with https" do
db = CouchRest.parse "https://127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host" do
db = CouchRest.parse "http://127.0.0.1:5555/"
db[:database].should be_nil
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host with https" do
db = CouchRest.parse "https://127.0.0.1:5555/"
db[:database].should be_nil
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host no slash" do
db = CouchRest.parse "http://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555"
db[:database].should be_nil
end
it "should parse just a host no slash and https" do
db = CouchRest.parse "https://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555"
db[:database].should be_nil
end
it "should get docid" do
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc"
end
it "should get docid with http" do
db = CouchRest.parse "http://127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc"
end
it "should get docid with https" do
db = CouchRest.parse "https://127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc"
end
it "should parse a host and db" do
db = CouchRest.parse "127.0.0.1/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1"
db[:host].should == "http://127.0.0.1"
end
it "should parse a host and db with http" do
db = CouchRest.parse "http://127.0.0.1/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1"
db[:host].should == "http://127.0.0.1"
end
it "should parse a host and db with https" do
db = CouchRest.parse "https://127.0.0.1/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1"
db[:host].should == "https://127.0.0.1"
end
it "should parse a host with a port and db" do
db = CouchRest.parse "127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:host].should == "http://127.0.0.1:5555"
end
it "should parse a host with a port and db with http" do
db = CouchRest.parse "http://127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:host].should == "http://127.0.0.1:5555"
end
it "should parse a host with a port and db with https" do
db = CouchRest.parse "http://127.0.0.1:5555/my-db"
db = CouchRest.parse "https://127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:host].should == "https://127.0.0.1:5555"
end
it "should parse just a host" do
db = CouchRest.parse "http://127.0.0.1:5555/"
db[:database].should be_nil
db[:host].should == "127.0.0.1:5555"
db[:host].should == "http://127.0.0.1:5555"
end
it "should parse just a host with https" do
db = CouchRest.parse "https://127.0.0.1:5555/"
db[:database].should be_nil
db[:host].should == "127.0.0.1:5555"
db[:host].should == "https://127.0.0.1:5555"
end
it "should parse just a host no slash" do
db = CouchRest.parse "http://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555"
db[:host].should == "http://127.0.0.1:5555"
db[:database].should be_nil
end
it "should parse just a host no slash and https" do
db = CouchRest.parse "https://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555"
db[:host].should == "https://127.0.0.1:5555"
db[:database].should be_nil
end
it "should get docid" do
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:host].should == "http://127.0.0.1:5555"
db[:doc].should == "my-doc"
end
it "should get docid with http" do
db = CouchRest.parse "http://127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:host].should == "http://127.0.0.1:5555"
db[:doc].should == "my-doc"
end
it "should get docid with https" do
db = CouchRest.parse "https://127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:host].should == "https://127.0.0.1:5555"
db[:doc].should == "my-doc"
end
end
@ -185,7 +122,7 @@ describe CouchRest do
it "should be possible without an explicit CouchRest instantiation" do
db = CouchRest.database "http://127.0.0.1:5984/couchrest-test"
db.should be_an_instance_of(CouchRest::Database)
db.host.should == "127.0.0.1:5984"
db.host.should == "http://127.0.0.1:5984"
end
# TODO add https support (need test environment...)
# it "should work with https" # do

View file

@ -703,12 +703,12 @@ describe CouchRest::Database do
end
end
describe "replicating a database" do
describe "simply replicating a database" do
before do
@db.save_doc({'_id' => 'test_doc', 'some-value' => 'foo'})
@other_db = @cr.database 'couchrest-test-replication'
@other_db = @cr.database REPLICATIONDB
@other_db.delete! rescue nil
@other_db = @cr.create_db 'couchrest-test-replication'
@other_db = @cr.create_db REPLICATIONDB
end
describe "via pulling" do
@ -733,6 +733,53 @@ describe CouchRest::Database do
end
end
end
describe "continuously replicating a database" do
before do
@db.save_doc({'_id' => 'test_doc', 'some-value' => 'foo'})
@other_db = @cr.database REPLICATIONDB
@other_db.delete! rescue nil
@other_db = @cr.create_db REPLICATIONDB
end
describe "via pulling" do
before do
@other_db.replicate_from @db, true
end
it "contains the document from the original database" do
sleep(1) # Allow some time to replicate
doc = @other_db.get('test_doc')
doc['some-value'].should == 'foo'
end
it "contains documents saved after replication initiated" do
@db.save_doc({'_id' => 'test_doc_after', 'some-value' => 'bar'})
sleep(1) # Allow some time to replicate
doc = @other_db.get('test_doc_after')
doc['some-value'].should == 'bar'
end
end
describe "via pushing" do
before do
@db.replicate_to @other_db, true
end
it "copies the document to the other database" do
sleep(1) # Allow some time to replicate
doc = @other_db.get('test_doc')
doc['some-value'].should == 'foo'
end
it "copies documents saved after replication initiated" do
@db.save_doc({'_id' => 'test_doc_after', 'some-value' => 'bar'})
sleep(1) # Allow some time to replicate
doc = @other_db.get('test_doc_after')
doc['some-value'].should == 'bar'
end
end
end
describe "creating a database" do
before(:each) do