Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: brownman/book-splitter-backbone-bootstrap
base: 166a2ebdff
...
head fork: brownman/book-splitter-backbone-bootstrap
compare: a99f86d0d2
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 34 files changed
  • 0 commit comments
  • 1 contributor
Showing with 875 additions and 297 deletions.
  1. +15 −8 app/assets/javascripts/backbone/models/comment.js.coffee
  2. +12 −6 app/assets/javascripts/backbone/models/comment.js.coffee~
  3. +27 −1 app/assets/javascripts/backbone/models/post.js.coffee
  4. +28 −2 app/assets/javascripts/backbone/models/post.js.coffee~
  5. +1 −1  app/assets/javascripts/backbone/rails_backbone_relational.js.coffee
  6. +4 −0 app/assets/javascripts/backbone/routers/posts_router.js.coffee
  7. +2 −0  app/assets/javascripts/backbone/templates/comments/comment.jst.ejs
  8. +4 −5 app/assets/javascripts/backbone/templates/comments/comment.jst.ejs~
  9. +7 −0 app/assets/javascripts/backbone/templates/comments/index.jst.ejs
  10. +9 −1 app/assets/javascripts/backbone/templates/comments/index.jst.ejs~
  11. +9 −3 app/assets/javascripts/backbone/templates/posts/post.jst.ejs
  12. +9 −4 app/assets/javascripts/backbone/templates/posts/post.jst.ejs~
  13. +22 −1 app/assets/javascripts/backbone/views/comments/comment_view.js.coffee
  14. +22 −1 app/assets/javascripts/backbone/views/comments/comment_view.js.coffee~
  15. +58 −7 app/assets/javascripts/backbone/views/comments/index_view.js.coffee
  16. +59 −8 app/assets/javascripts/backbone/views/comments/index_view.js.coffee~
  17. +0 −1  app/assets/javascripts/backbone/views/comments/new_view.js.coffee
  18. +1 −1  app/assets/javascripts/backbone/views/comments/new_view.js.coffee~
  19. +4 −7 app/assets/javascripts/backbone/views/posts/index_view.js.coffee
  20. +3 −6 app/assets/javascripts/backbone/views/posts/index_view.js.coffee~
  21. +1 −0  app/assets/javascripts/backbone/views/posts/new_view.js.coffee
  22. +49 −2 app/assets/javascripts/backbone/views/posts/post_view.js.coffee
  23. +49 −8 app/assets/javascripts/backbone/views/posts/post_view.js.coffee~
  24. +2 −1  app/views/layouts/application.html.erb
  25. +2 −1  app/views/layouts/application.html.erb~
  26. 0  spec/javascripts/general/app_spec.js
  27. +71 −0 spec/javascripts/general/collection_spec.js
  28. +127 −0 spec/javascripts/general/events_spec.js
  29. +68 −0 spec/javascripts/general/model_spec.js
  30. +50 −0 spec/javascripts/general/router_spec.js
  31. +77 −0 spec/javascripts/general/views_spec.js
  32. +83 −0 spec/javascripts/models/post_spec.js
  33. +0 −111 spec/javascripts/models/task_spec.js
  34. +0 −111 spec/javascripts/models/task_spec.js~
View
23 app/assets/javascripts/backbone/models/comment.js.coffee
@@ -25,10 +25,9 @@ class RailsBackboneRelational.Models.Comment extends Backbone.RelationalModel
obj.trigger('event')
@equal1(obj.counter, 5, 'counter should be incremented five times.')
#console.log(this)
- #alert('brothers:')
#save: ->
- #alert('save')
+
equal1: (a,b,c) ->
#alert(a + '|' + '|' +c)
@@ -68,18 +67,26 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
initialize: () ->
+ #this.bind('add', @addModelCallback);
#console.log(this)
- this.bind("add", @add_ofer)
+ this.bind("add remove", @add1)
+
+ #this.bind("change", @change_ofer)
+
+ #this.bind("add", @render)
#@num = this.models.length
#console.log(options)
#for model in this.models.array
-
+
+
- add_ofer: () =>
- console.log(this)
- length_i = this.models.length
+
+ add1: () =>
+ console.log(this)
+ length_i = this.models.length
+ if length_i > 0
length_j = this.models[0].array.length
#find min array
@@ -98,9 +105,9 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
if ( num1 == length_i)
for i in [0...length_i]
this.models[i].array[j..j] = []
+ this.trigger('add2')
- #alert('add_ofer triggered')
#localStorage: new Backbone.LocalStorage("CommentsCollection")
View
18 app/assets/javascripts/backbone/models/comment.js.coffee~
@@ -25,10 +25,9 @@ class RailsBackboneRelational.Models.Comment extends Backbone.RelationalModel
obj.trigger('event')
@equal1(obj.counter, 5, 'counter should be incremented five times.')
#console.log(this)
- #alert('brothers:')
#save: ->
- #alert('save')
+
equal1: (a,b,c) ->
#alert(a + '|' + '|' +c)
@@ -68,16 +67,23 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
initialize: () ->
+ #this.bind('add', @addModelCallback);
#console.log(this)
- this.bind("add", @add_ofer)
+ this.bind("add remove", @add1)
+
+ #this.bind("change", @change_ofer)
+
+ #this.bind("add", @render)
#@num = this.models.length
#console.log(options)
#for model in this.models.array
-
+
+
- add_ofer: () =>
+
+ add1: () =>
console.log(this)
length_i = this.models.length
length_j = this.models[0].array.length
@@ -98,9 +104,9 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
if ( num1 == length_i)
for i in [0...length_i]
this.models[i].array[j..j] = []
+ this.trigger('add2')
- #alert('add_ofer triggered')
#localStorage: new Backbone.LocalStorage("CommentsCollection")
View
28 app/assets/javascripts/backbone/models/post.js.coffee
@@ -1,8 +1,16 @@
+
+String::dasherize = ->
+ this.replace /_/g, "-"
+
+String::senitize = ->
+ this.replace /_/g, "-"
+#alert "one_two".dasherize()
+
class RailsBackboneRelational.Models.Post extends Backbone.RelationalModel
paramRoot: 'post'
defaults:
- title: null
+ title: 'title?'
relations: [
type: Backbone.HasMany
@@ -14,6 +22,22 @@ class RailsBackboneRelational.Models.Post extends Backbone.RelationalModel
key: 'post_id',
includeInJSON: 'id'
]
+
+ validate: (attrs) ->
+ if (attrs.hasOwnProperty('title') && _.isNull(attrs.title))
+ return 'attr.direction must be a non null value.'
+
+
+
+ sanitize1: (str) ->
+ str.senitize()
+
+
+ initialize: () ->
+ console.log('init post')
+
+
+
class RailsBackboneRelational.Collections.PostsCollection extends Backbone.Collection
model: RailsBackboneRelational.Models.Post
@@ -24,3 +48,5 @@ class RailsBackboneRelational.Collections.PostsCollection extends Backbone.Colle
#alert('new collection posts')
#localStorage: new Backbone.LocalStorage("PostsCollection")
+ comparator: (post) ->
+ return post.get('id');
View
30 app/assets/javascripts/backbone/models/post.js.coffee~
@@ -1,8 +1,16 @@
+
+String::dasherize = ->
+ this.replace /_/g, "-"
+
+String::senitize = ->
+ this.replace /_/g, "-"
+#alert "one_two".dasherize()
+
class RailsBackboneRelational.Models.Post extends Backbone.RelationalModel
paramRoot: 'post'
defaults:
- title: null
+ title: 'title?'
relations: [
type: Backbone.HasMany
@@ -14,13 +22,31 @@ class RailsBackboneRelational.Models.Post extends Backbone.RelationalModel
key: 'post_id',
includeInJSON: 'id'
]
+
+ validate: (attrs) ->
+ if (attrs.hasOwnProperty('title') && _.isNull(attrs.title))
+ return 'attr.direction must be a non null value.'
+
+
+
+ sanitize1: (str) ->
+ str.senitize()
+
+
+ initialize: () ->
+ console.log('init post')
+
+
+
class RailsBackboneRelational.Collections.PostsCollection extends Backbone.Collection
model: RailsBackboneRelational.Models.Post
url: '/posts'
initialize: () ->
- console.log('init post')
+ #console.log('init post')
#alert('new collection posts')
#localStorage: new Backbone.LocalStorage("PostsCollection")
+ comparator: (todo) ->
+ return todo.get('id');
View
2  app/assets/javascripts/backbone/rails_backbone_relational.js.coffee
@@ -8,4 +8,4 @@ window.RailsBackboneRelational =
Models: {}
Collections: {}
Routers: {}
- Views: {}
+ Views: {}
View
4 app/assets/javascripts/backbone/routers/posts_router.js.coffee
@@ -2,6 +2,8 @@ class RailsBackboneRelational.Routers.PostsRouter extends Backbone.Router
initialize: (options) ->
@posts = new RailsBackboneRelational.Collections.PostsCollection()
@posts.reset options.posts
+ console.log(this)
+ window.post_router = this
routes:
"/new" : "newPost"
@@ -29,3 +31,5 @@ class RailsBackboneRelational.Routers.PostsRouter extends Backbone.Router
@view = new RailsBackboneRelational.Views.Posts.EditView(model: post)
$("#posts").html(@view.render().el)
+
+#Backbone.history.start()
View
2  app/assets/javascripts/backbone/templates/comments/comment.jst.ejs
@@ -14,6 +14,8 @@
<input label='time: ' tooltip='delay in seconds' class='seconds span12' height='1em' type='text' value='<%= obj3 %>'></input>
+<input label='span: ' tooltip='delay in seconds' class='seconds span12' height='1em' type='text' value='<%= obj4 %>'></input>
+
View
9 app/assets/javascripts/backbone/templates/comments/comment.jst.ejs~
@@ -10,20 +10,19 @@
-<input height='1em' class='span12' name="content" value= '<%= obj.content %>' />
-<textarea rows="4" height='1em' class='span12' name="content1" >
-<%= obj.content %>
-</textarea>
+<input label='time: ' tooltip='delay in seconds' class='seconds span12' height='1em' type='text' value='<%= obj3 %>'></input>
-<input label='time: ' tooltip='delay in seconds' class='seconds span12' height='1em' type='text' value='<%= obj3 %>'></input>
+<textarea rows="4" height='1em' class='span12' name="content1" >
+<%= obj.content %>
+</textarea>
View
7 app/assets/javascripts/backbone/templates/comments/index.jst.ejs
@@ -1,7 +1,14 @@
+
<tbody class="span12">
+
+
<tr class='comments-list span12'>
</tr>
</tbody>
+
+
+
+
View
10 app/assets/javascripts/backbone/templates/comments/index.jst.ejs~
@@ -1,7 +1,15 @@
+
+<input class='span12' value='zzz'></input>
<tbody class="span12">
-<tr class='comments-list'>
+
+
+<tr class='comments-list span12'>
</tr>
</tbody>
+
+
+
+
View
12 app/assets/javascripts/backbone/templates/posts/post.jst.ejs
@@ -1,8 +1,14 @@
<div class="accordion-heading">
<div class="accordion-toggle" data-toggle="collapse" data-parent="#posts-list" href="#collapseOne<%= post.id %>">
-<a class="title">(<%= post.id %>)<%= post.title %></a>
-<a href="#/<%= post.id %>/edit" class="edit"></a>
-<a href="#/<%= post.id %>/destroy" class="destroy"></a>
+
+<a class="id"><%= post.id %></a>
+<input class="title" value=<%= post.title %> >title: </input>
+
+
+<a href="#/posts<%= post.id %>/edit" class="edit">edit</a>
+
+<a href="/posts#/<%= post.id %>/destroy" class="destroy">delete</a>
+<a class="c_length" >length:<%= length %> </a>
</div>
View
13 app/assets/javascripts/backbone/templates/posts/post.jst.ejs~
@@ -1,9 +1,14 @@
<div class="accordion-heading">
<div class="accordion-toggle" data-toggle="collapse" data-parent="#posts-list" href="#collapseOne<%= post.id %>">
-<a class="title">(<%= post.id %>)<%= post.title %></a>
-<a href="#/<%= post.id %>/edit" class="edit"></a>
-<a href="#/<%= post.id %>/destroy" class="destroy"></a>
+<a class="id"><%= post.id %></a>
+<input class="title" value=<%= post.title %> >title: </input>
+
+
+<a href="#/posts<%= post.id %>/edit" class="edit">edit</a>
+
+<a class="c_length" >length:<%= length %> </a>
+<a href="/posts#/<%= post.id %>/destroy" class="destroy">delete</a>
</div>
</div>
@@ -12,7 +17,7 @@
<div class="new_comment"></div>
- <div class="comments ></div>
+ <div class="comments" ></div>
</div>
View
23 app/assets/javascripts/backbone/views/comments/comment_view.js.coffee
@@ -17,10 +17,21 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
"click .save" : "save_array"
"blur .seconds" : "set_delay"
+
+
#"hover .todo-array button": "show_tooltip"
- initialize: () ->
+ initialize: () =>
+
+
+ console.log(this)
+
+ console.log(@options)
+ num = @options['c_length']
+ #this.model.collection.length
+ @update_span(num)
+ #@options.c_length
@status = 'saved'
@seconds = 10
this.model.bind('change', this.before_render);
@@ -60,6 +71,7 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
comment = @model.toJSON()
status = @status.toString()
seconds = @seconds.toString()
+ spans = @el.className.toString()
console.log(comment)
tmp = @template(
@@ -67,6 +79,8 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
'listed2': listed2
'obj2': status
'obj3': seconds
+
+ 'obj4': spans
)
$(@el).html(tmp)
@@ -105,6 +119,12 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
$(item).attr('background', '#000fff');
$(item).attr('value', 'Saved');
+
+ update_span: (num) ->
+ inta = parseInt(12/num)
+ str = "span" + inta
+ console.log(this)
+ @el.className = str
save_array: () ->
@@ -112,6 +132,7 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
@model.save(
content: text
)
+ this.trigger('somethingHappened');
View
23 app/assets/javascripts/backbone/views/comments/comment_view.js.coffee~
@@ -17,10 +17,20 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
"click .save" : "save_array"
"blur .seconds" : "set_delay"
+
+
#"hover .todo-array button": "show_tooltip"
initialize: () ->
+
+
+ console.log(this)
+
+ console.log(@options)
+ num = this.model.collection.length
+ @update_span(num)
+ #@options.c_length
@status = 'saved'
@seconds = 10
this.model.bind('change', this.before_render);
@@ -60,12 +70,16 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
comment = @model.toJSON()
status = @status.toString()
seconds = @seconds.toString()
-
+ spans = @el.className.toString()
+
+ console.log(comment)
tmp = @template(
'obj': comment
'listed2': listed2
'obj2': status
'obj3': seconds
+
+ 'obj4': spans
)
$(@el).html(tmp)
@@ -104,6 +118,12 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
$(item).attr('background', '#000fff');
$(item).attr('value', 'Saved');
+
+ update_span: (num) ->
+ inta = parseInt(12/num)
+ str = "span" + inta
+ console.log(this)
+ @el.className = str
save_array: () ->
@@ -111,6 +131,7 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
@model.save(
content: text
)
+ this.trigger('somethingHappened');
View
65 app/assets/javascripts/backbone/views/comments/index_view.js.coffee
@@ -11,11 +11,18 @@ class RailsBackboneRelational.Views.Comments.IndexView extends Backbone.View
initialize: () ->
#alert('options: ' + @options.ofer_length)
- @num = @options.ofer_length
+ @num = @options.comments.length
+ #ofer_length
#@options.comments.each(@update_span(num))
+ #.on('add2', this.alert_parent);
@options.comments.bind('reset', @addAll)
-
+
+ @options.comments.bind('add2', @add2_view)
+ #@options.comments.bind('remove', @addAll)
+ #@options.comments.bind('add', @addModelCallback);
+
+ #@options.comments.bind('remove', @addModelCallback);
#update_span: (num) =>
#alert(num)
@@ -25,24 +32,68 @@ class RailsBackboneRelational.Views.Comments.IndexView extends Backbone.View
#num = $(ev.target).index()
#$()
#alert(num)
+ add2_view: () =>
+ console.log(this)
+ console.log('add2_view')
+ #this.remove()
+ #this.addAll()
+ #this.render()
+ #
+ #@$(".comments-list").html('<a>ZVV</a>')
+
+ tmp = @render()
+ $(@el).append(tmp)
+ #@$el.show()
+
+ #@el.html(tmp)
+ addModelCallback1: () =>
+ console.log(this)
+ #alert('collection callback')
+ #
+ console.log('collection callback')
+
+ #@$(".comments-list").html('')
+ #tmp = @render()
+
+ #$(@el).html(tmp)
+
+
+ alert_parent: () ->
+ console.log(this)
+ alert('parent')
addAll: () =>
#console.log(@options.comments)
- @options.comments.each(@addOne)
+ comments1 = @options.comments
+ comments1.each(@addOne, num: comments1.length)
- addOne: (comment) =>
+ addOne: (comment ) =>
+ #this.trigger('somethingHappened')
+
abcd =
model : comment
+ c_length: @num.toString()
view = new RailsBackboneRelational.Views.Comments.CommentView(abcd)
- inta = parseInt(12/@num)
- view.el.className = "span" + inta
+
+ #view.el.className =
+ view.update_span(@num)
@$(".comments-list").append(view.render().el)
render: =>
- $(@el).html(@template(comments: @options.comments.toJSON() ))
+ comments = @options.comments.toJSON()
+
+ @num = @options.comments.length
+
+ obj =
+ comments: comments
+ #num: @num
+ console.log('Comments_collection: ' + obj)
+
+ $(@el).html(@template())
+ #$(@el).html(@template(obj))
@addAll()
return this
View
67 app/assets/javascripts/backbone/views/comments/index_view.js.coffee~
@@ -11,11 +11,18 @@ class RailsBackboneRelational.Views.Comments.IndexView extends Backbone.View
initialize: () ->
#alert('options: ' + @options.ofer_length)
- @num = @options.ofer_length
+ @num = @options.comments.length
+ #ofer_length
#@options.comments.each(@update_span(num))
+ #.on('add2', this.alert_parent);
@options.comments.bind('reset', @addAll)
-
+
+ @options.comments.bind('add2', @add2_view)
+ #@options.comments.bind('remove', @addAll)
+ #@options.comments.bind('add', @addModelCallback);
+
+ #@options.comments.bind('remove', @addModelCallback);
#update_span: (num) =>
#alert(num)
@@ -25,24 +32,68 @@ class RailsBackboneRelational.Views.Comments.IndexView extends Backbone.View
#num = $(ev.target).index()
#$()
#alert(num)
+ add2_view: () =>
+ console.log(this)
+ console.log('add2_view')
+ #this.remove()
+ #this.addAll()
+ #this.render()
+ #
+ #@$(".comments-list").html('<a>ZVV</a>')
+
+ tmp = @render()
+ $(@el).append(tmp)
+ #@$el.show()
+
+ #@el.html(tmp)
+ addModelCallback1: () =>
+ console.log(this)
+ #alert('collection callback')
+ #
+ console.log('collection callback')
+
+ #@$(".comments-list").html('')
+ #tmp = @render()
+
+ #$(@el).html(tmp)
+
+
+ alert_parent: () ->
+ console.log(this)
+ alert('parent')
addAll: () =>
- console.log(@options.comments)
- @options.comments.each(@addOne)
+ #console.log(@options.comments)
+ comments1 = @options.comments
+ comments1.each(@addOne, num: comments1.length)
- addOne: (comment) =>
+ addOne: (comment ) =>
+ #this.trigger('somethingHappened')
+
abcd =
model : comment
+ c_length: num
view = new RailsBackboneRelational.Views.Comments.CommentView(abcd)
- inta = parseInt(12/@num)
- view.el.className = "span" + inta
+
+ #view.el.className =
+ view.update_span(@num)
@$(".comments-list").append(view.render().el)
render: =>
- $(@el).html(@template(comments: @options.comments.toJSON() ))
+ comments = @options.comments.toJSON()
+
+ @num = @options.comments.length
+
+ obj =
+ comments: comments
+ #num: @num
+ console.log('Comments_collection: ' + obj)
+
+ $(@el).html(@template())
+ #$(@el).html(@template(obj))
@addAll()
return this
View
1  app/assets/javascripts/backbone/views/comments/new_view.js.coffee
@@ -40,7 +40,6 @@ class RailsBackboneRelational.Views.Comments.NewView extends Backbone.View
error: (comment, jqXHR) =>
alert('error')
-
console.log(comment)
console.log(jqXHR)
@model.set({errors: $.parseJSON(jqXHR.responseText)})
View
2  app/assets/javascripts/backbone/views/comments/new_view.js.coffee~
@@ -24,7 +24,7 @@ class RailsBackboneRelational.Views.Comments.NewView extends Backbone.View
@model.set('title', @$('.title').val())
- checked = @$('.direction').is('checked');
+ checked = @$('.direction').is(':checked');
@model.set('direction', checked)
View
11 app/assets/javascripts/backbone/views/posts/index_view.js.coffee
@@ -12,21 +12,18 @@ class RailsBackboneRelational.Views.Posts.IndexView extends Backbone.View
@options.posts.each(@addOne)
addOne: (post) =>
-
comments1 = post.get('comments')
num = comments1.length
-
-
view = new RailsBackboneRelational.Views.Posts.PostView({model : post})
@$("#posts-list").prepend(view.render().el)
abc =
comments: comments1
ofer_length: num
- comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
- view.$(".comments").html(comments_view.render().el)
- new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments'))
- view.$(".new_comment").html(new_comment_view.render().el)
+ #comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
+ #view.$(".comments").html(comments_view.render().el)
+ #new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments'))
+ #view.$(".new_comment").html(new_comment_view.render().el)
render: =>
$(@el).html(@template(posts: @options.posts.toJSON() ))
View
9 app/assets/javascripts/backbone/views/posts/index_view.js.coffee~
@@ -9,22 +9,19 @@ class RailsBackboneRelational.Views.Posts.IndexView extends Backbone.View
addAll: () =>
@view = new RailsBackboneRelational.Views.Posts.NewView(collection: @options.posts)
$("#new_post").html(@view.render().el)
- #@options.posts.each(@addOne)
+ @options.posts.each(@addOne)
addOne: (post) =>
-
comments1 = post.get('comments')
num = comments1.length
-
-
view = new RailsBackboneRelational.Views.Posts.PostView({model : post})
@$("#posts-list").prepend(view.render().el)
abc =
comments: comments1
ofer_length: num
- comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
- view.$(".comments").html(comments_view.render().el)
+ #comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
+ #view.$(".comments").html(comments_view.render().el)
new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments'))
view.$(".new_comment").html(new_comment_view.render().el)
View
1  app/assets/javascripts/backbone/views/posts/new_view.js.coffee
@@ -29,6 +29,7 @@ class RailsBackboneRelational.Views.Posts.NewView extends Backbone.View
new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments'))
view.$(".new_comment").html(new_comment_view.render().el)
$("#title").val('')
+
error: (post, jqXHR) =>
@model.set({errors: $.parseJSON(jqXHR.responseText)})
View
51 app/assets/javascripts/backbone/views/posts/post_view.js.coffee
@@ -5,34 +5,81 @@ class RailsBackboneRelational.Views.Posts.PostView extends Backbone.View
events:
"click .destroy" : "destroy"
+ #"click .submit" : "update"
+ #"dblclick a.todo-content" : "edit",
+
+ "keypress .title" : "updateOnEnter"
+ "dblclick .accordion-toggle" : "show_post"
+
+
initialize: () ->
#alert('init post')
#alert((@model.get('comments')).length)
+
+ #this.on('somethingHappened', this.alert_parent );
+ #this.trigger('somethingHappened')
className: "accordion-group"
tagName: "div"
+ show_post: () -> #fetch and show
+ console.log(this)
+ tmp = this.render()
+
+ post = @model
+ comments1 = post.get('comments')
+ num = comments1.length
+ view = @
+ abc =
+ comments: comments1
+ ofer_length: num
+
+ comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
+ view.$(".comments").html(comments_view.render().$el)
+ new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments'))
+ view.$(".new_comment").html(new_comment_view.render().el)
+
destroy: () ->
@model.destroy()
this.remove()
return false
+ #update: ->
+
+ #this.model.save(
+ #title: tmp
+ #)
+ #
+ #
+ updateOnEnter: (e) ->
+
+ this.trigger('somethingHappened')
+ if e.keyCode is 13
+ console.log(e)
+ @input = this.$(".title");
+ console.log(@input)
+
+ #@model.save({ title: @input.val() })
+ #$(@el).removeClass("editing")
+
render: ->
post = @model.toJSON()
+ console.log(this)
+ num = @model.get('comments').length
#alert(num)
tmp = @template(
'post': post
- #'length': num
+ 'length': num
)
$(@el).html(tmp)
return this
- render2: =>
+ not_render2: =>
listed2 = this.splitted2()
View
57 app/assets/javascripts/backbone/views/posts/post_view.js.coffee~
@@ -5,40 +5,81 @@ class RailsBackboneRelational.Views.Posts.PostView extends Backbone.View
events:
"click .destroy" : "destroy"
+ #"click .submit" : "update"
+ #"dblclick a.todo-content" : "edit",
+
+ "keypress .title" : "updateOnEnter"
+ "dblclick .accordion-toggle" : "show_post"
+
+
initialize: () ->
#alert('init post')
#alert((@model.get('comments')).length)
+
+ #this.on('somethingHappened', this.alert_parent );
+ #this.trigger('somethingHappened')
className: "accordion-group"
tagName: "div"
+ show_post: () -> #fetch and show
+ console.log(this)
+ tmp = this.render()
+
+ post = @model
+ comments1 = post.get('comments')
+ num = comments1.length
+ view = @
+ abc =
+ comments: comments1
+ ofer_length: num
+
+ comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
+ view.$(".comments").html(comments_view.render().el)
+ new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments'))
+ view.$(".new_comment").html(new_comment_view.render().el)
+
destroy: () ->
@model.destroy()
this.remove()
return false
+ #update: ->
+
+ #this.model.save(
+ #title: tmp
+ #)
+ #
+ #
+ updateOnEnter: (e) ->
+
+ this.trigger('somethingHappened')
+ if e.keyCode is 13
+ console.log(e)
+ @input = this.$(".title");
+ console.log(@input)
+
+ #@model.save({ title: @input.val() })
+ #$(@el).removeClass("editing")
+
render: ->
- num = @model.get('comments').length
- comments = @model.get('comments')
- for comment in comments
- do (comment) ->
- console.log( comment)
- #('span') = num
post = @model.toJSON()
+ console.log(this)
+ num = @model.get('comments').length
#alert(num)
tmp = @template(
'post': post
- #'length': num
+ 'length': num
)
$(@el).html(tmp)
return this
- render2: =>
+ not_render2: =>
listed2 = this.splitted2()
View
3  app/views/layouts/application.html.erb
@@ -7,7 +7,8 @@
<%= csrf_meta_tags %>
-<meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
View
3  app/views/layouts/application.html.erb~
@@ -6,7 +6,8 @@
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
- <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
+
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
View
0  spec/javascripts/general/app_spec.js
No changes.
View
71 spec/javascripts/general/collection_spec.js
@@ -0,0 +1,71 @@
+describe('About Backbone.Collection', function() {
+ it('Can add Model instances as objects one at a time, or as arrays of models.', function() {
+ window.TodoList =
+
+window.TodoList = RailsBackboneRelational.Collections.PostsCollection
+
+ var todos = new TodoList();
+
+ expect(todos.length).toBe(0);
+
+ todos.add({ title: 'Clean the kitchen' });
+
+ expect(todos.length).toEqual(1);
+
+ // How would you add multiple models to the collection with a single method call?
+
+ todos.add([{ title: 'Do the laundry'},
+ { title: 'Clean the house'}]);
+ expect(todos.length).toEqual(3);
+ });
+
+ it('Can have a comparator function to keep the collection sorted.', function() {
+ var todos = new TodoList();
+
+ // Without changing the sequence of the Todo objects in the array, how would you
+ // get the expectations below to pass?
+ //
+ // How is the collection sorting the models when they are added? (see TodoList.comparator in js/todos.js)
+ //
+ // Hint: Could you change attribute values on the todos themselves?
+
+ todos.add([{ title: 'Do the laundry'},
+ { title: 'Clean the house'},
+ { title: 'Take a nap'}]);
+
+ expect(todos.at(1).get('title')).toEqual('Clean the house');
+ expect(todos.at(0).get('title')).toEqual('Do the laundry');
+ expect(todos.at(2).get('title')).toEqual('Take a nap');
+ });
+
+ // How are you supposed to know what Backbone objects trigger events? To the docs!
+ // http://documentcloud.github.com/backbone/#FAQ-events
+
+ it('Fires custom named events when the contents of the collection change.', function() {
+ var todos = new TodoList();
+
+ var addModelCallback = jasmine.createSpy('-add model callback-');
+ todos.bind('add', addModelCallback);
+
+ // How would you get both expectations to pass with a single method call?
+
+ todos.add([ { title: 'Clean the house'}
+ ]);
+
+ expect(todos.length).toEqual(1);
+ expect(addModelCallback).toHaveBeenCalled();
+
+ var removeModelCallback = jasmine.createSpy('-remove model callback-');
+
+ todos.bind('remove', removeModelCallback);
+
+ todos.models[0].destroy()
+ /*
+ *todos.remove({index: 1})
+ */
+ // How would you get both expectations to pass with a single method call?
+
+ expect(todos.length).toEqual(0);
+ expect(removeModelCallback).toHaveBeenCalled();
+ });
+});
View
127 spec/javascripts/general/events_spec.js
@@ -0,0 +1,127 @@
+describe('About Backbone.Events', function() {
+
+ var obj = {};
+ _.extend(obj, Backbone.Events);
+
+ beforeEach(function() {
+ obj.off(); // remove all custom events before each spec is run.
+ });
+
+ it('Any regular javascript object can be extended with custom event functionality.', function() {
+ var basicObject = {};
+
+ // How would you get these Backbone.Events functions added to basicObject?
+ // Hint: http://documentcloud.github.com/backbone/#Events
+
+ _.extend(basicObject, Backbone.Events);
+ expect(typeof basicObject.on).toEqual('function');
+ expect(typeof basicObject.off).toEqual('function');
+ expect(typeof basicObject.trigger).toEqual('function');
+ });
+
+ it('Events allows us to bind and trigger custom named events on an object.', function() {
+ var callback = jasmine.createSpy('-Custom Event Callback-');
+
+ obj.on('basic_event', callback);
+
+ // How would you cause the callback for this custom event to be called?
+obj.trigger('basic_event')
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('Events allows us to trigger more than one event at the same time.', function() {
+ var callback = jasmine.createSpy('-Custom Event Callback-');
+
+ // You can bind an object to two events at the same time separating them with spaces
+ obj.on('an_event another_event', callback);
+
+ // How would you change the trigger call to trigger two events at the same time?
+ obj.trigger('an_event')
+
+ obj.trigger('another_event')
+
+ expect(callback.callCount).toBe(2);
+ });
+
+ it('Triggered events pass along any arguments to the callback.', function() {
+ var callback = jasmine.createSpy('-Custom Event Callback-');
+
+ obj.on('some_event', callback);
+
+ obj.trigger('some_event', 'arg1', 'arg2');
+
+ expect(callback.mostRecentCall.args).toEqual(['arg1', 'arg2']);
+ });
+
+ it('Bound events can also pass a specific context to the event callback.', function() {
+ var foo = { color: 'blue' };
+
+ var changeColor = function() {
+ this.color = 'red';
+ }
+
+ /***
+ * Does refering to 'this' from within an anonymous function seem foreign to you?
+ * No idea what 'context' refers to when talking about javascript?
+ * Here's a some reading that can help clarify things:
+ * http://javascriptweblog.wordpress.com/2010/08/30/understanding-javascripts-this/
+ *
+ * Now, back to the koans ...
+ ***/
+
+ // How would you get 'this.color' to refer to 'foo' in the changeColor function?
+ // Hint: Notice anything different about the 'on' method below?
+
+ obj.on('an_event', changeColor, foo);
+
+ obj.trigger('an_event');
+
+ expect(foo.color).toEqual('red');
+ });
+
+ it("Evented objects can bind 'all' as a special event name to capture all triggered events on the object.", function() {
+ var callback = jasmine.createSpy('-Custom Event Callback-');
+
+ obj.on('all', callback);
+
+ // How are you going to call obj.trigger to get both expectations passing?
+obj.trigger('custom_event')
+ expect(callback.callCount).toBe(1);
+ expect(callback.mostRecentCall.args[0]).toBe('custom_event');
+ });
+
+ it('Evented objects can also have their named events removed.', function() {
+ var spy1 = jasmine.createSpy('-Spy 1-');
+ var spy2 = jasmine.createSpy('-Spy 2-');
+ var spy3 = jasmine.createSpy('-Spy 3-');
+
+ obj.on('foo', spy1);
+ obj.on('foo', spy2);
+ obj.on('foo', spy3);
+ obj.on('bar', spy1);
+
+ // How do you unbind just a single callback for the event?
+
+ obj.off('foo', spy1);
+
+
+ obj.trigger('foo');
+
+ expect(spy1).not.toHaveBeenCalled();
+
+ // How do you unbind all callbacks tied to the event with a single method?
+obj.off('foo')
+ obj.trigger('foo');
+
+ expect(spy2.callCount).toEqual(1);
+ expect(spy3.callCount).toEqual(1);
+
+ // How do you unbind all callbacks and events tied to the object with a single method?
+
+ obj.off( );
+ obj.trigger('bar');
+
+ expect(spy1).not.toHaveBeenCalled();
+ });
+
+});
View
68 spec/javascripts/general/model_spec.js
@@ -0,0 +1,68 @@
+return;
+/**
+ * NOTE: At this point we're test driving the sample Todo list app.
+ * You'll be refering to js/todos.js quite a bit from now on,
+ * so make sure you have it open.
+ */
+describe('About Backbone.Model', function() {
+
+ it('A Model can have default values for its attributes.', function() {
+ var todo = new Todo();
+
+ var defaultAttrs = {
+ text: 'What is the default value?',
+ done : 'What is the default value?',
+ order: 'What is the default value?'
+ }
+
+ expect(defaultAttrs).toEqual(todo.attributes);
+ });
+
+ it('Attributes can be set on the model instance when it is created.', function() {
+ var todo = new Todo({ text: 'Get oil change for car.' });
+
+ var expectedText = 'FIX ME';
+
+ expect(expectedText).toEqual(todo.get('text'));
+ });
+
+ it('If it is exists, an initialize function on the model will be called when it is created.', function() {
+ var todo = new Todo({ text: 'Stop monkeys from throwing their own feces!' });
+
+ // Why does the expected text differ from what is passed in when we create the Todo?
+ // What is happening in Todo.initialize? (see js/todos.js line 22)
+ // You can get this test passing without changing todos.js or the expected text.
+
+ expect('Stop monkeys from throwing their own double rainbows!').toBe(todo.get('text'));
+ });
+
+ it('Fires a custom event when the state changes.', function() {
+ var callback = jasmine.createSpy('-change event callback-');
+
+ var todo = new Todo();
+
+ todo.bind('change', callback);
+
+ // How would you update a property on the todo here?
+ // Hint: http://documentcloud.github.com/backbone/#Model-set
+
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('Can contain custom validation rules, and will trigger an error event on failed validation.', function() {
+ var errorCallback = jasmine.createSpy('-error event callback-');
+
+ var todo = new Todo();
+
+ todo.bind('error', errorCallback);
+
+ // What would you need to set on the todo properties to cause validation to fail?
+ // Refer to Todo.validate in js/todos.js to see the logic.
+
+ var errorArgs = errorCallback.mostRecentCall.args;
+
+ expect(errorArgs).toBeDefined();
+ expect(errorArgs[0]).toBe(todo);
+ expect(errorArgs[1]).toBe('Todo.done must be a boolean value.');
+ });
+});
View
50 spec/javascripts/general/router_spec.js
@@ -0,0 +1,50 @@
+describe('About Backbone.Router', function() {
+ var MyRouter = Backbone.Router.extend({
+ routes: {
+ 'help': 'help',
+ 'search/:query/:page': 'search',
+ 'articles/*path': 'articles'
+ },
+
+ // route callback methods are just regular javascript functions.
+ // we use spies for the following callback methods to make testing easier.
+
+ help: jasmine.createSpy('help router action'),
+
+ search: jasmine.createSpy('search router action'),
+
+ articles: jasmine.createSpy('articles router action')
+ });
+
+ var router = new MyRouter();
+
+ Backbone.history.start({
+ root: '/specrunner.html',
+ silent: true
+ });
+
+ // For the following tests refer to:
+ // * the routes object just a few lines up that belongs to MyRouter
+ // * http://documentcloud.github.com/backbone/#Router-navigate
+
+ it('Routers provide a way to map urls to methods.', function() {
+ router.navigate('help', true);
+
+ expect(router.help).toHaveBeenCalled();
+ });
+
+ it('The routes object can do token matching for a given url, passing the matched tokens to the mapped method.', function() {
+ router.navigate('search/restaurants/1', true);
+
+ expect(router.search).toHaveBeenCalled();
+ expect(router.search.mostRecentCall.args).toEqual(['restaurants', '1']);
+ });
+
+ it('The routes object can also do wildcard matching for a given url, passing the entire matched path to the mapped method.', function() {
+ router.navigate('articles/2011/07/01/a_blog_post', true);
+
+ expect(router.articles).toHaveBeenCalled();
+ expect(router.articles.mostRecentCall.args).toEqual(['2011/07/01/a_blog_post']);
+ });
+
+});
View
77 spec/javascripts/general/views_spec.js
@@ -0,0 +1,77 @@
+return;
+describe('About Backbone.View', function() {
+ var todoView;
+
+ beforeEach(function() {
+ window.TodoView = RailsBackboneRelational.Views.Posts.PostView()
+
+ window.Todo = RailsBackboneRelational.Models.Post()
+
+ var todo = new Todo();
+ todo.localStorage =
+ new Backbone.LocalStorage("ViewSpecs")
+
+ $('body').append('<ul id="todoList"></ul>');
+ todoView = new TodoView({ model: todo });
+ });
+
+ afterEach(function() {
+ todoView.remove();
+ $('#todoList').remove();
+ });
+
+ it('Views are tied to a DOM element when created, based off the property provided.', function() {
+ var tagName = 'what html element represents this view?';
+
+ expect(tagName).toEqual(todoView.tagName)
+ expect(tagName).toEqual(todoView.el.tagName.toLowerCase());
+ });
+
+ it('Views are backed by a model instance, which provides the data when rendering the view.', function() {
+ // What method would you call on todoView to get this expectation to pass?
+ // Hint: You can accomplish this without accessing todoView.model directly.
+
+ expect(todoView.model.get('done')).toBe(true);
+ });
+
+ it('When rendered, the view element contains the complete DOM representation of the view.', function() {
+ todoView.render();
+
+ // Hint: render() just builds the DOM representation of the view, but doesn't insert it into the DOM.
+ // How would you append it to the ul#todoList?
+ // How do you access the view's DOM representation?
+ //
+ // Hint: http://documentcloud.github.com/backbone/#View-el and TodoApp.addOne in todos.js
+
+ expect($('#todoList').find('li').length).toBe(1);
+ });
+
+ it('Views can contain an events hash to wire up view methods to DOM events.', function() {
+ var viewElt;
+
+ spyOn(todoView.model, 'toggle');
+
+ // Render the <li> for the view, and append it to the <ul>
+ runs(function() {
+ $('#todoList').append(todoView.render().el);
+ });
+
+ // We use runs and waitsFor since this is an async process, and want to make
+ // sure we don't run our expectations until the view's markup is accessible in the DOM.
+ waitsFor(function() {
+ viewElt = $('#todoList li input.check').filter(':first');
+
+ return viewElt.length > 0;
+ }, 1000, 'Expected DOM Elt to exist');
+
+ // Make your changes within this function, you don't need to touch the code above.
+ runs(function() {
+ // Hint: How would you trigger the view, via a DOM Event, to toggle the 'done' status?
+ // (See todos.js line 70, where the events hash is defined.)
+ //
+ // Hint: http://api.jquery.com/click
+
+ expect(todoView.model.toggle).toHaveBeenCalled();
+ });
+ });
+});
View
83 spec/javascripts/models/post_spec.js
@@ -0,0 +1,83 @@
+/**
+ * NOTE: At this point we're test driving the sample Todo list app.
+ * You'll be refering to js/todos.js quite a bit from now on,
+ * so make sure you have it open.
+ */
+describe('About Backbone.Model', function() {
+window.Todo = RailsBackboneRelational.Models.Post
+
+ it('A Model can have default values for its attributes.', function() {
+ var todo = new Todo();
+
+ var defaultAttrs = {
+ title: 'title?'
+ }
+
+ expect(defaultAttrs['title']).toEqual(todo.attributes['title']);
+ });
+
+ it('Attributes can be set on the model instance when it is created.', function() {
+ var todo = new Todo({ title: 'title1' });
+
+ expect(todo.get('title')).toEqual('title1');
+ });
+
+ it('If it is exists, an initialize function on the model will be called when it is created.', function() {
+
+ // Why does the expected text differ from what is passed in when we create the Todo?
+ // What is happening in Todo.initialize? (see js/todos.js line 22)
+ // You can get this test passing without changing todos.js or actualText.
+ var todo = new Todo({ title: 'a-b' });
+
+ actualText = 'a_b'; // Don't change
+ expect(todo.sanitize1(actualText)).toBe('a-b');
+ });
+
+ it('Fires a custom event when the state changes.', function() {
+ var callback = jasmine.createSpy('-change event callback-');
+
+ var todo = new Todo({title: 'title..'});
+
+ todo.on('change', callback);
+
+ // How would you update a property on the todo here?
+ // Hint: http://documentcloud.github.com/backbone/#Model-set
+ todo.set(
+ {title: 'abc'}
+ )
+ expect(callback).toHaveBeenCalled();
+ });
+
+ it('Can contain custom validation rules, and will trigger an error event on failed validation.', function() {
+ var errorCallback = jasmine.createSpy('-error event callback-');
+
+ var todo = new Todo({title: 'xx'});
+
+ todo.on('error', errorCallback);
+
+ // What would you need to set on the todo properties to cause validation to fail?
+ // Refer to Todo.validate in js/todos.js to see the logic.
+
+ todo.set(
+ {
+ title: null
+ }
+ )
+
+ var errorArgs = errorCallback.mostRecentCall.args;
+ console.log(
+ errorCallback
+ )
+
+
+ expect(errorCallback).toBeDefined();
+
+ expect(errorArgs).toBeDefined();
+
+ expect(errorArgs[0]).toBe(todo);
+
+ expect(errorArgs[1]).toBe(
+ 'attr.direction must be a non null value.'
+ );
+ });
+});
View
111 spec/javascripts/models/task_spec.js
@@ -1,111 +0,0 @@
-return;
-describe('TodoList.Models.Task', function() {
-
- it('should be defined', function() {
- expect(TodoList.Models.Task).toBeDefined();
- });
-
- var task;
-
- beforeEach(function() {
- task = new TodoList.Models.Task();
- });
-
- it('should have correct default values', function() {
- expect(task.id).toBeUndefined();
- expect(task.get('name')).toEqual('');
- expect(task.get('complete')).toBeFalsy();
- });
-
- describe('#getId', function() {
- it('should be defined', function() {
- expect(task.getId).toBeDefined();
- });
-
- it('should return task id', function () {
- var stub = sinon.stub(task, 'get').returns(11);
-
- expect(task.getId()).toEqual(11);
- expect(stub.calledWith('id')).toBeTruthy();
- });
- });
-
- describe('#getName', function() {
- it('should be defined', function() {
- expect(task.getName).toBeDefined();
- });
-
- it('should return task name', function() {
- var stub = sinon.stub(task, 'get').returns('Task name');
-
- expect(task.getName()).toEqual('Task name');
- expect(stub.calledWith('name')).toBeTruthy();
- });
- });
-
- describe('#getComplete', function() {
- it('should be defined', function() {
- expect(task.getComplete).toBeDefined();
- });
-
- it('should return task id', function() {
- var stub = sinon.stub(task, 'get').returns(false);
-
- expect(task.getComplete()).toEqual(false);
- expect(stub.calledWith('complete')).toBeTruthy();
- });
- });
-
- describe('#save', function() {
- var server = null;
-
- beforeEach(function() {
- server = sinon.fakeServer.create();
- });
-
- afterEach(function() {
- server.restore();
- });
-
- it('should send valid data', function() {
- task.save({name: 'New task to do'});
- var request = server.requests[0];
-
- var params = JSON.parse(request.requestBody);
- expect(params.task).toBeDefined();
- expect(params.task.name).toEqual('New task to do');
- expect(params.task.complete).toBeFalsy();
- });
-
- describe('request', function() {
- beforeEach(function() {
- task.set({ name: 'New task to do' });
- });
-
- describe('on create', function() {
- beforeEach(function() {
- task.set({ id: null });
- task.save();
- this.request = server.requests[0];
- });
-
- itShouldBePOST();
- itShouldBeAsync();
- itShouldHaveUrl('/tasks.json');
- });
-
- describe('on update', function() {
- beforeEach(function() {
- task.id = 66;
- task.save();
- this.request = server.requests[0];
- });
-
- itShouldBePUT();
- itShouldBeAsync();
- itShouldHaveUrl('/tasks/66.json');
- });
- });
- });
-
-});
View
111 spec/javascripts/models/task_spec.js~
@@ -1,111 +0,0 @@
-return;
-describe('TodoList.Models.Task', function() {
-
- it('should be defined', function() {
- expect(TodoList.Models.Task).toBeDefined();
- });
-
- var task;
-
- beforeEach(function() {
- task = new TodoList.Models.Task();
- });
-
- it('should have correct default values', function() {
- expect(task.id).toBeUndefined();
- expect(task.get('name')).toEqual('');
- expect(task.get('complete')).toBeFalsy();
- });
-
- describe('#getId', function() {
- it('should be defined', function() {
- expect(task.getId).toBeDefined();
- });
-
- it('should return task id', function () {
- var stub = sinon.stub(task, 'get').returns(11);
-
- expect(task.getId()).toEqual(11);
- expect(stub.calledWith('id')).toBeTruthy();
- });
- });
-
- describe('#getName', function() {
- it('should be defined', function() {
- expect(task.getName).toBeDefined();
- });
-
- it('should return task name', function() {
- var stub = sinon.stub(task, 'get').returns('Task name');
-
- expect(task.getName()).toEqual('Task name');
- expect(stub.calledWith('name')).toBeTruthy();
- });
- });
-
- describe('#getComplete', function() {
- it('should be defined', function() {
- expect(task.getComplete).toBeDefined();
- });
-
- it('should return task id', function() {
- var stub = sinon.stub(task, 'get').returns(false);
-
- expect(task.getComplete()).toEqual(false);
- expect(stub.calledWith('complete')).toBeTruthy();
- });
- });
-
- describe('#save', function() {
- var server = null;
-
- beforeEach(function() {
- server = sinon.fakeServer.create();
- });
-
- afterEach(function() {
- server.restore();
- });
-
- it('should send valid data', function() {
- task.save({name: 'New task to do'});
- var request = server.requests[0];
-
- var params = JSON.parse(request.requestBody);
- expect(params.task).toBeDefined();
- expect(params.task.name).toEqual('New task to do');
- expect(params.task.complete).toBeFalsy();
- });
-
- describe('request', function() {
- beforeEach(function() {
- task.set({ name: 'New task to do' });
- });
-
- describe('on create', function() {
- beforeEach(function() {
- task.set({ id: null });
- task.save();
- this.request = server.requests[0];
- });
-
- itShouldBePOST();
- itShouldBeAsync();
- itShouldHaveUrl('/tasks.json');
- });
-
- describe('on update', function() {
- beforeEach(function() {
- task.id = 66;
- task.save();
- this.request = server.requests[0];
- });
-
- itShouldBePUT();
- itShouldBeAsync();
- itShouldHaveUrl('/tasks/66.json');
- });
- });
- });
-
-});

No commit comments for this range

Something went wrong with that request. Please try again.