From e5fe8fd975ee45791b9a41478cae64bd91a12867 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Mon, 26 Nov 2018 09:23:42 -0800 Subject: [PATCH] Save As clears transaction while undirtying (#1471) * mutation listener adds via transaction manager Update the TransactingMutationListener to add items to a transaction using the transactionManager so that they can be properly removed from the transaction at a later date. Prevents showing error dialogs during successful save, and also prevents persisting duplicate objects. Fixes #1468 --- .../src/runs/TransactingMutationListener.js | 5 +--- .../runs/TransactingMutationListenerSpec.js | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/platform/core/src/runs/TransactingMutationListener.js b/platform/core/src/runs/TransactingMutationListener.js index c242ed3015..f58bac5fda 100644 --- a/platform/core/src/runs/TransactingMutationListener.js +++ b/platform/core/src/runs/TransactingMutationListener.js @@ -52,10 +52,7 @@ define([], function () { transactionService.startTransaction(); } - transactionService.addToTransaction( - persistence.persist.bind(persistence), - persistence.refresh.bind(persistence) - ); + persistence.persist(); if (!wasActive) { transactionService.commit(); diff --git a/platform/core/test/runs/TransactingMutationListenerSpec.js b/platform/core/test/runs/TransactingMutationListenerSpec.js index 139b0fa6dd..0fb2357634 100644 --- a/platform/core/test/runs/TransactingMutationListenerSpec.js +++ b/platform/core/test/runs/TransactingMutationListenerSpec.js @@ -24,22 +24,27 @@ define( ["../../src/runs/TransactingMutationListener"], function (TransactingMutationListener) { - xdescribe("TransactingMutationListener", function () { + describe("TransactingMutationListener", function () { var mockTopic, mockMutationTopic, + mockCacheService, mockTransactionService, mockDomainObject, + mockModel, mockPersistence; beforeEach(function () { mockTopic = jasmine.createSpy('topic'); mockMutationTopic = jasmine.createSpyObj('mutation', ['listen']); + mockCacheService = + jasmine.createSpyObj('cacheService', [ + 'put' + ]); mockTransactionService = jasmine.createSpyObj('transactionService', [ 'isActive', 'startTransaction', - 'addToTransaction', 'commit' ]); mockDomainObject = jasmine.createSpyObj( @@ -52,18 +57,24 @@ define( ); mockTopic.and.callFake(function (t) { - return (t === 'mutation') && mockMutationTopic; + expect(t).toBe('mutation'); + return mockMutationTopic; }); + mockDomainObject.getId.and.returnValue('mockId'); mockDomainObject.getCapability.and.callFake(function (c) { - return (c === 'persistence') && mockPersistence; + expect(c).toBe('persistence'); + return mockPersistence; }); + mockModel = {}; + mockDomainObject.getModel.and.returnValue(mockModel); mockPersistence.persisted.and.returnValue(true); return new TransactingMutationListener( mockTopic, - mockTransactionService + mockTransactionService, + mockCacheService ); }); @@ -99,12 +110,8 @@ define( ).toHaveBeenCalled(); }); - it("adds to the active transaction", function () { - expect(mockTransactionService.addToTransaction) - .toHaveBeenCalledWith( - jasmine.any(Function), - jasmine.any(Function) - ); + it("calls persist", function () { + expect(mockPersistence.persist).toHaveBeenCalled(); }); it(innerVerb + " immediately commit", function () {