spec/integration/ripple/conflict_resolution_spec.rb in ripple-1.0.0.beta vs spec/integration/ripple/conflict_resolution_spec.rb in ripple-1.0.0.beta2

- old
+ new

@@ -35,15 +35,12 @@ class ConflictedJob include Ripple::EmbeddedDocument property :title, String end - before :all do - ConflictedPerson.bucket.allow_mult = true - end - before(:each) do + ConflictedPerson.bucket.allow_mult ||= true ConflictedPerson.on_conflict { } # reset to no-op end context 'when there is no conflict' do it 'does not invoke the on_conflict hook' do @@ -72,9 +69,43 @@ :coworkers => [ConflictedPerson.create!(:name => 'Horace', :gender => 'male')], :mother => ConflictedPerson.create!(:name => 'Serena', :gender => 'female'), :created_at => created_at, :updated_at => updated_at ) + end + + context 'for a document that has a deleted sibling' do + before(:each) do + create_conflict original_person, + lambda { |p| p.destroy! }, + lambda { |p| p.age = 20 }, + lambda { |p| p.age = 30 } + end + + it 'indicates that one of the siblings was deleted' do + siblings = nil + ConflictedPerson.on_conflict { |s, c| siblings = s } + ConflictedPerson.find('John') + + siblings.should have(3).sibling_records + deleted, undeleted = siblings.partition(&:deleted?) + deleted.should have(1).record + undeleted.should have(2).records + deleted = deleted.first + + # the deleted record should be totally blank except for the name (since it is the key) + deleted.attributes.reject { |k, v| v.blank? }.should == {"name" => "John"} + end + + it 'does not consider the deleted sibling when trying basic resolution of attributes that siblings are in agreement about' do + record = conflicts = nil + ConflictedPerson.on_conflict { |s, c| conflicts = c; record = self } + ConflictedPerson.find('John') + + conflicts.should == [:age] + record.gender.should == 'male' + record.favorite_colors.should == ['green'].to_set + end end context 'for a document that has conflicted attributes' do let(:most_recent_updated_at) { DateTime.new(2011, 6, 4, 12, 30) } let(:earliest_created_at) { DateTime.new(2010, 5, 3, 12, 30) }