Enable polling for tests

This commit is contained in:
Piotr Sarnacki 2015-05-12 10:02:47 +02:00
parent 234572f8a6
commit 93373e89ee
4 changed files with 8 additions and 6 deletions

View File

@ -1,5 +1,4 @@
`import Ember from 'ember'`
`import config from 'travis/config/environment'`
mixin = Ember.Mixin.create
polling: Ember.inject.service()
@ -7,13 +6,11 @@ mixin = Ember.Mixin.create
didInsertElement: ->
@_super.apply(this, arguments)
return unless config.ajaxPolling
@startPolling()
willDestroyElement: ->
@_super.apply(this, arguments)
return unless config.ajaxPolling
@stopPolling()
pollModelDidChange: (sender, key, value) ->

View File

@ -3,6 +3,7 @@
service = Ember.Service.extend
pollingInterval: 30000
ajaxPolling: true
init: ->
@_super.apply(this, arguments)
@ -10,9 +11,8 @@ service = Ember.Service.extend
@set('watchedModels', [])
@set('sources', [])
return unless config.ajaxPolling
interval = setInterval =>
return unless config.ajaxPolling
@poll()
, @get('pollingInterval')

View File

@ -38,7 +38,7 @@ define('travis/components/polling-test', [], ->
# I want to test this mixin in context of component, so I'm using
# modelForComponent
moduleForComponent 'polling-test', 'PollingTestComponent', {
moduleForComponent 'polling-test', 'PollingMixin', {
# specify the other units that are required for this test
needs: []

View File

@ -1,10 +1,15 @@
`import Ember from 'ember'`
`import Polling from 'travis/services/polling'`
`import config from 'travis/config/environment'`
service = null
module 'PollingService',
setup: ->
config.ajaxPolling = true
teardown: ->
config.ajaxPolling = false
unless service.get('isDestroyed')
Ember.run ->
service.destroy()