Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexspeller/15bb57c41b907a30707d to your computer and use it in GitHub Desktop.
Save alexspeller/15bb57c41b907a30707d to your computer and use it in GitHub Desktop.
Dirty Property Test Case
import Ember from 'ember';
export default Ember.Controller.extend({
});
import Ember from 'ember';
export default Ember.Route.extend({
init() {
this._super();
$.mockjax({
url: '/authors/1',
type: 'GET',
responseText: {
author: {
id: 1,
name: 'Kerrick'
}
}
});
$.mockjax({
url: '/authors/1',
type: 'PUT',
response: function(settings) {
this.responseText = {
author: {
id: 1,
name: JSON.parse(settings.data).author.name
}
}
}
});
},
model() {
return this.store.find('author', 1);
},
actions: {
save(model) {
model.save();
}
}
});
<h1>Reduced Test Case</h1>
<br>
<br>
{{input value=model.name}}
<button {{action "save" model}}>
{{#if model.isNameDirty}}
save
{{else}}
saved
{{/if}}
</button>
<br>
<br>
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
name: DS.attr('string'),
isNameDirty: Ember.computed('name', 'hasDirtyAttributes', function() {
if (!this.get('hasDirtyAttributes')) { return false }
return !!this.changedAttributes()['name'];
})
});
{
"version": "0.6.5",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "1.13.13",
"ember-data": "1.13.15",
"ember-template-compiler": "1.13.13",
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment