From 4337949dd4d98ea9de04a412d48f8ac233588777 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 4 Mar 2013 13:29:00 +0100 Subject: [PATCH] Fix the rest of the specs --- assets/scripts/app/controllers/job.coffee | 12 ++++++ assets/scripts/app/store.coffee | 16 ++++++++ assets/scripts/app/templates/jobs/show.hbs | 34 ++++++++-------- assets/scripts/lib/travis/model.coffee | 4 +- assets/scripts/spec/event_spec.coffee | 39 +------------------ assets/scripts/spec/job_spec.coffee | 14 +++++-- .../scripts/spec/support/expectations.coffee | 5 +-- .../scripts/spec/unit/incomplete_spec.coffee | 2 +- 8 files changed, 64 insertions(+), 62 deletions(-) diff --git a/assets/scripts/app/controllers/job.coffee b/assets/scripts/app/controllers/job.coffee index 274a7555..9d5734fe 100644 --- a/assets/scripts/app/controllers/job.coffee +++ b/assets/scripts/app/controllers/job.coffee @@ -4,3 +4,15 @@ Travis.JobController = Em.Controller.extend jobBinding: 'controllers.repo.job' repoBinding: 'controllers.repo.repo' commitBinding: 'job.commit' + + urlGithubCommit: (-> + Travis.Urls.githubCommit(@get('repo.slug'), @get('commit.sha')) + ).property('repo.slug', 'commit.sha') + + urlAuthor: (-> + Travis.Urls.email(@get('commit.authorEmail')) + ).property('commit.authorEmail') + + urlCommitter: (-> + Travis.Urls.email(@get('commit.committerEmail')) + ).property('commit.committerEmail') diff --git a/assets/scripts/app/store.coffee b/assets/scripts/app/store.coffee index cf8f8d5c..b0a1717d 100644 --- a/assets/scripts/app/store.coffee +++ b/assets/scripts/app/store.coffee @@ -141,6 +141,7 @@ Travis.Store = DS.Store.extend result = @merge(type, hash, true) if result && result.clientId @addLoadedData(type, result.clientId, hash) + #@_updateRelationships(type, hash) result @@ -158,3 +159,18 @@ Travis.Store = DS.Store.extend root = type.pluralName() @adapter.sideload(store, type, json, root) @loadMany(type, json[root]) + + _updateRelationships: (type, data) -> + Em.get(type, 'relationshipsByName').forEach (key, meta) => + if meta.kind == 'belongsTo' + id = data["#{key}_id"] + if clientId = @typeMapFor(meta.type).idToCid[id] + if parent = this.findByClientId(meta.type, clientId, id) + dataProxy = parent.get('data') + if ids = dataProxy['hasMany'][type.pluralName()] + unless data.id in ids + state = parent.get('stateManager.currentState.path') + unless state == "rootState.loaded.materializing" + parent.send('materializingData') + ids.pushObject(data.id) + parent.notifyPropertyChange('data') diff --git a/assets/scripts/app/templates/jobs/show.hbs b/assets/scripts/app/templates/jobs/show.hbs index f24454ba..1d7a9989 100644 --- a/assets/scripts/app/templates/jobs/show.hbs +++ b/assets/scripts/app/templates/jobs/show.hbs @@ -19,22 +19,24 @@
{{formatDuration job.duration}}
-
-
{{t jobs.commit}}
-
{{formatCommit commit}}
- {{#if commit.compareUrl}} -
{{t jobs.compare}}
-
{{pathFrom commit.compareUrl}}
- {{/if}} - {{#if commit.authorName}} -
{{t jobs.author}}
-
{{commit.authorName}}
- {{/if}} - {{#if commit.committerName}} -
{{t jobs.committer}}
-
{{commit.committerName}}
- {{/if}} -
+ {{#if commit}} +
+
{{t jobs.commit}}
+
{{formatCommit commit}}
+ {{#if commit.compareUrl}} +
{{t jobs.compare}}
+
{{pathFrom commit.compareUrl}}
+ {{/if}} + {{#if commit.authorName}} +
{{t jobs.author}}
+
{{commit.authorName}}
+ {{/if}} + {{#if commit.committerName}} +
{{t jobs.committer}}
+
{{commit.committerName}}
+ {{/if}} +
+ {{/if}}
{{t jobs.message}}
{{formatMessage commit.message}}
diff --git a/assets/scripts/lib/travis/model.coffee b/assets/scripts/lib/travis/model.coffee index 9084dd02..4587033e 100644 --- a/assets/scripts/lib/travis/model.coffee +++ b/assets/scripts/lib/travis/model.coffee @@ -42,14 +42,14 @@ # undefined key return if !key || key == 'undefined' - message = "Load missing fields for #{@constructor.toString()} because of missing key '#{key}', cid: #{@get('clientId')}" + message = "Load missing fields for #{@constructor.toString()} because of missing key '#{key}', cid: #{@get('clientId')}, id: #{@get('id')}" if @constructor.isAttribute('state') && key != 'state' message += ", in state: #{@get('state')}" console.log message return if @get('isCompleting') @set 'isCompleting', true - if @get('stateManager.currentState.path') != 'rootState.loaded.materializing' + unless @get('stateManager.currentState.path').match /^rootState.loaded.materializing/ @reload() @set 'incomplete', false diff --git a/assets/scripts/spec/event_spec.coffee b/assets/scripts/spec/event_spec.coffee index e2bc6b87..8ea55595 100644 --- a/assets/scripts/spec/event_spec.coffee +++ b/assets/scripts/spec/event_spec.coffee @@ -54,10 +54,9 @@ describe 'events', -> started_at: '2012-07-02T00:02:00Z' finished_at: '2012-07-02T00:02:55Z' event_type: 'push' - result: 1 message: 'commit message 3' commit: '1234567' - state: 'started' + state: 'failed' Em.run -> Travis.receive 'build:started', payload @@ -75,40 +74,6 @@ describe 'events', -> runs -> waitFor queuesRendered - it 'adds a job to the jobs matrix', -> - payload = - job: - id: 15 - repository_id: 1 - build_id: 1 - commit_id: 1 - log_id: 1 - number: '1.4' - duration: 55 - started_at: '2012-07-02T00:02:00Z' - finished_at: '2012-07-02T00:02:55Z' - config: { rvm: 'jruby' } - - $.mockjax - url: '/jobs/15' - responseTime: 0 - responseText: payload - - Em.run -> - Travis.receive 'job:started', - job: - id: 15 - repository_id: 1 - build_id: 1 - commit_id: 1 - - waits(100) - runs -> - listsJob - table: $('#jobs') - row: 3 - item: { id: 15, number: '1.4', repo: 'travis-ci/travis-core', finishedAt: 'less than a minute ago', duration: '55 sec', rvm: 'jruby' } - it 'adds a job to the jobs queue', -> payload = job: @@ -191,7 +156,7 @@ describe 'events', -> app '/travis-ci/travis-core' waitFor workersRendered - it 'does not update repository if it\'s already in store', -> + it 'does not update repository if it\'s already in the store', -> payload = worker: id: 1 diff --git a/assets/scripts/spec/job_spec.coffee b/assets/scripts/spec/job_spec.coffee index 73e63337..4b4c5f88 100644 --- a/assets/scripts/spec/job_spec.coffee +++ b/assets/scripts/spec/job_spec.coffee @@ -1,5 +1,11 @@ describe 'on the "job" state', -> beforeEach -> + $.mockjax + url: '/jobs/1/log?cors_hax=true' + responseTime: 0 + responseText: 'log 1' + + app 'travis-ci/travis-core/jobs/1' waitFor jobRendered runs -> @@ -32,6 +38,8 @@ describe 'on the "job" state', -> build: { href: '/travis-ci/travis-core/builds/1' } job: { href: '/travis-ci/travis-core/jobs/1', active: true } - displaysLog [ - 'log 1' - ] + waits 10 + runs -> + displaysLog [ + 'log 1' + ] diff --git a/assets/scripts/spec/support/expectations.coffee b/assets/scripts/spec/support/expectations.coffee index 6365fdc7..edf80ddc 100644 --- a/assets/scripts/spec/support/expectations.coffee +++ b/assets/scripts/spec/support/expectations.coffee @@ -41,9 +41,8 @@ expect(element.text()).toEqual data.message @displaysLog = (lines) -> - ix = 0 - log = $.map(lines, (line) -> ix += 1; "#{ix}#{line}").join("\n") - expect($('#log p').text().trim()).toEqual log + log = lines.join() + expect($('#log').text().trim()).toEqual log @listsRepos = (items) -> listsItems('repo', items) diff --git a/assets/scripts/spec/unit/incomplete_spec.coffee b/assets/scripts/spec/unit/incomplete_spec.coffee index 02431802..adf501c3 100644 --- a/assets/scripts/spec/unit/incomplete_spec.coffee +++ b/assets/scripts/spec/unit/incomplete_spec.coffee @@ -129,7 +129,7 @@ describe 'Travis.Model - incomplete', -> waits 50 runs -> - expect( record.get('description') ).toEqual 'bar' + expect( other.get('record.description') ).toEqual 'bar' expect( record.get('isComplete') ).toBeTruthy() it 'loads missing data on try to get it', ->