-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preventInvertInRollback option #443
Closed
antoinelyset
wants to merge
1
commit into
share:master
from
antoinelyset:prevent-invert-in-rollback-option
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -474,5 +474,74 @@ describe('Doc', function() { | |||||
} | ||||||
], done); | ||||||
}); | ||||||
|
||||||
describe('with an op collision', function() { | ||||||
function testScenario(preventInvertInRollback, done) { | ||||||
var doc1 = this.backend.connect().get('dogs', 'snoopy'); | ||||||
var doc2 = this.backend.connect().get('dogs', 'snoopy'); | ||||||
doc2.preventInvertInRollback = preventInvertInRollback; | ||||||
|
||||||
var pauseSubmit = false; | ||||||
var fireSubmit; | ||||||
var invertHaveBeenCalled = false; | ||||||
|
||||||
this.backend.use('submit', function(request, callback) { | ||||||
if (pauseSubmit) { | ||||||
fireSubmit = function() { | ||||||
pauseSubmit = false; | ||||||
callback(); | ||||||
}; | ||||||
} else { | ||||||
fireSubmit = null; | ||||||
callback(); | ||||||
} | ||||||
}); | ||||||
async.series([ | ||||||
doc1.create.bind(doc1, {colours: ['white']}), | ||||||
doc1.whenNothingPending.bind(doc1), | ||||||
doc2.fetch.bind(doc2), | ||||||
doc2.whenNothingPending.bind(doc2), | ||||||
function(next) { | ||||||
// Wrap invert to test that it has been called | ||||||
var originalInvert = doc2.type.invert; | ||||||
doc2.type.invert = function(op) { | ||||||
invertHaveBeenCalled = true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return originalInvert(op); | ||||||
}; | ||||||
next(); | ||||||
}, | ||||||
doc1.submitOp.bind(doc1, {p: ['colours'], oi: 'white,black'}), | ||||||
function(next) { | ||||||
pauseSubmit = true; | ||||||
doc2.submitOp({p: ['colours', '0'], li: 'black'}, function(error) { | ||||||
expect(error.message).to.equal('Referenced element not a list'); | ||||||
next(); | ||||||
}); | ||||||
|
||||||
doc2.fetch(function(error) { | ||||||
if (error) return next(error); | ||||||
fireSubmit(); | ||||||
}); | ||||||
}, | ||||||
function(next) { | ||||||
expect(invertHaveBeenCalled).to.eql(!preventInvertInRollback); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
expect(doc2.data).to.eql(doc1.data); | ||||||
next(); | ||||||
} | ||||||
], done); | ||||||
} | ||||||
|
||||||
it('calls doc type invert by default', function(done) { | ||||||
var preventInvertInRollback = false; | ||||||
var testScenarioBound = testScenario.bind(this); | ||||||
testScenarioBound(preventInvertInRollback, done); | ||||||
}); | ||||||
|
||||||
it('does not call doc type invert if preventInvertInRollback is `true`', function(done) { | ||||||
var preventInvertInRollback = true; | ||||||
var testScenarioBound = testScenario.bind(this); | ||||||
testScenarioBound(preventInvertInRollback, done); | ||||||
}); | ||||||
}); | ||||||
}); | ||||||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't help but notice a grammar issue. Suggest to simplify this name.