Skip to content

Commit

Permalink
(pouchdb#658) - Force inclusion of conflicts in view querying..
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-thompson authored and daleharvey committed Apr 1, 2013
1 parent a0541ed commit f0e6426
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
9 changes: 1 addition & 8 deletions src/plugins/pouchdb.mapreduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ var MapReduce = function(db) {
options.reduce = false;
}

// Including conflicts
options.conflicts = true;

function sum(values) {
return values.reduce(function(a, b) { return a + b; }, 0);
}
Expand Down Expand Up @@ -75,10 +72,6 @@ var MapReduce = function(db) {
eval('fun.reduce = ' + fun.reduce.toString() + ';');
}

// exclude _conflicts key by default
// or to use options.conflicts if it's set when called by db.query
var conflicts = ('conflicts' in options ? options.conflicts : false);

//only proceed once all documents are mapped and joined
var checkComplete= function(){
if (completed && results.length == num_started){
Expand Down Expand Up @@ -111,7 +104,7 @@ var MapReduce = function(db) {
}

db.changes({
conflicts: conflicts,
conflicts: true,
include_docs: true,
onChange: function(doc) {
if (!('deleted' in doc)) {
Expand Down
20 changes: 4 additions & 16 deletions tests/test.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,32 +242,20 @@ adapters.map(function(adapter) {
});


asyncTest('Views should include _conflict by default', function() {
asyncTest('Views should include _conflicts', function() {
var self = this;
var doc1 = {_id: '1', foo: 'bar'};
var doc2 = {_id: '1', foo: 'baz'};
var queryFun = function(doc) { emit(doc._conflicts); };
var queryFun = function(doc) { emit(doc._id, !!doc._conflicts); };
initDBPair(this.name, this.remote, function(db, remote) {
db.post(doc1, function(err, res) {
remote.post(doc2, function(err, res) {
db.replicate.from(remote, function(err, res) {
db.get(doc1._id, {conflicts: true}, function(err, res) {
ok(res._conflicts,'Conflict exists in db');

// Default behaviour
db.query(queryFun, function(err, res) {
equal(res.rows[0].key.length, 1, 'Conflicts included');

// conflicts: true
db.query(queryFun, {conflicts: true}, function(err, res) {
equal(res.rows[0].key.length, 1, 'Conflicts included');

// conflicts: false
db.query(queryFun, {conflicts: false}, function(err, res) {
equal(res.rows[0].key.length, 1,'Conflicts excluded');
start();
});
});
ok(res.rows[0].value, 'Conflicts included.');
start();
});
});
});
Expand Down

0 comments on commit f0e6426

Please sign in to comment.