diff --git a/assets/scripts/app/app.coffee b/assets/scripts/app/app.coffee index 3cc79ca6..4e16be6f 100644 --- a/assets/scripts/app/app.coffee +++ b/assets/scripts/app/app.coffee @@ -119,14 +119,12 @@ unless window.TravisApplication loadOrMerge: (type, hash, options) -> options ||= {} - if !type._idToReference - type._idToReference = {} - reference = type._idToReference[hash.id] + reference = type._getReferenceById(hash.id) if reference && options.skipIfExists return - reference = type._referenceForId(hash.id) + reference = type._getOrCreateReferenceForId(hash.id) if reference.record reference.record.merge(hash) else diff --git a/assets/scripts/app/controllers/flash.coffee b/assets/scripts/app/controllers/flash.coffee index c942114a..a7abdbee 100644 --- a/assets/scripts/app/controllers/flash.coffee +++ b/assets/scripts/app/controllers/flash.coffee @@ -9,7 +9,7 @@ Travis.FlashController = Ember.ArrayController.extend @set('flashes', Ember.A()) content: (-> - @get('unseenBroadcasts').concat(@get('flashes')) + @get('unseenBroadcasts').concat(@get('flashes')).filter (o) -> o ).property('unseenBroadcasts.length', 'flashes.length') unseenBroadcasts: (-> diff --git a/assets/scripts/lib/travis/model.coffee b/assets/scripts/lib/travis/model.coffee index 4c37fe50..9226130b 100644 --- a/assets/scripts/lib/travis/model.coffee +++ b/assets/scripts/lib/travis/model.coffee @@ -38,18 +38,19 @@ Array.prototype.diff = (a) -> @loadedAttributes = [] @loadedRelationships = [] - attributes = this.attributes || [] - relationships = this.relationships || [] + attributes = this.constructor.getAttributes() || [] + relationships = this.constructor.getRelationships() || [] - for key in attributes - dataKey = @dataKey(key) - if hash.hasOwnProperty(dataKey) - @loadedAttributes.pushObject(key) + if hash + for key in attributes + dataKey = @dataKey(key) + if hash.hasOwnProperty(dataKey) + @loadedAttributes.pushObject(key) - for key in relationships - dataKey = @dataKey(key) - if hash.hasOwnProperty(dataKey) - @loadedRelationships.pushObject(key) + for key in relationships + dataKey = @dataKey(key) + if hash.hasOwnProperty(dataKey) + @loadedRelationships.pushObject(key) incomplete = Ember.EnumerableUtils.intersection(@loadedAttributes, attributes).length != attributes.length || Ember.EnumerableUtils.intersection(@loadedRelationships, relationships).length != relationships.length @@ -86,10 +87,10 @@ Array.prototype.diff = (a) -> @loadTheRest(key) isAttribute: (name) -> - this.attributes.contains(name) + this.constructor.getAttributes().contains(name) isRelationship: (name) -> - this.relationships.contains(name) + this.constructor.getRelationships().contains(name) loadTheRest: (key) -> # for some weird reason key comes changed to a string and for some weird reason it even is called with @@ -145,19 +146,19 @@ Array.prototype.diff = (a) -> ).property() isRecordLoaded: (id) -> - !!@_referenceForId(id).record + reference = @_getReferenceById(id) + reference && reference.record camelizeKeys: true # TODO: the functions below will be added to Ember Model, remove them when that # happens resetData: -> - @_idToReference = null - @sideloadedData = null - @recordCache = null - @recordArrays = null - @_currentBatchIds = null - @_hasManyArrays = null + @_referenceCache = {} + @sideloadedData = {} + @recordArrays = [] + @_currentBatchIds = [] + @_hasManyArrays = [] @_findAllRecordArray = null unload: (record) -> @@ -172,10 +173,8 @@ Array.prototype.diff = (a) -> delete this.recordCache[key] loadRecordForReference: (reference) -> - record = @create({ _reference: reference }) - @recordCache = {} unless @recordCache + record = @create({ _reference: reference, id: reference.id }) @sideloadedData = {} unless @sideloadedData - @recordCache[reference.id] = record reference.record = record record.load(reference.id, @sideloadedData[reference.id]) # TODO: find a nicer way to not add record to record arrays twice diff --git a/assets/scripts/spec/support/expectations.coffee b/assets/scripts/spec/support/expectations.coffee index 03050d29..4d348c53 100644 --- a/assets/scripts/spec/support/expectations.coffee +++ b/assets/scripts/spec/support/expectations.coffee @@ -5,7 +5,7 @@ @displaysTabs = (tabs) -> for name, tab of tabs equal($("#tab_#{name} a").attr('href'), tab.href, "#{name} tab should link to #{tab.href}") unless tab.hidden - equal($("#tab_#{name}").hasClass('active'), !!tab.active, "#{name} tab should be active") + equal($("#tab_#{name}").hasClass('active'), !!tab.active, "#{name} tab should #{'not' unless tab.active} be active") equal($("#tab_#{name}").hasClass('display-inline'), !tab.hidden, "#{name} tab should has class display-inline") if name in ['build', 'job'] @displaysSummaryBuildLink = (link, number) -> diff --git a/assets/scripts/spec/support/mocks.coffee b/assets/scripts/spec/support/mocks.coffee index 7a5213c1..2220b866 100644 --- a/assets/scripts/spec/support/mocks.coffee +++ b/assets/scripts/spec/support/mocks.coffee @@ -3,9 +3,9 @@ minispade.require 'ext/jquery' responseTime = 0 repos = [ - { id: '1', owner: 'travis-ci', name: 'travis-core', slug: 'travis-ci/travis-core', build_ids: [1, 2], last_build_id: 1, last_build_number: 1, last_build_state: 'passed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:00:00Z', last_build_finished_at: '2012-07-02T00:00:30Z', description: 'Description of travis-core' }, - { id: '2', owner: 'travis-ci', name: 'travis-assets', slug: 'travis-ci/travis-assets', build_ids: [3], last_build_id: 3, last_build_number: 3, last_build_state: 'failed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:01:00Z', last_build_finished_at: '2012-07-01T00:01:30Z', description: 'Description of travis-assets'}, - { id: '3', owner: 'travis-ci', name: 'travis-hub', slug: 'travis-ci/travis-hub', build_ids: [4], last_build_id: 4, last_build_number: 4, last_build_state: null, last_build_duration: null, last_build_started_at: '2012-07-02T00:02:00Z', last_build_finished_at: null, description: 'Description of travis-hub'}, + { id: '1', owner: 'travis-ci', name: 'travis-core', slug: 'travis-ci/travis-core', build_ids: [1, 2], last_build_id: 1, last_build_number: 1, last_build_state: 'passed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:00:00Z', last_build_finished_at: '2012-07-02T00:00:30Z', description: 'Description of travis-core', github_language: 'ruby' }, + { id: '2', owner: 'travis-ci', name: 'travis-assets', slug: 'travis-ci/travis-assets', build_ids: [3], last_build_id: 3, last_build_number: 3, last_build_state: 'failed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:01:00Z', last_build_finished_at: '2012-07-01T00:01:30Z', description: 'Description of travis-assets', github_language: 'ruby'}, + { id: '3', owner: 'travis-ci', name: 'travis-hub', slug: 'travis-ci/travis-hub', build_ids: [4], last_build_id: 4, last_build_number: 4, last_build_state: null, last_build_duration: null, last_build_started_at: '2012-07-02T00:02:00Z', last_build_finished_at: null, description: 'Description of travis-hub', github_language: 'ruby' }, ] reposByName = (name) ->