Issues with model behavior while testing

I’m having some issues testing an ember-cli app. specifically issues with the model not being setup as it does in the app. the rollback method does not seem to behave as expected.

if somebody has any idea what is going on here, i would be very grateful. thanks in advance!

  1. if i set it up using store.createRecord rollback does not work as expected.

    test(‘#testname’, function(assert) {

    var record = store.createRecord(‘modelName’, {id:2, foo: ‘bar’});

    // this sets the record to state to loaded and clean record.send(‘willCommit’); record.set(‘_attributes’, {}); record.send(‘didComimt’);

    record.get(‘isDirty’); // >> false record.set(‘foo’, ‘baz’); record.get(‘isDirty’); // >> true;

    // expecting this to rollback the model to the the saved state, // but sets all the properties on the model to undefined except the id record.rollback(); record.get(‘foo’); // >> undefined });

  2. if setup using store.push() the model is semi-accessable via controller.model.whatever, but looks like the actual ember model object is located at controller.model.content

    setup: function() { … store.push(‘modelName’, {id: 123, foo: ‘bar’}); …

    test(‘#testname’, function(assert){ var controller = this.subject();{ controller.set(‘model’, store.find(‘modelName’, 123); });{ controller.model.get(‘foo’); // >> ‘bar’ controller.model.set(‘foo’, ‘baz’); controller.model.get(‘isDirty’); // >> true controller.model.rollback(); // >> rollback is not a funciton

     * below is a function that seems to rollback things the way i would expect 
     * them to work, but the code being tested is calling the model not
     * model.content. i tried settings the controller.model to     
     * controller.model.content and then the rollback behaves as above
     controller.model.content.rollback(); // rolls back controller.model

    }); });


I have the same issue with ember 2.2.0 , have you figured out what gives “rollback is not a function”?

@davidstevens37 ,

For your information: Model.rollback() is RENAMED to model.rollbackAttributes()