adopted-ember-addons / ember-data-model-fragments

Ember Data addon to support nested JSON documents
MIT License
370 stars 114 forks source link

Fragment changed inflight is not returning as dirty #331

Open ELepolt opened 5 years ago

ELepolt commented 5 years ago

In a recent update to Ember 3.8 I updated this addon and an existing test (last updated 2 years ago) began failing.

While saving, the record is updated and after the save finalizes the record claims to not have any dirty attributes.

test('String Array - changed and then changed back while inflight', function(assert) {
  let record = this.testRecord;

  // Sanity check the default values
  assert.notOk(record.get('hasDirtyAttributes'), 'Record should start out clean');
  assert.deepEqual(record.get('tags').toArray(), ['Kroger', 'Target', 'Meijer'], 'Should start out with the proper tags.');

  // Sanity check for saving and dirtyness
  Ember.run(function() { record.get('tags').addObject('Remke'); });
  assert.deepEqual(record.get('tags').toArray(), ['Kroger', 'Target', 'Meijer', 'Remke'], 'Should have been updated.');
  assert.ok(record.get('hasDirtyAttributes'), 'Record now be dirty');
  Ember.run(() => { record.save(); });
  Ember.run(() => { record.get('tags').removeObject('Remke'); });
  Ember.run(() => { this.resumeSave(); });
  Ember.run(() => {

    // This is where hasDirtyAttributes is coming back false
    assert.ok(record.get('hasDirtyAttributes'), 'Record should still be dirty because it was change back in flight');

    assert.deepEqual(record.get('tags').toArray(), ['Kroger', 'Target', 'Meijer'], 'Should have been updated.');
  });
});
VincentMolinie commented 4 years ago

Hey @ELepolt, did you try with the new beta version 5.0.0-beta.0, it fixes a similar issue for me 😉