Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests showing creating and saving a model with async relationships does ... #63

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions tests/adapter_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,71 @@ test('camelCase belongsTo key is serialized with underscores on save', function(
equal(ajaxHash.data, '{"description":"firstkid","camel_parent":"1"}');
});
});

asyncTest('async hasMany relationship is serialized', function() {
var store,
assertion;

stubEndpointForHttpRequest('/api/camels/', {}, 'POST'); // avoid a failed request

store = App.__container__.lookup('store:main');
Ember.run(App, function(){
store.serializerFor('tag').pushSinglePayload(store, 'tag', {"id": 10, "description": "django"});
});

visit("/").then(function() {
return store.find('tag', 10);
}).then(function(tag){
var camel;
camel = store.createRecord('camel', {
camelCaseAttribute: 'awesome stuff in here',
camelCaseRelationship: [tag],
belongsToAsyncRelationship: null
});

return camel.save().then(
assertion,
assertion
); // check the assertion regardless of success or failure of camel.save()
});

assertion = function() {
equal(ajaxHash.data, '{"camel_case_attribute":"awesome stuff in here","camel_case_relationship":["10"],"belongs_to_async_relationship":null}');
start(); // end the asyncTest
};

});

asyncTest('async belongsTo relationship is serialized', function() {
var store,
assertion;

stubEndpointForHttpRequest('/api/camels/', {}, 'POST'); // avoid a failed request

store = App.__container__.lookup('store:main');
Ember.run(App, function(){
store.serializerFor('tag').pushSinglePayload(store, 'tag', {"id": 10, "description": "django"});
});

visit("/").then(function() {
return store.find('tag', 10);
}).then(function(tag){
var camel;
camel = store.createRecord('camel', {
camelCaseAttribute: 'awesome stuff in here',
camelCaseRelationship: null,
belongsToAsyncRelationship: tag
});

return camel.save().then(
assertion,
assertion
); // check the assertion regardless of success or failure of camel.save()
});

assertion = function() {
equal(ajaxHash.data, '{"camel_case_attribute":"awesome stuff in here","camel_case_relationship":[],"belongs_to_async_relationship":"10"}');
start(); // end the asyncTest
};

});
3 changes: 2 additions & 1 deletion tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ App.CamelUrl = DS.Model.extend({

App.Camel = DS.Model.extend({
camelCaseAttribute: DS.attr('string'),
camelCaseRelationship: DS.hasMany('tag', { async: true })
camelCaseRelationship: DS.hasMany('tag', { async: true }),
belongsToAsyncRelationship: DS.belongsTo('tag', { async: true })
});

App.Location = DS.Model.extend({
Expand Down