Skip to content

Commit

Permalink
Merge pull request emberjs#1033 from stefanpenner/uncatchable_assert_…
Browse files Browse the repository at this point in the history
…and_fixes

Uncatchable assert and fixes
  • Loading branch information
stefanpenner committed Jun 14, 2013
2 parents 0a90d47 + 29be4a1 commit 07b3a43
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"minispade",
"async",
"invokeAsync",
"jQuery"
"jQuery",
"expectAssertion"
],

"node" : false,
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/emberjs/ember-dev.git
revision: 104afee9ca7bf406af545126f377f696c0c10581
revision: d064bd6c33e87979aa5b852f8eb853c39b190e87
branch: master
specs:
ember-dev (0.1)
Expand Down
27 changes: 14 additions & 13 deletions packages/ember-data/lib/adapters/rest_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ require('ember-data/serializers/rest_serializer');

var get = Ember.get, set = Ember.set;

function rejectionHandler(reason) {
Ember.Logger.error(reason, reason.message);
DS.rejectionHandler = function(reason) {
Ember.Logger.assert([reason, reason.message, reason.stack]);

throw reason;
}
};

/**
The REST adapter allows your store to communicate with an HTTP server by
Expand Down Expand Up @@ -136,7 +137,7 @@ DS.RESTAdapter = DS.Adapter.extend({
}, function(xhr) {
adapter.didError(store, type, record, xhr);
throw xhr;
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

createRecords: function(store, type, records) {
Expand All @@ -159,7 +160,7 @@ DS.RESTAdapter = DS.Adapter.extend({
data: data
}).then(function(json) {
adapter.didCreateRecords(store, type, records, json);
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

updateRecord: function(store, type, record) {
Expand All @@ -179,7 +180,7 @@ DS.RESTAdapter = DS.Adapter.extend({
}, function(xhr) {
adapter.didError(store, type, record, xhr);
throw xhr;
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

updateRecords: function(store, type, records) {
Expand All @@ -205,7 +206,7 @@ DS.RESTAdapter = DS.Adapter.extend({
data: data
}).then(function(json) {
adapter.didUpdateRecords(store, type, records, json);
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

deleteRecord: function(store, type, record) {
Expand All @@ -220,7 +221,7 @@ DS.RESTAdapter = DS.Adapter.extend({
}, function(xhr){
adapter.didError(store, type, record, xhr);
throw xhr;
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

deleteRecords: function(store, type, records) {
Expand All @@ -246,7 +247,7 @@ DS.RESTAdapter = DS.Adapter.extend({
data: data
}).then(function(json){
adapter.didDeleteRecords(store, type, records, json);
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

find: function(store, type, id) {
Expand All @@ -255,7 +256,7 @@ DS.RESTAdapter = DS.Adapter.extend({
return this.ajax(this.buildURL(root, id), "GET").
then(function(json){
adapter.didFindRecord(store, type, json, id);
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

findAll: function(store, type, since) {
Expand All @@ -268,7 +269,7 @@ DS.RESTAdapter = DS.Adapter.extend({
data: this.sinceQuery(since)
}).then(function(json) {
adapter.didFindAll(store, type, json);
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

findQuery: function(store, type, query, recordArray) {
Expand All @@ -279,7 +280,7 @@ DS.RESTAdapter = DS.Adapter.extend({
data: query
}).then(function(json){
adapter.didFindQuery(store, type, json, recordArray);
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

findMany: function(store, type, ids, owner) {
Expand All @@ -292,7 +293,7 @@ DS.RESTAdapter = DS.Adapter.extend({
data: {ids: ids}
}).then(function(json) {
adapter.didFindMany(store, type, json);
}).then(null, rejectionHandler);
}).then(null, DS.rejectionHandler);
},

/**
Expand Down
17 changes: 7 additions & 10 deletions packages/ember-data/tests/integration/belongs_to_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,15 @@ test("The store can materialize a non loaded monomorphic belongsTo association",

test("Only a record of the same type can be used with a monomorphic belongsTo relationship", function() {
expect(1);

store.load(App.Post, { id: 1 });
store.load(App.Comment, { id: 2 });
var post = store.find(App.Post, 1),
comment = store.find(App.Comment, 2);

raises(
function() { post.set('user', comment); },
/You can only add a record of App.User to this relationship/,
"Adding a record of a different type on a monomorphic belongsTo is disallowed"
);
expectAssertion(function(){
post.set('user', comment);
}, /You can only add a record of App.User to this relationship/);
});

test("Only a record of the same base type can be used with a polymorphic belongsTo relationship", function() {
Expand All @@ -109,11 +108,9 @@ test("Only a record of the same base type can be used with a polymorphic belongs
comment.set('message', post);
comment.set('message', null);

raises(
function() { comment.set('message', user); },
/You can only add a record of App.Message to this relationship/,
"Adding a record of a different base type on a polymorphic belongsTo is disallowed"
);
expectAssertion(function() {
comment.set('message', user);
}, /You can only add a record of App.Message to this relationship/);
});

test("The store can load a polymorphic belongsTo association", function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ asyncTest("Embedded belongsTo relationships can be saved when embedded: always i

return promise(function(resolve, reject) {
setTimeout(function() {
Ember.run(null, resolve, adapter);
Ember.run(function() {
hash.data.comment.id = 1;
resolve(hash.data);
});
done();
});
});
Expand All @@ -121,7 +124,6 @@ asyncTest("Embedded belongsTo relationships can be saved when embedded: always i
user.set('name', "mongodb_expert");
equal(user.get('isDirty'), true, "user becomes dirty after changing a property");
equal(comment.get('isDirty'), true, "comment becomes dirty when its embedded user becomes dirty");

transaction.commit();

function done() {
Expand Down Expand Up @@ -196,7 +198,10 @@ asyncTest("Embedded hasMany relationships can be saved when embedded: always is

return promise(function(resolve, reject){
setTimeout(function() {
Ember.run(null, resolve, adapter);
Ember.run(function() {
hash.data.post.id = 1;
resolve(hash.data);
});
done();
});
});
Expand Down Expand Up @@ -298,7 +303,10 @@ asyncTest("Embedded records that contain embedded records can be saved", functio

return promise(function(resolve, reject){
setTimeout(function(){
Ember.run(null, resolve, adapter);
Ember.run(function() {
hash.data.post.id = 1;
resolve(hash.data);
});
done();
});
});
Expand Down
24 changes: 9 additions & 15 deletions packages/ember-data/tests/integration/has_many_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,9 @@ test("A record can't be created from a polymorphic hasMany relationship", functi
var user = store.find(App.User, 1),
messages = user.get('messages');

raises(
function() { messages.createRecord(); },
/You can not create records of App.Message on this polymorphic relationship/,
"Creating records directly on a polymorphic hasMany is disallowed"
);
expectAssertion(function() {
messages.createRecord();
}, /You can not create records of App.Message on this polymorphic relationship/);
});

test("Only records of the same type can be added to a monomorphic hasMany relationship", function() {
Expand All @@ -232,11 +230,9 @@ test("Only records of the same type can be added to a monomorphic hasMany relati
var post = store.find(App.Post, 1),
message = store.find(App.Post, 2);

raises(
function() { post.get('comments').pushObject(message); },
/You can only add records of App.Comment to this relationship/,
"Adding records of a different type on a monomorphic hasMany is disallowed"
);
expectAssertion(function() {
post.get('comments').pushObject(message);
}, /You can only add records of App.Comment to this relationship/);
});

test("Only records of the same base type can be added to a polymorphic hasMany relationship", function() {
Expand All @@ -257,11 +253,9 @@ test("Only records of the same base type can be added to a polymorphic hasMany r

equal(messages.get('length'), 2, "The messages are correctly added");

raises(
function() { messages.pushObject(anotherUser); },
/You can only add records of App.Message to this relationship/,
"Adding records of a different base type on a polymorphic hasMany is disallowed"
);
expectAssertion(function() {
messages.pushObject(anotherUser);
}, /You can only add records of App.Message to this relationship/);
});

test("A record can be removed from a polymorphic association", function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ test("A record can't be created from an embedded polymorphic hasMany relationshi
var user = store.find(App.User, 1),
messages = user.get('messages');

raises(
function() { messages.createRecord(); },
/You can not create records of App.Message on this polymorphic relationship/,
"Creating records directly on a polymorphic hasMany is disallowed"
);
expectAssertion(function() {
messages.createRecord();
}, /You can not create records of App.Message on this polymorphic relationship/);
});

test("Only records of the same base type can be added to an embedded polymorphic hasMany relationship", function() {
Expand All @@ -100,11 +98,9 @@ test("Only records of the same base type can be added to an embedded polymorphic

equal(messages.get('length'), 2, "The messages are correctly added");

raises(
function() { messages.pushObject(anotherUser); },
/You can only add records of App.Message to this relationship/,
"Adding records of a different base type on a polymorphic hasMany is disallowed"
);
expectAssertion(function() {
messages.pushObject(anotherUser);
}, /You can only add records of App.Message to this relationship/);
});

test("A record can be removed from an embedded polymorphic association", function() {
Expand Down
3 changes: 1 addition & 2 deletions packages/ember-data/tests/unit/model_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ test("trying to set an `id` attribute should raise", function() {
name: "Scumdale"
});

raises(function() {
expectAssertion(function() {
store.load(Person, { id: 1, name: "Scumdale" });
var person = store.find(Person, 1);
person.get('name');
}, /You may not set `id`/);
});

Expand Down
17 changes: 10 additions & 7 deletions packages/ember-data/tests/unit/rest_adapter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,9 @@ test("When a record with a belongsTo is saved the foreign key should be sent.",
title: DS.attr("string"),
people: DS.hasMany(Person)
});
PersonType.toString = function() {
return "App.PersonType";
};
Person.reopen({
personType: DS.belongsTo(PersonType)
});
Expand Down Expand Up @@ -1369,7 +1372,7 @@ var TestError = function(message) {
this.message = message;
};

var originalLogger = Ember.Logger.error;
var originalRejectionHandler = DS.rejectionHandler;

module('The REST adapter - error handling', {
setup: function() {
Expand All @@ -1385,11 +1388,13 @@ module('The REST adapter - error handling', {
},

teardown: function() {
Ember.Logger.error = originalLogger;
DS.rejectionHandler = originalRejectionHandler;
}
});

test("promise errors are sent to the ember error logger", function() {
test("promise errors are sent to the ember assertion logger", function() {
expect(1);

// setup
store = DS.Store.create({
adapter: Adapter.extend({
Expand All @@ -1407,11 +1412,9 @@ test("promise errors are sent to the ember error logger", function() {
})
});

expect(2);

Ember.Logger.error = function(error, message) {
ok(error instanceof TestError, "Promise chains should dump exception classes to the logger");
equal(message, 'TestError', "Promise chains should dump exception messages to the logger");
DS.rejectionHandler = function(reason) {
ok(reason instanceof TestError, "Promise chains should dump exception classes to the logger");
};

store.find(Person, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ test("registered transformations should be called when serializing and materiali
value = serializer.serializeValue('unknown', 'unobtainium');
equal(value, 'serialize', "the serialize transform was called");

raises(function() {
expectAssertion(function() {
serializer.deserializeValue('unknown', 'obtainium');
});

raises(function() {
expectAssertion(function() {
serializer.serializeValue('unknown', 'obtainium');
});
});
Expand Down
14 changes: 7 additions & 7 deletions packages/ember-data/tests/unit/store_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,18 @@ test("a new record with a specific id can't be created if this id is already use
var Person = DS.Model.extend({
name: DS.attr('string'),
});

Person.reopenClass({
toString: function() {
return 'Person';
}
});

store.createRecord(Person, {id: 5});

raises(
function() { store.createRecord(Person, {id: 5}); },
/The id 5 has already been used with another record of type Person/,
"Creating a record with an if an id already in used in the store is disallowed"
);
expectAssertion(function() {
store.createRecord(Person, {id: 5});
}, /The id 5 has already been used with another record of type Person/);
});

test("an initial data hash can be provided via store.createRecord(type, hash)", function() {
Expand Down Expand Up @@ -745,9 +745,9 @@ test("unload a dirty record", function() {
record.set('title', 'toto2');

equal(get(record, 'isDirty'), true, "record is dirty");
raises(function() {
expectAssertion(function() {
record.unloadRecord();
}, "You can only unload a loaded non dirty record.", "can not unload dirty record");
}, "You can only unload a loaded, non-dirty record.", "can not unload dirty record");
});

test("unload a record", function() {
Expand Down
1 change: 1 addition & 0 deletions tests/ember_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@
spade: 'ember-spade.js',
build: 'ember-data.js'
};

})();

0 comments on commit 07b3a43

Please sign in to comment.