Fix specs and a bug that they've catched

Specs needed to be updated to handle new way of receiving methods.
What's more they revealed a subtle bug that was present after changing
merge function to fetch record if it's not present.

After calling merge, store calls method to update associations. This
may be not possible if clientId for new record is not correctly set.
This commit is contained in:
Piotr Sarnacki 2012-08-12 02:23:37 +02:00
parent f7422e15c7
commit 8b25160a62
5 changed files with 339 additions and 197 deletions

View File

@ -15,15 +15,17 @@ require 'travis/model'
).property('name') ).property('name')
display: (-> display: (->
name = @get('name').replace('travis-', '') name = @get('name')
state = @get('state') state = @get('state')
payload = @get('payload') payload = @get('payload')
if state == 'working' && payload != undefined if name
repo = if payload.repository then $.truncate(payload.repository.slug, 18) else undefined name = name.replace('travis-', '')
number = if payload.build and payload.build.number then ' #' + payload.build.number else '' if state == 'working' && payload != undefined
state = if repo then repo + number else state repo = if payload.repository then $.truncate(payload.repository.slug, 18) else undefined
name + ': ' + state number = if payload.build and payload.build.number then ' #' + payload.build.number else ''
).property('state') state = if repo then repo + number else state
name + ': ' + state
).property('state', 'name', 'payload')
urlJob: (-> urlJob: (->
"/#{@get('repository')}/jobs/#{@get('job_id')}" if @get('state') == 'working' "/#{@get('repository')}/jobs/#{@get('job_id')}" if @get('state') == 'working'

View File

@ -33,12 +33,13 @@ Travis.Store = DS.Store.extend
# if event is triggered for a record # if event is triggered for a record
# that's not yet available, just use find # that's not yet available, just use find
# to make a request to fetch it # to make a request to fetch it
@find(type, id) clientId = @find(type, id).get('clientId')
DATA_PROXY.savedData = hash if clientId
@updateRecordArrays(type, clientId, DATA_PROXY) DATA_PROXY.savedData = hash
@updateRecordArrays(type, clientId, DATA_PROXY)
{ id: id, clientId: clientId } { id: id, clientId: clientId }
receive: (event, data) -> receive: (event, data) ->
[name, type] = event.split(':') [name, type] = event.split(':')

View File

@ -11,22 +11,33 @@ describe 'events', ->
waitFor reposRendered waitFor reposRendered
runs -> runs ->
payload =
repository:
id: 10
slug: 'travis-ci/travis-support'
last_build_id: 10
last_build_number: 10
last_build_started_at: '2012-07-02T00:01:00Z'
last_build_finished_at: '2012-07-02T00:02:30Z'
build:
id: 10
repository_id: 10
$.mockjax
url: '/builds/10'
responseTime: 0
responseText: payload
Em.run -> Em.run ->
Travis.app.receive 'build', Travis.app.receive 'build:started',
repository:
id: 10
slug: 'travis-ci/travis-support'
last_build_id: 10
last_build_number: 10
last_build_started_at: '2012-07-02T00:01:00Z'
last_build_finished_at: '2012-07-02T00:02:30Z'
build: build:
id: 10 id: 10
repository_id: 10
listsRepo waits(100)
row: 2 runs ->
item: { slug: 'travis-ci/travis-support', build: { number: 4, url: '/travis-ci/travis-support/builds/10', duration: '1 min 30 sec', finishedAt: 'less than a minute ago' } } listsRepo
row: 2
item: { slug: 'travis-ci/travis-support', build: { number: 4, url: '/travis-ci/travis-support/builds/10', duration: '1 min 30 sec', finishedAt: 'less than a minute ago' } }
describe 'an event adding a build', -> describe 'an event adding a build', ->
beforeEach -> beforeEach ->
@ -34,27 +45,39 @@ describe 'events', ->
waitFor buildsRendered waitFor buildsRendered
it 'adds a build to the builds list', -> it 'adds a build to the builds list', ->
Em.run -> payload =
Travis.app.receive 'build', build:
build: id: 11
id: 10 repository_id: 1
repository_id: 1 commit_id: 11
commit_id: 10 number: '3'
number: '3' duration: 55
duration: 55 started_at: '2012-07-02T00:02:00Z'
started_at: '2012-07-02T00:02:00Z' finished_at: '2012-07-02T00:02:55Z'
finished_at: '2012-07-02T00:02:55Z' event_type: 'push'
event_type: 'push' result: 1
result: 1 commit:
commit: id: 11
id: 10 sha: '1234567'
sha: '1234567' branch: 'master'
branch: 'master' message: 'commit message 3'
message: 'commit message 3'
listsBuild
row: 3 $.mockjax
item: { id: 10, slug: 'travis-ci/travis-core', number: '3', sha: '1234567', branch: 'master', message: 'commit message 3', finishedAt: 'less than a minute ago', duration: '55 sec', color: 'red' } url: '/builds/11'
responseTime: 0
responseText: payload
Em.run ->
Travis.app.receive 'build:started',
build:
id: 11
waits(100)
runs ->
listsBuild
row: 3
item: { id: 11, slug: 'travis-ci/travis-core', number: '3', sha: '1234567', branch: 'master', message: 'commit message 3', finishedAt: 'less than a minute ago', duration: '55 sec', color: 'red' }
describe 'an event adding a job', -> describe 'an event adding a job', ->
beforeEach -> beforeEach ->
@ -64,50 +87,75 @@ describe 'events', ->
waitFor queuesRendered waitFor queuesRendered
it 'adds a job to the jobs matrix', -> it 'adds a job to the jobs matrix', ->
Em.run -> payload =
Travis.app.receive 'job', job:
job: id: 15
id: 10 repository_id: 1
repository_id: 1 build_id: 1
build_id: 1 commit_id: 1
commit_id: 1 log_id: 1
log_id: 1 number: '1.4'
number: '1.4' duration: 55
duration: 55 started_at: '2012-07-02T00:02:00Z'
started_at: '2012-07-02T00:02:00Z' finished_at: '2012-07-02T00:02:55Z'
finished_at: '2012-07-02T00:02:55Z' config: { rvm: 'jruby' }
config: { rvm: 'jruby' }
listsJob $.mockjax
table: $('#jobs') url: '/jobs/15'
row: 3 responseTime: 0
item: { id: 10, number: '1.4', repo: 'travis-ci/travis-core', finishedAt: 'less than a minute ago', duration: '55 sec', rvm: 'jruby' } responseText: payload
Em.run ->
Travis.app.receive 'job:started',
job:
id: 15
build_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', -> it 'adds a job to the jobs queue', ->
Em.run -> payload =
Travis.app.receive 'job', job:
job: id: 12
id: 10 repository_id: 1
repository_id: 1 number: '1.4'
number: '1.4' queue: 'common'
queue: 'common'
listsQueuedJob $.mockjax
name: 'common' url: '/jobs/12'
row: 3 responseTime: 0
item: { number: '1.4', repo: 'travis-ci/travis-core' } responseText: payload
Em.run ->
Travis.app.receive 'job:started',
job:
id: 12
waits(100)
runs ->
listsQueuedJob
name: 'common'
row: 3
item: { number: '1.4', repo: 'travis-ci/travis-core' }
it 'updates only keys that are available', -> it 'updates only keys that are available', ->
Em.run -> Em.run ->
Travis.app.receive 'job', Travis.app.receive 'job:started',
job: job:
id: 1 id: 1
build_id: 1 build_id: 1
listsJob waits(100)
table: $('#jobs') runs ->
row: 1 listsJob
item: { id: 1, number: '1.1', repo: 'travis-ci/travis-core', finishedAt: '3 minutes ago', duration: '30 sec', rvm: 'rbx' } table: $('#jobs')
row: 1
item: { id: 1, number: '1.1', repo: 'travis-ci/travis-core', finishedAt: '3 minutes ago', duration: '30 sec', rvm: 'rbx' }
describe 'an event adding a worker', -> describe 'an event adding a worker', ->
beforeEach -> beforeEach ->
@ -115,16 +163,30 @@ describe 'events', ->
waitFor workersRendered waitFor workersRendered
it 'adds a worker to the workers list', -> it 'adds a worker to the workers list', ->
payload =
worker:
id: 10
host: 'worker.travis-ci.org'
name: 'ruby-3'
state: 'ready'
$.mockjax
url: '/workers/10'
responseTime: 0
responseText: payload
Em.run -> Em.run ->
Travis.app.receive 'worker', Travis.app.receive 'worker:created',
worker: worker:
host: 'worker.travis-ci.org'
name: 'ruby-3'
state: 'ready'
id: 10 id: 10
name: 'ruby-3'
host: 'worker.travis-ci.org'
state: 'ready'
listsWorker waits(100)
group: 'worker.travis-ci.org' runs ->
row: 3 listsWorker
item: { name: 'ruby-3', state: 'ready' } group: 'worker.travis-ci.org'
row: 3
item: { name: 'ruby-3', state: 'ready' }

File diff suppressed because one or more lines are too long

View File

@ -316,33 +316,47 @@
return it('adds a repository to the list', function() { return it('adds a repository to the list', function() {
waitFor(reposRendered); waitFor(reposRendered);
return runs(function() { return runs(function() {
var payload;
payload = {
repository: {
id: 10,
slug: 'travis-ci/travis-support',
last_build_id: 10,
last_build_number: 10,
last_build_started_at: '2012-07-02T00:01:00Z',
last_build_finished_at: '2012-07-02T00:02:30Z'
},
build: {
id: 10,
repository_id: 10
}
};
$.mockjax({
url: '/builds/10',
responseTime: 0,
responseText: payload
});
Em.run(function() { Em.run(function() {
return Travis.app.receive('build', { return Travis.app.receive('build:started', {
repository: {
id: 10,
slug: 'travis-ci/travis-support',
last_build_id: 10,
last_build_number: 10,
last_build_started_at: '2012-07-02T00:01:00Z',
last_build_finished_at: '2012-07-02T00:02:30Z'
},
build: { build: {
id: 10, id: 10
repository_id: 10
} }
}); });
}); });
return listsRepo({ waits(100);
row: 2, return runs(function() {
item: { return listsRepo({
slug: 'travis-ci/travis-support', row: 2,
build: { item: {
number: 4, slug: 'travis-ci/travis-support',
url: '/travis-ci/travis-support/builds/10', build: {
duration: '1 min 30 sec', number: 4,
finishedAt: 'less than a minute ago' url: '/travis-ci/travis-support/builds/10',
duration: '1 min 30 sec',
finishedAt: 'less than a minute ago'
}
} }
} });
}); });
}); });
}); });
@ -353,40 +367,54 @@
return waitFor(buildsRendered); return waitFor(buildsRendered);
}); });
return it('adds a build to the builds list', function() { return it('adds a build to the builds list', function() {
var payload;
payload = {
build: {
id: 11,
repository_id: 1,
commit_id: 11,
number: '3',
duration: 55,
started_at: '2012-07-02T00:02:00Z',
finished_at: '2012-07-02T00:02:55Z',
event_type: 'push',
result: 1
},
commit: {
id: 11,
sha: '1234567',
branch: 'master',
message: 'commit message 3'
}
};
$.mockjax({
url: '/builds/11',
responseTime: 0,
responseText: payload
});
Em.run(function() { Em.run(function() {
return Travis.app.receive('build', { return Travis.app.receive('build:started', {
build: { build: {
id: 10, id: 11
repository_id: 1,
commit_id: 10,
number: '3',
duration: 55,
started_at: '2012-07-02T00:02:00Z',
finished_at: '2012-07-02T00:02:55Z',
event_type: 'push',
result: 1
},
commit: {
id: 10,
sha: '1234567',
branch: 'master',
message: 'commit message 3'
} }
}); });
}); });
return listsBuild({ waits(100);
row: 3, return runs(function() {
item: { return listsBuild({
id: 10, row: 3,
slug: 'travis-ci/travis-core', item: {
number: '3', id: 11,
sha: '1234567', slug: 'travis-ci/travis-core',
branch: 'master', number: '3',
message: 'commit message 3', sha: '1234567',
finishedAt: 'less than a minute ago', branch: 'master',
duration: '55 sec', message: 'commit message 3',
color: 'red' finishedAt: 'less than a minute ago',
} duration: '55 sec',
color: 'red'
}
});
}); });
}); });
}); });
@ -399,77 +427,109 @@
}); });
}); });
it('adds a job to the jobs matrix', function() { it('adds a job to the jobs matrix', function() {
var payload;
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(function() { Em.run(function() {
return Travis.app.receive('job', { return Travis.app.receive('job:started', {
job: { job: {
id: 10, id: 15,
repository_id: 1, build_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'
}
} }
}); });
}); });
return listsJob({ waits(100);
table: $('#jobs'), return runs(function() {
row: 3, return listsJob({
item: { table: $('#jobs'),
id: 10, row: 3,
number: '1.4', item: {
repo: 'travis-ci/travis-core', id: 15,
finishedAt: 'less than a minute ago', number: '1.4',
duration: '55 sec', repo: 'travis-ci/travis-core',
rvm: 'jruby' finishedAt: 'less than a minute ago',
} duration: '55 sec',
rvm: 'jruby'
}
});
}); });
}); });
it('adds a job to the jobs queue', function() { it('adds a job to the jobs queue', function() {
var payload;
payload = {
job: {
id: 12,
repository_id: 1,
number: '1.4',
queue: 'common'
}
};
$.mockjax({
url: '/jobs/12',
responseTime: 0,
responseText: payload
});
Em.run(function() { Em.run(function() {
return Travis.app.receive('job', { return Travis.app.receive('job:started', {
job: { job: {
id: 10, id: 12
repository_id: 1,
number: '1.4',
queue: 'common'
} }
}); });
}); });
return listsQueuedJob({ waits(100);
name: 'common', return runs(function() {
row: 3, return listsQueuedJob({
item: { name: 'common',
number: '1.4', row: 3,
repo: 'travis-ci/travis-core' item: {
} number: '1.4',
repo: 'travis-ci/travis-core'
}
});
}); });
}); });
return it('updates only keys that are available', function() { return it('updates only keys that are available', function() {
Em.run(function() { Em.run(function() {
return Travis.app.receive('job', { return Travis.app.receive('job:started', {
job: { job: {
id: 1, id: 1,
build_id: 1 build_id: 1
} }
}); });
}); });
return listsJob({ waits(100);
table: $('#jobs'), return runs(function() {
row: 1, return listsJob({
item: { table: $('#jobs'),
id: 1, row: 1,
number: '1.1', item: {
repo: 'travis-ci/travis-core', id: 1,
finishedAt: '3 minutes ago', number: '1.1',
duration: '30 sec', repo: 'travis-ci/travis-core',
rvm: 'rbx' finishedAt: '3 minutes ago',
} duration: '30 sec',
rvm: 'rbx'
}
});
}); });
}); });
}); });
@ -479,23 +539,40 @@
return waitFor(workersRendered); return waitFor(workersRendered);
}); });
return it('adds a worker to the workers list', function() { return it('adds a worker to the workers list', function() {
Em.run(function() { var payload;
return Travis.app.receive('worker', { payload = {
worker: { worker: {
host: 'worker.travis-ci.org', id: 10,
name: 'ruby-3', host: 'worker.travis-ci.org',
state: 'ready',
id: 10
}
});
});
return listsWorker({
group: 'worker.travis-ci.org',
row: 3,
item: {
name: 'ruby-3', name: 'ruby-3',
state: 'ready' state: 'ready'
} }
};
$.mockjax({
url: '/workers/10',
responseTime: 0,
responseText: payload
});
Em.run(function() {
return Travis.app.receive('worker:created', {
worker: {
id: 10,
name: 'ruby-3',
host: 'worker.travis-ci.org',
state: 'ready'
}
});
});
waits(100);
return runs(function() {
return listsWorker({
group: 'worker.travis-ci.org',
row: 3,
item: {
name: 'ruby-3',
state: 'ready'
}
});
}); });
}); });
}); });