Fix pusher events and pusher related specs

This commit is contained in:
Piotr Sarnacki 2012-07-30 22:25:33 +02:00
parent f71a1daab9
commit 65d844f480
9 changed files with 538 additions and 359 deletions

View File

@ -26,7 +26,7 @@ Travis.reopen
@store.loadMany(Travis.Sponsor, Travis.SPONSORS)
@routes = new Travis.Routes()
# @pusher = new Travis.Pusher()
@pusher = new Travis.Pusher()
connect: ->
@controller = Em.Controller.create()
@ -35,6 +35,9 @@ Travis.reopen
controller: @controller
view.appendTo(@get('rootElement') || 'body')
receive: ->
@store.receive.apply(@store, arguments)
connectLayout: (name) ->
unless @get('layout.name') == name
name = $.camelize(name)

View File

@ -14,13 +14,13 @@ require 'travis/model'
builds: (->
id = @get('id')
Travis.Build.byRepositoryId id, event_type: 'push'
Travis.Build.filter (data) -> parseInt(data.get('repository_id')) == id && data.get('pull_request') == false
Travis.Build.filter (data) -> parseInt(data.get('repository_id')) == id && !data.get('pull_request')
).property()
pullRequests: (->
id = @get('id')
Travis.Build.byRepositoryId id, event_type: 'pull_request'
Travis.Build.filter (data) -> parseInt(data.get('repository_id')) == id && data.get('pull_request') == true
Travis.Build.filter (data) -> parseInt(data.get('repository_id')) == id && data.get('pull_request')
).property()
branches: (->

View File

@ -26,7 +26,9 @@ $.extend Travis.Pusher.prototype,
"#{Travis.Pusher.CHANNEL_PREFIX}#{channel}"
receive: (event, data) ->
data = @normalize(event, data) if data.id
if data.id
data = @normalize(event, data)
console.log(event, data)
Travis.app.store.receive(event.split(':')[0], data)
normalize: (event, data) ->

View File

@ -19,41 +19,20 @@ Travis.Store = DS.Store.extend
root = type.singularName()
@adapter.sideload(store, type, json, root)
type.load(json[root])
@_updateAssociations(type, name, json[root])
@_updateAssociations(type, root, json[root])
_loadMany: (store, type, json) ->
root = type.pluralName()
@adapter.sideload(store, type, json, root)
@loadMany(type, json[root])
# _updateAssociations: (type, name, data) ->
# Em.get(type, 'associationsByName').forEach (key, meta) =>
# if meta.kind == 'belongsTo' && id = data["#{key}_id"]
# parent = type.find(data.id).get("#{key}.data")
# ids = parent.get("data.#{name}_ids")
# parent.set("data.#{name}_ids", ids.concat(data.id)) # if ids && !(data.id in ids)
# _updateAssociations: (type, name, data) ->
# Em.get(type, 'associationsByName').forEach (key, meta) =>
# console.log [type, meta.type, meta.kind, meta.kind == 'belongsTo']
# if meta.kind == 'belongsTo'
# id = data["#{key}_id"]
# if clientId = @typeMapFor(meta.type).idToCid[id]
# if parent = this.findByClientId(meta.type, clientId, id)
# data = parent.get('data')
# if ids = data.get("#{name}_ids")
# ids.pushObject(data.id) unless data.id in ids
# parent.send('didChangeData');
# _updateAssociations: (type, name, data) ->
# clientId = @typeMapFor(Travis.Repository).idToCid[data['repository_id']]
# associations = Em.get(type, 'associationsByName')
# console.log [type, meta.type, meta.kind, meta.kind == 'belongsTo']
# if meta.kind == 'belongsTo'
# id = data["#{key}_id"]
# if parent = this.findByClientId(meta.type, clientId, id)
# data = parent.get('data')
# if ids = data.get("#{name}_ids")
# ids.pushObject(data.id) unless data.id in ids
# parent.send('didChangeData')
_updateAssociations: (type, name, data) ->
Em.get(type, 'associationsByName').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.get("#{name}_ids")
ids.pushObject(data.id) unless data.id in ids
parent.send('didChangeData');

View File

@ -1,110 +1,118 @@
describe 'events', ->
# describe 'an event adding a repository', ->
# beforeEach ->
# app ''
# waitFor jobsRendered
afterEach ->
window.history.pushState({}, null, '/spec.html')
# it 'adds a repository to the list', ->
# app ''
# waitFor reposRendered
#
# Em.run ->
# Travis.app.receive 'build:created',
# repository:
# id: 10
# slug: 'travis-ci/travis-support'
# last_build_id: 10
# last_build_number: 10
# last_build_started_at: '2012-07-02T00:02:00Z'
# build:
# id: 10
# repository_id: 10
describe 'an event adding a repository', ->
beforeEach ->
app 'travis-ci/travis-core'
waitFor jobsRendered
# listsRepo
# row: 4
# item: { slug: 'travis-ci/travis-support', build: { number: 4, url: '#!/travis-ci/travis-support/builds/10', duration: '1 min', finishedAt: '-' } }
it 'adds a repository to the list', ->
waitFor reposRendered
# describe 'an event adding a build', ->
# beforeEach ->
# app '#!/travis-ci/travis-core/builds'
# waitFor buildsRendered
runs ->
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'
build:
id: 10
repository_id: 10
# it 'adds a build to the builds list', ->
# Em.run ->
# Travis.app.receive 'build:finished',
# 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'
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' } }
# 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' }
describe 'an event adding a build', ->
beforeEach ->
app 'travis-ci/travis-core/builds'
waitFor buildsRendered
# describe 'an event adding a job', ->
# beforeEach ->
# app ''
# waitFor jobsRendered
# waitFor queuesRendered
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'
# it 'adds a job to the jobs matrix', ->
# Em.run ->
# Travis.app.receive 'job:created',
# 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' }
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' }
# 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' }
describe 'an event adding a job', ->
beforeEach ->
app 'travis-ci/travis-core'
waitFor jobsRendered
runs ->
waitFor queuesRendered
# it 'adds a job to the jobs queue', ->
# Em.run ->
# Travis.app.receive 'job:created',
# job:
# id: 10
# repository_id: 1
# number: '1.4'
# queue: 'common'
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' }
# listsQueuedJob
# name: 'common'
# row: 3
# item: { number: '1.4', repo: 'travis-ci/travis-core' }
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' }
# describe 'an event adding a worker', ->
# beforeEach ->
# app ''
# waitFor workersRendered
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'
# it 'adds a worker to the workers list', ->
# Em.run ->
# Travis.app.receive 'worker:added',
# worker:
# id: 10
listsQueuedJob
name: 'common'
row: 3
item: { number: '1.4', repo: 'travis-ci/travis-core' }
# listsWorker
# group: 'workers.travis-ci.org'
# row: 3
# item: { 'ruby-3' }
describe 'an event adding a worker', ->
beforeEach ->
app ''
waitFor workersRendered
it 'adds a worker to the workers list', ->
Em.run ->
Travis.app.receive 'worker',
worker:
host: 'worker.travis-ci.org'
name: 'ruby-3'
state: 'ready'
id: 10
listsWorker
group: 'worker.travis-ci.org'
row: 3
item: { name: 'ruby-3', state: 'ready' }

View File

@ -99,7 +99,6 @@
listsItems('queuedJob', jobs)
@listsQueuedJob = (data) ->
console.log data
job = data.item
text = $($("#queue_#{data.name} li")[data.row - 1]).text()
expect(text).toContain job.repo
@ -119,3 +118,10 @@
@listsQueues = (queues) ->
listsItems('queue', queues)
@listsWorker = (data) ->
group = $("#workers li:contains('#{data.group}')")
element = $($('ul li', group)[data.row - 1])
worker = data.item
expect(element.text()).toContain worker.name
expect(element.text()).toContain worker.state

File diff suppressed because one or more lines are too long

View File

@ -304,7 +304,180 @@
}).call(this);
(function() {
describe('events', function() {});
describe('events', function() {
afterEach(function() {
return window.history.pushState({}, null, '/spec.html');
});
describe('an event adding a repository', function() {
beforeEach(function() {
app('travis-ci/travis-core');
return waitFor(jobsRendered);
});
return it('adds a repository to the list', function() {
waitFor(reposRendered);
return runs(function() {
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'
},
build: {
id: 10,
repository_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'
}
}
});
});
});
});
describe('an event adding a build', function() {
beforeEach(function() {
app('travis-ci/travis-core/builds');
return waitFor(buildsRendered);
});
return it('adds a build to the builds list', function() {
Em.run(function() {
return 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'
}
});
});
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'
}
});
});
});
describe('an event adding a job', function() {
beforeEach(function() {
app('travis-ci/travis-core');
waitFor(jobsRendered);
return runs(function() {
return waitFor(queuesRendered);
});
});
it('adds a job to the jobs matrix', function() {
Em.run(function() {
return 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'
}
}
});
});
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'
}
});
});
return it('adds a job to the jobs queue', function() {
Em.run(function() {
return Travis.app.receive('job', {
job: {
id: 10,
repository_id: 1,
number: '1.4',
queue: 'common'
}
});
});
return listsQueuedJob({
name: 'common',
row: 3,
item: {
number: '1.4',
repo: 'travis-ci/travis-core'
}
});
});
});
return describe('an event adding a worker', function() {
beforeEach(function() {
app('');
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: {
name: 'ruby-3',
state: 'ready'
}
});
});
});
});
}).call(this);
(function() {
@ -730,7 +903,6 @@
this.listsQueuedJob = function(data) {
var job, text;
console.log(data);
job = data.item;
text = $($("#queue_" + data.name + " li")[data.row - 1]).text();
expect(text).toContain(job.repo);
@ -760,6 +932,15 @@
return listsItems('queue', queues);
};
this.listsWorker = function(data) {
var element, group, worker;
group = $("#workers li:contains('" + data.group + "')");
element = $($('ul li', group)[data.row - 1]);
worker = data.item;
expect(element.text()).toContain(worker.name);
return expect(element.text()).toContain(worker.state);
};
}).call(this);
(function() {

File diff suppressed because it is too large Load Diff