database replication methods, no conflict resolution provided

This commit is contained in:
Matt Lyon 2009-01-31 10:38:44 -08:00 committed by Chris Anderson
parent e9f7456eab
commit 571cd257e0
2 changed files with 44 additions and 1 deletions

View file

@ -213,7 +213,19 @@ module CouchRest
def compact! def compact!
CouchRest.post "#{@root}/_compact" CouchRest.post "#{@root}/_compact"
end end
# Replicates via "pulling" from another database to this database. Makes no attempt to deal with conflicts.
def replicate_from other_db
raise ArgumentError, "must provide a CouchReset::Database" unless other_db.kind_of?(CouchRest::Database)
CouchRest.post "#{@host}/_replicate", :source => other_db.root, :target => name
end
# Replicates via "pushing" to another database. Makes no attempt to deal with conflicts.
def replicate_to other_db
raise ArgumentError, "must provide a CouchReset::Database" unless other_db.kind_of?(CouchRest::Database)
CouchRest.post "#{@host}/_replicate", :target => other_db.root, :source => name
end
# DELETE the database itself. This is not undoable and could be rather # DELETE the database itself. This is not undoable and could be rather
# catastrophic. Use with care! # catastrophic. Use with care!
def delete! def delete!

View file

@ -624,6 +624,37 @@ describe CouchRest::Database do
@cr.databases.should_not include('couchrest-test') @cr.databases.should_not include('couchrest-test')
end end
end end
describe "replicating a database" do
before do
@db.save({'_id' => 'test_doc', 'some-value' => 'foo'})
@other_db = @cr.database 'couchrest-test-replication'
@other_db.delete! rescue nil
@other_db = @cr.create_db 'couchrest-test-replication'
end
describe "via pulling" do
before do
@other_db.replicate_from @db
end
it "contains the document from the original database" do
doc = @other_db.get('test_doc')
doc['some-value'].should == 'foo'
end
end
describe "via pushing" do
before do
@db.replicate_to @other_db
end
it "copies the document to the other database" do
doc = @other_db.get('test_doc')
doc['some-value'].should == 'foo'
end
end
end
end end