Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created July 6, 2014 18:38
Show Gist options
  • Save tpitale/6574c5b4019cd46824aa to your computer and use it in GitHub Desktop.
Save tpitale/6574c5b4019cd46824aa to your computer and use it in GitHub Desktop.
Failing test for conflict between Errors.content and a model attribute named content
// Added to the bottom of tests/unit/model/errors_test.js
var env, store, Person, Dog;
module("unit/model/errors - model.save() triggers errors", {
setup: function() {
Person = DS.Model.extend({
firstName: DS.attr(),
lastName: DS.attr()
});
env = setupStore({ person: Person });
store = env.store;
}
});
test("invalid record triggers becameInvalid", function() {
expect(1);
Dog = DS.Model.extend({
content: DS.attr('string'),
becameInvalid: function() {
ok(true, "triggered becameInvalid");
}
});
var adapter = DS.ActiveModelAdapter.extend({
updateRecord: function(store, type, record) {
return this.ajax("", "PUT", { data: {} });
},
ajax: function(url, type, hash) {
var adapter = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
/* If InvalidError is passed back in the reject it will throw the
exception which will bubble up the call stack (crashing the test)
instead of hitting the failure route of the promise.
So wrapping the reject in an Ember.run.next makes it so save
completes without failure and the failure hits the failure route
of the promise instead of crashing the save. */
Ember.run.next(function(){
var jsonError = '{"errors": {"content": "cannot be blank"}}'
var jqXHR = {responseText: jsonError, status: 422};
reject(adapter.ajaxError(jqXHR));
});
});
}
});
env = setupStore({ dog: Dog, adapter: adapter});
var dog = env.store.push('dog', { id: 1, content: "Pluto was a dog" });
dog.set('content', "");
dog.save().catch(async(function() {}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment