Skip to content
Browse files

Merge pull request #9 from markchadwick/master

[Breaking] Upgrade to jQuery(ify) 1.9.1
  • Loading branch information...
2 parents c957633 + 292090a commit f5d4f8829dfa6e41dc653947f3c3b5069edccd26 @markchadwick markchadwick committed
View
2 controllers/controller.coffee
@@ -1,5 +1,5 @@
Backbone = require 'backbone'
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
events = require '../lib/events'
View
2 controllers/form_controller.coffee
@@ -1,5 +1,5 @@
_ = require 'underscore'
-Deferred = require('jqueryify2').Deferred
+Deferred = require('jqueryify').Deferred
Controller = require './controller'
View
2 controllers/login_controller.coffee
@@ -1,4 +1,4 @@
-Deferred = require('jqueryify2').Deferred
+Deferred = require('jqueryify').Deferred
Backbone = require 'backbone'
Controller = require './controller'
View
2 lib/combiner.coffee
@@ -1,4 +1,4 @@
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
module.exports =
combine: (deferreds) ->
View
2 lib/forms.coffee
@@ -1,7 +1,7 @@
require './date'
_ = require 'underscore'
-jQuery = require 'jqueryify2'
+jQuery = require 'jqueryify'
Deferred = jQuery.Deferred
JSON = require 'json2ify'
View
27 models/collection.coffee
@@ -11,18 +11,21 @@ class Collection extends Backbone.Collection
lazy: false
- syncTo: (otherCol) ->
- @on('sync add remove', ((model, resp, opts) ->
- unless opts.from_handler
- # the timeout is used to account for eventual consistency. This can be
- # removed if we are using an ACID database.
- setTimeout((-> otherCol.fetch(update: true, from_handler: true)), 300)
- ), this)
-
- otherCol.on('sync add remove', ((model, resp, opts) =>
- unless opts.from_handler
- setTimeout((=> @fetch(update: true, from_handler: true)), 300)
- ), this)
+ # the timeout is used to account for eventual consistency. This can be removed
+ # if we are using an ACID database.
+ syncTo: (otherCol, timeout=300) ->
+ events = 'sync add remove'
+
+ syncThis = (model, resp, opts) ->
+ fetch = -> otherCol.fetch(update: true, from_handler: true)
+ unless opts.from_handler then setTimeout(fetch, timeout)
+
+ syncOther = (model, resp, opts) =>
+ fetch = => @fetch(update: true, from_handler: true)
+ unless opts.from_handler then setTimeout(fetch, timeout)
+
+ @on(events, syncThis, this)
+ otherCol.on(events, syncOther, this)
module.exports = events.track Collection
View
2 models/loader.coffee
@@ -1,4 +1,4 @@
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
combine = require('../lib/combiner').combine
root = ''
View
2 models/user.coffee
@@ -1,4 +1,4 @@
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
JSON = require 'json2ify'
View
4 package.json
@@ -1,9 +1,9 @@
{
"name": "quips",
- "version": "0.0.46",
+ "version": "0.1.0",
"dependencies": {
"coffee-script": "1.3.3",
- "jqueryify2": "0.0.1",
+ "jqueryify": "1.9.1",
"json2ify": "0.0.1",
"underscore": "1.4.3",
"backbone": "0.9.10",
View
2 test/controllers/controller_spec.coffee
@@ -1,6 +1,6 @@
test = require '../setup'
expect = require('chai').expect
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
Controller = require 'controllers/controller'
View = require 'views/view'
View
45 test/lib/combiner_spec.coffee
@@ -1,7 +1,8 @@
test = require '../setup'
-expect = require('chai').expect
+
+expect = require('chai').expect
combine = require('lib/combiner').combine
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
describe 'Deferred combiner', ->
beforeEach ->
@@ -25,7 +26,7 @@ describe 'Deferred combiner', ->
d1.resolve()
d2.resolve()
- it 'should propage the first error', (done) ->
+ it 'should propagate the first error', (done) ->
willSucceed = $.Deferred()
willFail = $.Deferred()
@@ -36,17 +37,35 @@ describe 'Deferred combiner', ->
willFail.reject 'cuz'
- expect(willSucceed.isRejected()).to.be.false
- expect(willSucceed.isResolved()).to.be.false
+ expect(willSucceed.state()).to.equal 'pending'
+ expect(willFail.state()).to.equal 'rejected'
+ expect(combined.state()).to.equal 'rejected'
- expect(willFail.isRejected()).to.be.true
- expect(willFail.isResolved()).to.be.false
+ willSucceed.resolve 'gooies'
- expect(combined.isRejected()).to.be.true
- expect(combined.isResolved()).to.be.false
+ expect(willSucceed.state()).to.equal 'resolved'
+ expect(willFail.state()).to.equal 'rejected'
+ expect(combined.state()).to.equal 'rejected'
- # We should be able to get results after a failure without error
- willSucceed.resolve 'gooies'
+describe 'jQuery deferreds', ->
+ beforeEach ->
+ @state = test.create()
- expect(willSucceed.isResolved()).to.be.true
- expect(combined.isRejected()).to.be.true
+ afterEach ->
+ @state.destroy()
+
+ it 'should notify of failures', (done) ->
+ deferred = $.Deferred()
+ promise = deferred.promise()
+
+ promise.fail (reason) ->
+ expect(promise.state()).to.equal 'rejected'
+ expect(reason).to.equal "Ain't nobody got time for that"
+ done()
+
+ deferred.reject "Ain't nobody got time for that"
+
+ it 'should expose state', ->
+ willFail = $.Deferred()
+ willFail.reject 'cuz'
+ expect(willFail.state()).to.equal 'rejected'
View
19 test/lib/forms_spec.coffee
@@ -2,7 +2,7 @@ require 'lib/date'
test = require '../setup'
expect = require('chai').expect
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
JSON = require 'json2ify'
Model = require 'models/model'
@@ -67,7 +67,18 @@ describe 'Form View', ->
it 'should populate a select field', ->
@lilBilly.set(gender: 'male')
form = new TestForm(@lilBilly).render()
- expect(form.$el.find('select[name=gender] option[selected]')).to.have.val 'male'
+ expect(form.$el.find('select[name=gender]')).to.have.val 'male'
+
+ it 'should submit the value of a select view', (done) ->
+ test.when 'POST', '/lils/billy', (req) ->
+ postData = $.parseJSON(req.requestText)
+ expect(postData.gender).to.equal 'male'
+ done()
+
+ @lilBilly.set(gender: 'male')
+ form = new TestForm(@lilBilly).render()
+ form.$el.find('form').submit()
+
describe 'when getting an update', ->
@@ -125,7 +136,7 @@ describe 'Form View', ->
it 'should notify instance deferred on success', (done) ->
test.when 'POST', '/lils/billy', (req) ->
- status: 200
+ status: 204
@form.deferred.progress ->
done()
@@ -134,7 +145,7 @@ describe 'Form View', ->
it 'should fire a saved event on success', (done) ->
test.when 'POST', '/lils/billy', (req) ->
- status: 200
+ status: 204
@form.on('saved', (->
done()), @form)
View
14 test/models/collection_spec.coffee
@@ -35,7 +35,7 @@ describe 'Collection', ->
test.when 'GET', '/mock1/', =>
@mock1FetchCount++
- body: JSON.stringify([{id: 2},{id: 3}])
+ body: JSON.stringify([{id: 2}, {id: 3}])
test.when 'GET', '/mock2/', =>
@mock2FetchCount++
@@ -48,7 +48,7 @@ describe 'Collection', ->
@clock.restore()
it 'should fetch the other collection when a model is added', ->
- @mock1.syncTo(@mock2)
+ @mock1.syncTo(@mock2, 0)
@mock2.add(new MockModel2())
@mock1.add(new MockModel1())
@mock1.add(new MockModel1())
@@ -62,7 +62,7 @@ describe 'Collection', ->
@mock1.add(new MockModel1(id: 2))
@mock1.add(new MockModel1(id: 3))
- @mock1.syncTo(@mock2)
+ @mock1.syncTo(@mock2, 0)
@mock2.remove([1])
@mock1.remove([2, 3])
@clock.tick(300)
@@ -72,7 +72,7 @@ describe 'Collection', ->
it 'should fetch the other collection when a model is saved', ->
test.when 'PUT', '/mock1/2', ->
- status: 200
+ status: 204
model = new MockModel1(id: 2)
@@ -80,7 +80,7 @@ describe 'Collection', ->
@mock1.add(model)
@mock1.add(new MockModel1(id: 3))
- @mock1.syncTo(@mock2)
+ @mock1.syncTo(@mock2, 0)
model.save()
@clock.tick(300)
@@ -94,7 +94,7 @@ describe 'Collection', ->
@mock1.add(model)
@mock1.add(new MockModel1(id: 3))
- @mock1.syncTo(@mock2)
+ @mock1.syncTo(@mock2, 0)
model.set(name: 'test')
@clock.tick(300)
@@ -114,7 +114,7 @@ describe 'Collection', ->
model = new MockModel1(id: 2)
@mock1.add(model)
- @mock1.syncTo(@mock2)
+ @mock1.syncTo(@mock2, 0)
for i in [1..100]
@modelSaved = false
View
10 test/models/loader_spec.coffee
@@ -1,6 +1,6 @@
test = require '../setup'
expect = require('chai').expect
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
Collection = require 'models/collection'
Model = require 'models/model'
@@ -20,10 +20,10 @@ describe 'Model Loader', ->
it 'should handle collections with a url func', (done) ->
test.when 'GET', 'api-root/my/mock/url', (req) ->
- status: 200
+ status: 204
test.when 'GET', 'api-root/my/mock/func/url', (req) ->
- status: 200
+ status: 204
class MockCollection extends Collection
model: MockModel
@@ -48,11 +48,11 @@ describe 'Model Loader', ->
test.when 'GET', 'api-root/my/mock/func/url1', (req) ->
collectionOneFetches++
- status: 200
+ status: 204
test.when 'GET', 'api-root/my/mock/func/url2', (req) ->
collectionTwoFetches++
- status: 200
+ status: 204
class FuncOneCollection extends Collection
model: MockModel
View
2 test/setup.coffee
@@ -7,7 +7,7 @@ global.document or= jsdom()
global.window or= global.document.createWindow()
global.window.confirm = -> true
-global.jQuery = require 'jqueryify2'
+global.jQuery = require 'jqueryify'
global.jQuery.contains = -> true
Backbone = require 'backbone'
View
2 test/views/list_view_spec.coffee
@@ -1,6 +1,6 @@
test = require '../setup'
expect = require('chai').expect
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
_ = require 'underscore'
lists = require 'views/list_view'
View
2 test/views/view_spec.coffee
@@ -2,7 +2,7 @@ test = require '../setup'
expect = require('chai').expect
Backbone = require 'backbone'
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
_ = require 'underscore'
View = require 'views/view'
View
2 views/detail_view.coffee
@@ -1,6 +1,6 @@
View = require './view'
Sticky = require '../lib/sticky'
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
class DetailView extends View
View
2 views/navigation_view.coffee
@@ -1,5 +1,5 @@
View = require './view'
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
class NavigationView extends View
View
2 views/view.coffee
@@ -1,4 +1,4 @@
-$ = require 'jqueryify2'
+$ = require 'jqueryify'
_ = require 'underscore'
Backbone = require 'backbone'

0 comments on commit f5d4f88

Please sign in to comment.
Something went wrong with that request. Please try again.