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 name
name = name.replace('travis-', '')
if state == 'working' && payload != undefined if state == 'working' && payload != undefined
repo = if payload.repository then $.truncate(payload.repository.slug, 18) else undefined repo = if payload.repository then $.truncate(payload.repository.slug, 18) else undefined
number = if payload.build and payload.build.number then ' #' + payload.build.number else '' number = if payload.build and payload.build.number then ' #' + payload.build.number else ''
state = if repo then repo + number else state state = if repo then repo + number else state
name + ': ' + state name + ': ' + state
).property('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,8 +33,9 @@ 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')
if clientId
DATA_PROXY.savedData = hash DATA_PROXY.savedData = hash
@updateRecordArrays(type, clientId, DATA_PROXY) @updateRecordArrays(type, clientId, DATA_PROXY)

View File

@ -11,8 +11,7 @@ describe 'events', ->
waitFor reposRendered waitFor reposRendered
runs -> runs ->
Em.run -> payload =
Travis.app.receive 'build',
repository: repository:
id: 10 id: 10
slug: 'travis-ci/travis-support' slug: 'travis-ci/travis-support'
@ -24,6 +23,18 @@ describe 'events', ->
id: 10 id: 10
repository_id: 10 repository_id: 10
$.mockjax
url: '/builds/10'
responseTime: 0
responseText: payload
Em.run ->
Travis.app.receive 'build:started',
build:
id: 10
waits(100)
runs ->
listsRepo listsRepo
row: 2 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' } } 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' } }
@ -34,12 +45,11 @@ 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: 10 id: 11
repository_id: 1 repository_id: 1
commit_id: 10 commit_id: 11
number: '3' number: '3'
duration: 55 duration: 55
started_at: '2012-07-02T00:02:00Z' started_at: '2012-07-02T00:02:00Z'
@ -47,14 +57,27 @@ describe 'events', ->
event_type: 'push' event_type: 'push'
result: 1 result: 1
commit: commit:
id: 10 id: 11
sha: '1234567' sha: '1234567'
branch: 'master' branch: 'master'
message: 'commit message 3' message: 'commit message 3'
$.mockjax
url: '/builds/11'
responseTime: 0
responseText: payload
Em.run ->
Travis.app.receive 'build:started',
build:
id: 11
waits(100)
runs ->
listsBuild listsBuild
row: 3 row: 3
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' } 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,10 +87,9 @@ 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: 10 id: 15
repository_id: 1 repository_id: 1
build_id: 1 build_id: 1
commit_id: 1 commit_id: 1
@ -78,20 +100,44 @@ describe 'events', ->
finished_at: '2012-07-02T00:02:55Z' finished_at: '2012-07-02T00:02:55Z'
config: { rvm: 'jruby' } config: { rvm: 'jruby' }
$.mockjax
url: '/jobs/15'
responseTime: 0
responseText: payload
Em.run ->
Travis.app.receive 'job:started',
job:
id: 15
build_id: 1
waits(100)
runs ->
listsJob listsJob
table: $('#jobs') table: $('#jobs')
row: 3 row: 3
item: { id: 10, number: '1.4', repo: 'travis-ci/travis-core', finishedAt: 'less than a minute ago', duration: '55 sec', rvm: 'jruby' } 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: 10 id: 12
repository_id: 1 repository_id: 1
number: '1.4' number: '1.4'
queue: 'common' queue: 'common'
$.mockjax
url: '/jobs/12'
responseTime: 0
responseText: payload
Em.run ->
Travis.app.receive 'job:started',
job:
id: 12
waits(100)
runs ->
listsQueuedJob listsQueuedJob
name: 'common' name: 'common'
row: 3 row: 3
@ -99,11 +145,13 @@ describe 'events', ->
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
waits(100)
runs ->
listsJob listsJob
table: $('#jobs') table: $('#jobs')
row: 1 row: 1
@ -115,14 +163,28 @@ describe 'events', ->
waitFor workersRendered waitFor workersRendered
it 'adds a worker to the workers list', -> it 'adds a worker to the workers list', ->
Em.run -> payload =
Travis.app.receive 'worker',
worker: worker:
id: 10
host: 'worker.travis-ci.org' host: 'worker.travis-ci.org'
name: 'ruby-3' name: 'ruby-3'
state: 'ready' state: 'ready'
id: 10
$.mockjax
url: '/workers/10'
responseTime: 0
responseText: payload
Em.run ->
Travis.app.receive 'worker:created',
worker:
id: 10
name: 'ruby-3'
host: 'worker.travis-ci.org'
state: 'ready'
waits(100)
runs ->
listsWorker listsWorker
group: 'worker.travis-ci.org' group: 'worker.travis-ci.org'
row: 3 row: 3

File diff suppressed because one or more lines are too long

View File

@ -316,8 +316,8 @@
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() {
Em.run(function() { var payload;
return Travis.app.receive('build', { payload = {
repository: { repository: {
id: 10, id: 10,
slug: 'travis-ci/travis-support', slug: 'travis-ci/travis-support',
@ -330,8 +330,21 @@
id: 10, id: 10,
repository_id: 10 repository_id: 10
} }
};
$.mockjax({
url: '/builds/10',
responseTime: 0,
responseText: payload
});
Em.run(function() {
return Travis.app.receive('build:started', {
build: {
id: 10
}
}); });
}); });
waits(100);
return runs(function() {
return listsRepo({ return listsRepo({
row: 2, row: 2,
item: { item: {
@ -347,18 +360,19 @@
}); });
}); });
}); });
});
describe('an event adding a build', function() { describe('an event adding a build', function() {
beforeEach(function() { beforeEach(function() {
app('travis-ci/travis-core/builds'); app('travis-ci/travis-core/builds');
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() {
Em.run(function() { var payload;
return Travis.app.receive('build', { payload = {
build: { build: {
id: 10, id: 11,
repository_id: 1, repository_id: 1,
commit_id: 10, commit_id: 11,
number: '3', number: '3',
duration: 55, duration: 55,
started_at: '2012-07-02T00:02:00Z', started_at: '2012-07-02T00:02:00Z',
@ -367,17 +381,30 @@
result: 1 result: 1
}, },
commit: { commit: {
id: 10, id: 11,
sha: '1234567', sha: '1234567',
branch: 'master', branch: 'master',
message: 'commit message 3' message: 'commit message 3'
} }
};
$.mockjax({
url: '/builds/11',
responseTime: 0,
responseText: payload
});
Em.run(function() {
return Travis.app.receive('build:started', {
build: {
id: 11
}
}); });
}); });
waits(100);
return runs(function() {
return listsBuild({ return listsBuild({
row: 3, row: 3,
item: { item: {
id: 10, id: 11,
slug: 'travis-ci/travis-core', slug: 'travis-ci/travis-core',
number: '3', number: '3',
sha: '1234567', sha: '1234567',
@ -390,6 +417,7 @@
}); });
}); });
}); });
});
describe('an event adding a job', function() { describe('an event adding a job', function() {
beforeEach(function() { beforeEach(function() {
app('travis-ci/travis-core'); app('travis-ci/travis-core');
@ -399,10 +427,10 @@
}); });
}); });
it('adds a job to the jobs matrix', function() { it('adds a job to the jobs matrix', function() {
Em.run(function() { var payload;
return Travis.app.receive('job', { payload = {
job: { job: {
id: 10, id: 15,
repository_id: 1, repository_id: 1,
build_id: 1, build_id: 1,
commit_id: 1, commit_id: 1,
@ -415,13 +443,27 @@
rvm: 'jruby' rvm: 'jruby'
} }
} }
};
$.mockjax({
url: '/jobs/15',
responseTime: 0,
responseText: payload
});
Em.run(function() {
return Travis.app.receive('job:started', {
job: {
id: 15,
build_id: 1
}
}); });
}); });
waits(100);
return runs(function() {
return listsJob({ return listsJob({
table: $('#jobs'), table: $('#jobs'),
row: 3, row: 3,
item: { item: {
id: 10, id: 15,
number: '1.4', number: '1.4',
repo: 'travis-ci/travis-core', repo: 'travis-ci/travis-core',
finishedAt: 'less than a minute ago', finishedAt: 'less than a minute ago',
@ -430,17 +472,31 @@
} }
}); });
}); });
});
it('adds a job to the jobs queue', function() { it('adds a job to the jobs queue', function() {
Em.run(function() { var payload;
return Travis.app.receive('job', { payload = {
job: { job: {
id: 10, id: 12,
repository_id: 1, repository_id: 1,
number: '1.4', number: '1.4',
queue: 'common' queue: 'common'
} }
};
$.mockjax({
url: '/jobs/12',
responseTime: 0,
responseText: payload
});
Em.run(function() {
return Travis.app.receive('job:started', {
job: {
id: 12
}
}); });
}); });
waits(100);
return runs(function() {
return listsQueuedJob({ return listsQueuedJob({
name: 'common', name: 'common',
row: 3, row: 3,
@ -450,15 +506,18 @@
} }
}); });
}); });
});
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
} }
}); });
}); });
waits(100);
return runs(function() {
return listsJob({ return listsJob({
table: $('#jobs'), table: $('#jobs'),
row: 1, row: 1,
@ -473,22 +532,39 @@
}); });
}); });
}); });
});
return describe('an event adding a worker', function() { return describe('an event adding a worker', function() {
beforeEach(function() { beforeEach(function() {
app(''); app('');
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: {
id: 10,
host: 'worker.travis-ci.org', host: 'worker.travis-ci.org',
name: 'ruby-3', name: 'ruby-3',
state: 'ready', state: 'ready'
id: 10 }
};
$.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({ return listsWorker({
group: 'worker.travis-ci.org', group: 'worker.travis-ci.org',
row: 3, row: 3,
@ -500,6 +576,7 @@
}); });
}); });
}); });
});
}).call(this); }).call(this);
(function() { (function() {