Permalink
Browse files

switched 'cothread' to 'thread' on clientside javascript (backbone) w…

…herever it does not correspond directly to the rails model.
  • Loading branch information...
1 parent 69aa1c6 commit 0a205298230ac6913099ee0fe82a1eb72785660f @shioyama shioyama committed Apr 17, 2012
@@ -4,9 +4,9 @@ window.CojiroApp =
Views: {}
Routers: {}
init: (data) ->
- @cothread = new CojiroApp.Models.Cothread(data.cothread)
+ @thread = new CojiroApp.Models.Thread(data.thread)
- new CojiroApp.Routers.Cothreads(model: @cothread)
+ new CojiroApp.Routers.Threads(model: @thread)
if (!Backbone.history.started)
Backbone.history.start()
Backbone.history.started = true
@@ -1,3 +0,0 @@
-class CojiroApp.Collections.Cothreads extends Backbone.Collection
- model: CojiroApp.Models.Cothread
- url: '/cothreads'
@@ -0,0 +1,3 @@
+class CojiroApp.Collections.Threads extends Backbone.Collection
+ model: CojiroApp.Models.Thread
+ url: '/threads'
@@ -1,4 +1,4 @@
-class CojiroApp.Models.Cothread extends Backbone.Model
+class CojiroApp.Models.Thread extends Backbone.Model
url: ->
if @isNew()
'/threads'
@@ -9,7 +9,7 @@ class CojiroApp.Models.Cothread extends Backbone.Model
title: ''
summary: ''
- toJSON: -> cothread: @attributes
+ toJSON: -> thread: @attributes
getId: -> @id
getTitle: -> @get('title')
getSummary: -> @get('summary')
@@ -1,7 +0,0 @@
-class CojiroApp.Routers.Cothreads extends Backbone.Router
- routes:
- "" : "show"
-
- show: ->
- view = new CojiroApp.Views.CothreadsShow( model: CojiroApp.cothread )
- $('.content').html(view.render().el)
@@ -0,0 +1,7 @@
+class CojiroApp.Routers.Threads extends Backbone.Router
+ routes:
+ "" : "show"
+
+ show: ->
+ view = new CojiroApp.Views.ThreadsShow( model: CojiroApp.thread )
+ $('.content').html(view.render().el)
@@ -1,10 +0,0 @@
-class CojiroApp.Views.CothreadsShow extends Backbone.View
- id: 'thread'
-
- initialize: ->
- _.bindAll @
- @render()
-
- render: ->
- @$el.html(JST['cothreads/show'](model: @model))
- @
@@ -0,0 +1,10 @@
+class CojiroApp.Views.ThreadsShow extends Backbone.View
+ id: 'thread'
+
+ initialize: ->
+ _.bindAll @
+ @render()
+
+ render: ->
+ @$el.html(JST['threads/show'](model: @model))
+ @
@@ -6,17 +6,17 @@ describe "CojiroApp", ->
describe "init()", ->
it "accepts JSON and instantiates collections from it", ->
- cothreadsJSON =
- "cothread":
+ threadsJSON =
+ "thread":
"title": "Co-working spaces in Tokyo","summary": "I'm collecting blog posts on co-working spaces in Tokyo."
- CojiroApp.init(cothreadsJSON)
+ CojiroApp.init(threadsJSON)
- expect(CojiroApp.cothread).not.toEqual(undefined)
- expect(CojiroApp.cothread.getTitle()).toEqual("Co-working spaces in Tokyo")
- expect(CojiroApp.cothread.getSummary()).toEqual("I'm collecting blog posts on co-working spaces in Tokyo.")
+ expect(CojiroApp.thread).not.toEqual(undefined)
+ expect(CojiroApp.thread.getTitle()).toEqual("Co-working spaces in Tokyo")
+ expect(CojiroApp.thread.getSummary()).toEqual("I'm collecting blog posts on co-working spaces in Tokyo.")
- it "instantiates a Cothreads router", ->
- CojiroApp.Routers.Cothreads = sinon.spy()
+ it "instantiates a Threads router", ->
+ CojiroApp.Routers.Threads = sinon.spy()
CojiroApp.init({})
- expect(CojiroApp.Routers.Cothreads).toHaveBeenCalled()
+ expect(CojiroApp.Routers.Threads).toHaveBeenCalled()
@@ -1,8 +0,0 @@
-describe "CojiroApp.Collections.Cothreads", ->
- it "contains instances of CojiroApp.Models.Cothread", ->
- collection = new CojiroApp.Collections.Cothreads()
- expect(collection.model).toEqual(CojiroApp.Models.Cothread)
-
- it "is persisted at /threads", ->
- collection = new CojiroApp.Collections.Cothreads()
- expect(collection.url).toEqual("/cothreads")
@@ -0,0 +1,8 @@
+describe "CojiroApp.Collections.Threads", ->
+ it "contains instances of CojiroApp.Models.Thread", ->
+ collection = new CojiroApp.Collections.Threads()
+ expect(collection.model).toEqual(CojiroApp.Models.Thread)
+
+ it "is persisted at /threads", ->
+ collection = new CojiroApp.Collections.Threads()
+ expect(collection.url).toEqual("/threads")
@@ -1,70 +1,70 @@
# ref: http://blog.bandzarewicz.com/blog/2012/03/08/backbone-dot-js-tdd-with-jasmine-part-one-the-model/
#
-describe 'CojiroApp.Models.Cothread', ->
- it 'is defined', -> expect(CojiroApp.Models.Cothread).toBeDefined()
+describe 'CojiroApp.Models.Thread', ->
+ it 'is defined', -> expect(CojiroApp.Models.Thread).toBeDefined()
it 'can be instantiated', ->
- cothread = new CojiroApp.Models.Cothread
- expect(cothread).not.toBeNull()
+ thread = new CojiroApp.Models.Thread
+ expect(thread).not.toBeNull()
describe 'new instance default values', ->
- beforeEach -> @cothread = new CojiroApp.Models.Cothread()
+ beforeEach -> @thread = new CojiroApp.Models.Thread()
it 'has default values for the .title attribute', ->
- expect(@cothread.get('title')).toEqual('')
+ expect(@thread.get('title')).toEqual('')
it 'has default values for the .summary attribute', ->
- expect(@cothread.get('summary')).toEqual('')
+ expect(@thread.get('summary')).toEqual('')
describe 'getters', ->
- beforeEach -> @cothread = new CojiroApp.Models.Cothread()
+ beforeEach -> @thread = new CojiroApp.Models.Thread()
describe '#getId', ->
- it 'is defined', -> expect(@cothread.getId).toBeDefined()
+ it 'is defined', -> expect(@thread.getId).toBeDefined()
it 'returns undefined if id is not defined', ->
- expect(@cothread.getId()).toBeUndefined()
+ expect(@thread.getId()).toBeUndefined()
it "otherwise returns model's id", ->
- @cothread.id = 66;
- expect(@cothread.getId()).toEqual(66)
+ @thread.id = 66;
+ expect(@thread.getId()).toEqual(66)
describe '#getTitle', ->
- it 'is defined', -> expect(@cothread.getTitle).toBeDefined()
+ it 'is defined', -> expect(@thread.getTitle).toBeDefined()
it 'returns value for the title attribute', ->
- stub = sinon.stub(@cothread, 'get').returns('Thread title')
+ stub = sinon.stub(@thread, 'get').returns('Thread title')
- expect(@cothread.getTitle()).toEqual('Thread title')
+ expect(@thread.getTitle()).toEqual('Thread title')
expect(stub).toHaveBeenCalledWith('title')
describe '#getSummary', ->
- it 'is defined', -> expect(@cothread.getSummary).toBeDefined()
+ it 'is defined', -> expect(@thread.getSummary).toBeDefined()
it 'returns value for the summary attribute', ->
- stub = sinon.stub(@cothread, 'get').returns('Thread summary')
+ stub = sinon.stub(@thread, 'get').returns('Thread summary')
- expect(@cothread.getSummary()).toEqual('Thread summary')
+ expect(@thread.getSummary()).toEqual('Thread summary')
expect(stub).toHaveBeenCalledWith('summary')
describe '#save', ->
beforeEach -> @server = sinon.fakeServer.create()
afterEach -> @server.restore()
it 'sends valid data to the server', ->
- @cothread.save({ title: 'Co-working spaces in Tokyo' })
+ @thread.save({ title: 'Co-working spaces in Tokyo' })
request = @server.requests[0]
params = JSON.parse(request.requestBody)
- expect(params.cothread).toBeDefined()
- expect(params.cothread.title).toEqual('Co-working spaces in Tokyo')
+ expect(params.thread).toBeDefined()
+ expect(params.thread.title).toEqual('Co-working spaces in Tokyo')
describe 'request', ->
describe 'on create', ->
beforeEach ->
- @cothread.id = null
- @cothread.save()
+ @thread.id = null
+ @thread.save()
@request = @server.requests[0]
it 'is a POST', -> expect(@request).toBePOST()
@@ -73,8 +73,8 @@ describe 'CojiroApp.Models.Cothread', ->
describe 'on update', ->
beforeEach ->
- @cothread.id = 66
- @cothread.save()
+ @thread.id = 66
+ @thread.save()
@request = @server.requests[0]
it 'is a PUT', -> expect(@request).toBePUT()
@@ -1,11 +1,11 @@
-describe "CojiroApp.Views.CothreadsShow", ->
- it "renders the cothread", ->
- cothread = new CojiroApp.Models.Cothread()
- cothread.set
+describe "CojiroApp.Views.ThreadsShow", ->
+ it "renders the thread", ->
+ thread = new CojiroApp.Models.Thread()
+ thread.set
title: "Geisha bloggers",
summary: "Looking for info on geisha bloggers."
- view = new CojiroApp.Views.CothreadsShow(model: cothread)
+ view = new CojiroApp.Views.ThreadsShow(model: thread)
$el = $(view.render().el)
expect($el).toBe("#thread")

0 comments on commit 0a20529

Please sign in to comment.