Fix bug with undefined loadedAttributes

This commit is contained in:
Piotr Sarnacki 2012-10-16 17:47:03 +02:00
parent 96acd8e526
commit 9d07ef79ac
5 changed files with 60 additions and 6 deletions

View File

@ -2,6 +2,10 @@
primaryKey: 'id'
id: DS.attr('number')
init: ->
@loadedAttributes = []
@_super.apply this, arguments
get: (name) ->
if @constructor.isAttribute(name) && @get('incomplete') && !@isAttributeLoaded(name)
@loadTheRest()

View File

@ -11,10 +11,14 @@ $.mockjax
responseText: { foo: { id: 1, name: 'foo', description: 'bar' } }
describe 'Travis.Model', ->
beforeEach ->
store = Travis.Store.create()
afterEach ->
store.destroy()
describe 'with incomplete record', ->
beforeEach ->
store = Travis.Store.create()
attrs = {
id: 1
name: 'foo'
@ -46,3 +50,23 @@ describe 'Travis.Model', ->
runs ->
store.loadIncomplete(Travis.Foo, id: 1)
expect( record.get('incomplete') ).toBeFalsy()
describe 'with complete record', ->
beforeEach ->
id = 5
attrs = {
id: id
name: 'foo'
}
store.load(Travis.Foo, id, attrs)
record = Travis.Foo.find(id)
it 'is marked as completed', ->
expect( record.get('complete') ).toBeTruthy()
it 'allows to get regular attribute', ->
expect( record.get('name') ).toEqual 'foo'
it 'allows to check attribute state', ->
expect( record.isAttributeLoaded('name') ).toBeFalsy()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8893,10 +8893,15 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
});
describe('Travis.Model', function() {
return describe('with incomplete record', function() {
beforeEach(function() {
return store = Travis.Store.create();
});
afterEach(function() {
return store.destroy();
});
describe('with incomplete record', function() {
beforeEach(function() {
var attrs;
store = Travis.Store.create();
attrs = {
id: 1,
name: 'foo'
@ -8935,6 +8940,27 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
});
});
});
return describe('with complete record', function() {
beforeEach(function() {
var attrs, id;
id = 5;
attrs = {
id: id,
name: 'foo'
};
store.load(Travis.Foo, id, attrs);
return record = Travis.Foo.find(id);
});
it('is marked as completed', function() {
return expect(record.get('complete')).toBeTruthy();
});
it('allows to get regular attribute', function() {
return expect(record.get('name')).toEqual('foo');
});
return it('allows to check attribute state', function() {
return expect(record.isAttributeLoaded('name')).toBeFalsy();
});
});
});
}).call(this);