diff --git a/assets/scripts/lib/travis/model.coffee b/assets/scripts/lib/travis/model.coffee index d39e19da..099e515b 100644 --- a/assets/scripts/lib/travis/model.coffee +++ b/assets/scripts/lib/travis/model.coffee @@ -8,6 +8,7 @@ get: (name) -> if @constructor.isAttribute(name) && @get('incomplete') && !@isAttributeLoaded(name) + console.log 'Loading rest of', @constructor, @get('clientId'), 'for key: ', name @loadTheRest() @_super.apply this, arguments @@ -23,9 +24,14 @@ this isAttributeLoaded: (name) -> + key = null if meta = Ember.get(this.constructor, 'attributes').get(name) - name = meta.key(this.constructor) - @get('store').isDataLoadedFor(this.constructor, @get('clientId'), name) + key = meta.key(this.constructor) + else if meta = Ember.get(this.constructor, 'associationsByName').get(name) + key = meta.options.key || @get('namingConvention').foreignKey(name) + + if key + @get('store').isDataLoadedFor(this.constructor, @get('clientId'), key) isComplete: (-> if @get 'incomplete' @@ -82,4 +88,5 @@ Travis.app.store.adapter.pluralize(@singularName()) isAttribute: (name) -> - Ember.get(this, 'attributes').has(name) + Ember.get(this, 'attributes').has(name) || + Ember.get(this, 'associationsByName').has(name) diff --git a/assets/scripts/spec/unit/incomplete_spec.coffee b/assets/scripts/spec/unit/incomplete_spec.coffee index f2229009..4ac494e9 100644 --- a/assets/scripts/spec/unit/incomplete_spec.coffee +++ b/assets/scripts/spec/unit/incomplete_spec.coffee @@ -3,6 +3,12 @@ Travis.Foo = Travis.Model.extend description: DS.attr('string') lastName: DS.attr('string') + bar: DS.belongsTo('Travis.Bar') + niceBar: DS.belongsTo('Travis.Bar') + veryNiceBar: DS.belongsTo('Travis.Bar', key: 'very_nice_bar_indeed_id') + +Travis.Bar = Travis.Model.extend() + record = null store = null @@ -18,6 +24,52 @@ describe 'Travis.Model', -> afterEach -> store.destroy() + describe 'with incomplete record with loaded associations', -> + beforeEach -> + attrs = { + id: 1 + bar_id: 2 + nice_bar_id: 3 + very_nice_bar_indeed_id: 4 + } + record = store.loadIncomplete(Travis.Foo, attrs) + store.load(Travis.Bar, id: 2) + store.load(Travis.Bar, id: 3) + store.load(Travis.Bar, id: 4) + + it 'does not load record on association access', -> + expect( record.get('bar.id') ).toEqual 2 + expect( record.get('niceBar.id') ).toEqual 3 + expect( record.get('veryNiceBar.id') ).toEqual 4 + waits 50 + runs -> + expect( record.get('complete') ).toBeFalsy() + + describe 'with incomplete record without loaded associations', -> + beforeEach -> + attrs = { + id: 1 + } + record = store.loadIncomplete(Travis.Foo, attrs) + + it 'loads record based on regular association key', -> + record.get('bar') + waits 50 + runs -> + expect( record.get('complete') ).toBeTruthy() + + it 'loads record based on camel case association key', -> + record.get('niceBar') + waits 50 + runs -> + expect( record.get('complete') ).toBeTruthy() + + it 'loads record based on ssociation with explicit key', -> + record.get('veryNiceBar') + waits 50 + runs -> + expect( record.get('complete') ).toBeTruthy() + describe 'with incomplete record', -> beforeEach -> attrs = { diff --git a/public/scripts/app.js b/public/scripts/app.js index 5a082e08..689debb4 100644 --- a/public/scripts/app.js +++ b/public/scripts/app.js @@ -30753,4 +30753,4 @@ var _require=function(){function c(a,c){document.addEventListener?a.addEventList ++g&&setTimeout(c,0)})}}(); (function(){!window.WebSocket&&window.MozWebSocket&&(window.WebSocket=window.MozWebSocket);if(window.WebSocket)Pusher.Transport=window.WebSocket,Pusher.TransportType="native";var c=(document.location.protocol=="http:"?Pusher.cdn_http:Pusher.cdn_https)+Pusher.VERSION,a=[];window.JSON||a.push(c+"/json2"+Pusher.dependency_suffix+".js");if(!window.WebSocket)window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=!0,a.push(c+"/flashfallback"+Pusher.dependency_suffix+".js");var b=function(){return window.WebSocket?function(){Pusher.ready()}: function(){window.WebSocket?(Pusher.Transport=window.WebSocket,Pusher.TransportType="flash",window.WEB_SOCKET_SWF_LOCATION=c+"/WebSocketMain.swf",WebSocket.__addTask(function(){Pusher.ready()}),WebSocket.__initialize()):(Pusher.Transport=null,Pusher.TransportType="none",Pusher.ready())}}(),e=function(a){var b=function(){document.body?a():setTimeout(b,0)};b()},g=function(){e(b)};a.length>0?_require(a,g):g()})(); -;minispade.register('app', "(function() {(function() {\nminispade.require('auth');\nminispade.require('controllers');\nminispade.require('helpers');\nminispade.require('models');\nminispade.require('pusher');\nminispade.require('routes');\nminispade.require('slider');\nminispade.require('store');\nminispade.require('tailing');\nminispade.require('templates');\nminispade.require('views');\nminispade.require('config/locales');\nminispade.require('data/sponsors');\n\n Travis.reopen({\n App: Em.Application.extend({\n autoinit: false,\n currentUserBinding: 'auth.user',\n authStateBinding: 'auth.state',\n init: function() {\n this._super.apply(this, arguments);\n this.store = Travis.Store.create();\n this.store.loadMany(Travis.Sponsor, Travis.SPONSORS);\n this.slider = new Travis.Slider();\n this.pusher = new Travis.Pusher(Travis.config.pusher_key);\n this.tailing = new Travis.Tailing();\n return this.set('auth', Travis.Auth.create({\n app: this,\n endpoint: Travis.config.api_endpoint\n }));\n },\n storeAfterSignInPath: function(path) {\n return this.get('auth').storeAfterSignInPath(path);\n },\n autoSignIn: function(path) {\n return this.get('auth').autoSignIn(path);\n },\n signIn: function() {\n return this.get('auth').signIn();\n },\n signOut: function() {\n this.get('auth').signOut();\n return this.get('router').send('afterSignOut');\n },\n receive: function() {\n return this.store.receive.apply(this.store, arguments);\n },\n toggleSidebar: function() {\n var element;\n $('body').toggleClass('maximized');\n element = $('');\n $('#top .profile').append(element);\n Em.run.later((function() {\n return element.remove();\n }), 10);\n element = $('');\n $('#repo').append(element);\n return Em.run.later((function() {\n return element.remove();\n }), 10);\n }\n })\n });\n\n}).call(this);\n\n})();\n//@ sourceURL=app");minispade.register('auth', "(function() {(function() {\n\n this.Travis.Auth = Ember.Object.extend({\n iframe: $('