Fix bug with undefined loadedAttributes
This commit is contained in:
parent
96acd8e526
commit
9d07ef79ac
|
@ -2,6 +2,10 @@
|
||||||
primaryKey: 'id'
|
primaryKey: 'id'
|
||||||
id: DS.attr('number')
|
id: DS.attr('number')
|
||||||
|
|
||||||
|
init: ->
|
||||||
|
@loadedAttributes = []
|
||||||
|
@_super.apply this, arguments
|
||||||
|
|
||||||
get: (name) ->
|
get: (name) ->
|
||||||
if @constructor.isAttribute(name) && @get('incomplete') && !@isAttributeLoaded(name)
|
if @constructor.isAttribute(name) && @get('incomplete') && !@isAttributeLoaded(name)
|
||||||
@loadTheRest()
|
@loadTheRest()
|
||||||
|
|
|
@ -11,10 +11,14 @@ $.mockjax
|
||||||
responseText: { foo: { id: 1, name: 'foo', description: 'bar' } }
|
responseText: { foo: { id: 1, name: 'foo', description: 'bar' } }
|
||||||
|
|
||||||
describe 'Travis.Model', ->
|
describe 'Travis.Model', ->
|
||||||
|
beforeEach ->
|
||||||
|
store = Travis.Store.create()
|
||||||
|
|
||||||
|
afterEach ->
|
||||||
|
store.destroy()
|
||||||
|
|
||||||
describe 'with incomplete record', ->
|
describe 'with incomplete record', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
store = Travis.Store.create()
|
|
||||||
|
|
||||||
attrs = {
|
attrs = {
|
||||||
id: 1
|
id: 1
|
||||||
name: 'foo'
|
name: 'foo'
|
||||||
|
@ -46,3 +50,23 @@ describe 'Travis.Model', ->
|
||||||
runs ->
|
runs ->
|
||||||
store.loadIncomplete(Travis.Foo, id: 1)
|
store.loadIncomplete(Travis.Foo, id: 1)
|
||||||
expect( record.get('incomplete') ).toBeFalsy()
|
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
|
@ -8893,10 +8893,15 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Travis.Model', function() {
|
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() {
|
beforeEach(function() {
|
||||||
var attrs;
|
var attrs;
|
||||||
store = Travis.Store.create();
|
|
||||||
attrs = {
|
attrs = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'foo'
|
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);
|
}).call(this);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user