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')
display: (->
name = @get('name').replace('travis-', '')
name = @get('name')
state = @get('state')
payload = @get('payload')
if state == 'working' && payload != 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 ''
state = if repo then repo + number else state
name + ': ' + state
).property('state')
if name
name = name.replace('travis-', '')
if state == 'working' && payload != 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 ''
state = if repo then repo + number else state
name + ': ' + state
).property('state', 'name', 'payload')
urlJob: (->
"/#{@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
# that's not yet available, just use find
# to make a request to fetch it
@find(type, id)
clientId = @find(type, id).get('clientId')
DATA_PROXY.savedData = hash
@updateRecordArrays(type, clientId, DATA_PROXY)
if clientId
DATA_PROXY.savedData = hash
@updateRecordArrays(type, clientId, DATA_PROXY)
{ id: id, clientId: clientId }
{ id: id, clientId: clientId }
receive: (event, data) ->
[name, type] = event.split(':')

View File

@ -11,22 +11,33 @@ describe 'events', ->
waitFor reposRendered
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 ->
Travis.app.receive 'build',
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'
Travis.app.receive 'build:started',
build:
id: 10
repository_id: 10
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' } }
waits(100)
runs ->
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', ->
beforeEach ->
@ -34,27 +45,39 @@ describe 'events', ->
waitFor buildsRendered
it 'adds a build to the builds list', ->
Em.run ->
Travis.app.receive 'build',
build:
id: 10
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'
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'
listsBuild
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' }
$.mockjax
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', ->
beforeEach ->
@ -64,50 +87,75 @@ describe 'events', ->
waitFor queuesRendered
it 'adds a job to the jobs matrix', ->
Em.run ->
Travis.app.receive 'job',
job:
id: 10
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' }
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' }
listsJob
table: $('#jobs')
row: 3
item: { id: 10, number: '1.4', repo: 'travis-ci/travis-core', finishedAt: 'less than a minute ago', duration: '55 sec', 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
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', ->
Em.run ->
Travis.app.receive 'job',
job:
id: 10
repository_id: 1
number: '1.4'
queue: 'common'
payload =
job:
id: 12
repository_id: 1
number: '1.4'
queue: 'common'
listsQueuedJob
name: 'common'
row: 3
item: { number: '1.4', repo: 'travis-ci/travis-core' }
$.mockjax
url: '/jobs/12'
responseTime: 0
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', ->
Em.run ->
Travis.app.receive 'job',
Travis.app.receive 'job:started',
job:
id: 1
build_id: 1
listsJob
table: $('#jobs')
row: 1
item: { id: 1, number: '1.1', repo: 'travis-ci/travis-core', finishedAt: '3 minutes ago', duration: '30 sec', rvm: 'rbx' }
waits(100)
runs ->
listsJob
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', ->
beforeEach ->
@ -115,16 +163,30 @@ describe 'events', ->
waitFor workersRendered
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 ->
Travis.app.receive 'worker',
Travis.app.receive 'worker:created',
worker:
host: 'worker.travis-ci.org'
name: 'ruby-3'
state: 'ready'
id: 10
name: 'ruby-3'
host: 'worker.travis-ci.org'
state: 'ready'
listsWorker
group: 'worker.travis-ci.org'
row: 3
item: { name: 'ruby-3', state: 'ready' }
waits(100)
runs ->
listsWorker
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() {
waitFor(reposRendered);
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() {
return Travis.app.receive('build', {
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'
},
return Travis.app.receive('build:started', {
build: {
id: 10,
repository_id: 10
id: 10
}
});
});
return 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'
waits(100);
return runs(function() {
return 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'
}
}
}
});
});
});
});
@ -353,40 +367,54 @@
return waitFor(buildsRendered);
});
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() {
return Travis.app.receive('build', {
return Travis.app.receive('build:started', {
build: {
id: 10,
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'
id: 11
}
});
});
return listsBuild({
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'
}
waits(100);
return runs(function() {
return 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'
}
});
});
});
});
@ -399,77 +427,109 @@
});
});
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() {
return Travis.app.receive('job', {
return Travis.app.receive('job:started', {
job: {
id: 10,
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'
}
id: 15,
build_id: 1
}
});
});
return listsJob({
table: $('#jobs'),
row: 3,
item: {
id: 10,
number: '1.4',
repo: 'travis-ci/travis-core',
finishedAt: 'less than a minute ago',
duration: '55 sec',
rvm: 'jruby'
}
waits(100);
return runs(function() {
return 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', 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() {
return Travis.app.receive('job', {
return Travis.app.receive('job:started', {
job: {
id: 10,
repository_id: 1,
number: '1.4',
queue: 'common'
id: 12
}
});
});
return listsQueuedJob({
name: 'common',
row: 3,
item: {
number: '1.4',
repo: 'travis-ci/travis-core'
}
waits(100);
return runs(function() {
return listsQueuedJob({
name: 'common',
row: 3,
item: {
number: '1.4',
repo: 'travis-ci/travis-core'
}
});
});
});
return it('updates only keys that are available', function() {
Em.run(function() {
return Travis.app.receive('job', {
return Travis.app.receive('job:started', {
job: {
id: 1,
build_id: 1
}
});
});
return listsJob({
table: $('#jobs'),
row: 1,
item: {
id: 1,
number: '1.1',
repo: 'travis-ci/travis-core',
finishedAt: '3 minutes ago',
duration: '30 sec',
rvm: 'rbx'
}
waits(100);
return runs(function() {
return listsJob({
table: $('#jobs'),
row: 1,
item: {
id: 1,
number: '1.1',
repo: 'travis-ci/travis-core',
finishedAt: '3 minutes ago',
duration: '30 sec',
rvm: 'rbx'
}
});
});
});
});
@ -479,23 +539,40 @@
return waitFor(workersRendered);
});
return it('adds a worker to the workers list', function() {
Em.run(function() {
return Travis.app.receive('worker', {
worker: {
host: 'worker.travis-ci.org',
name: 'ruby-3',
state: 'ready',
id: 10
}
});
});
return listsWorker({
group: 'worker.travis-ci.org',
row: 3,
item: {
var payload;
payload = {
worker: {
id: 10,
host: 'worker.travis-ci.org',
name: 'ruby-3',
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'
}
});
});
});
});