JackAdams / meteor-transactions

App level transactions for Meteor + Mongo
http://transactions.taonova.com/
MIT License
113 stars 16 forks source link

Inserted documents with predefined _id gets re-assigned _id value #33

Closed rjsmith closed 9 years ago

rjsmith commented 9 years ago

Found in 0.7.2 If an attempt is made to insert a document with a pre-defined _id property, meteor transactions package overwrites this with its own randomly - generated _id value

The following test demonstrates this bug

'use strict';

describe('committable actions', function () {

  var transaction_id, insertedFooDoc, transactionDoc, fakeId;

  beforeEach(function () {

    // Fake userId to get through tx userId checks
    fakeId = 'or6YSgs6nT8Bs5o6p';

    // Because `tx.requireUser = true` (by default)
    spyOn(Meteor,'userId').and.returnValue(fakeId);

  });

  fit('insert with pre-defined document _id', function () {
    // SETUP
    var predefinedId = 'PNAJ67oTkkaH46xJz';
    tx.start('insert transaction');
    fooCollection.insert(
      {_id: predefinedId, foo: "After insert"}, {tx: true});

    // EXECUTE
    tx.commit();

    // VERIFY
    var savedDoc = fooCollection.findOne({_id: predefinedId});

    expect(savedDoc).toBeDefined();
    expect(savedDoc.foo).toEqual('After insert');

  });

  afterEach(function () {
    fooCollection.remove({});
    tx.Transactions.remove({});
  });

});