Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 11 files changed
  • 0 comments
  • 1 contributor
20  Gemfile.lock
@@ -35,7 +35,7 @@ GEM
35 35
       jquery-rails
36 36
       railties (>= 3.1)
37 37
     builder (3.0.0)
38  
-    childprocess (0.3.4)
  38
+    childprocess (0.3.5)
39 39
       ffi (~> 1.0, >= 1.0.6)
40 40
     coffee-rails (3.2.2)
41 41
       coffee-script (>= 2.2.0)
@@ -54,24 +54,24 @@ GEM
54 54
     erubis (2.7.0)
55 55
     execjs (1.4.0)
56 56
       multi_json (~> 1.0)
57  
-    ffi (1.1.4)
58  
-    guard (1.3.0)
  57
+    ffi (1.1.5)
  58
+    guard (1.3.2)
59 59
       listen (>= 0.4.2)
60 60
       thor (>= 0.14.6)
61  
-    guard-jasmine (1.6.1)
  61
+    guard-jasmine (1.7.0)
62 62
       childprocess
63 63
       guard (>= 1.1.0)
64 64
       multi_json
65 65
       thor
66  
-    haml (3.1.6)
  66
+    haml (3.1.7)
67 67
     hike (1.2.1)
68 68
     i18n (0.6.0)
69 69
     jasminerice (0.0.9)
70 70
       coffee-rails
71 71
       haml
72 72
     journey (1.0.4)
73  
-    jquery-rails (2.0.2)
74  
-      railties (>= 3.2.0, < 5.0)
  73
+    jquery-rails (2.1.0)
  74
+      railties (>= 3.1.0, < 5.0)
75 75
       thor (~> 0.14)
76 76
     json (1.7.4)
77 77
     kgio (2.7.4)
@@ -124,13 +124,13 @@ GEM
124 124
     rspec-core (2.11.1)
125 125
     rspec-expectations (2.11.2)
126 126
       diff-lcs (~> 1.1.3)
127  
-    rspec-mocks (2.11.1)
  127
+    rspec-mocks (2.11.2)
128 128
     rspec-rails (2.11.0)
129 129
       actionpack (>= 3.0)
130 130
       activesupport (>= 3.0)
131 131
       railties (>= 3.0)
132 132
       rspec (~> 2.11.0)
133  
-    sass (3.1.20)
  133
+    sass (3.2.1)
134 134
     sass-rails (3.2.5)
135 135
       railties (~> 3.2.0)
136 136
       sass (>= 3.1.10)
@@ -140,7 +140,7 @@ GEM
140 140
       rack (~> 1.0)
141 141
       tilt (~> 1.1, != 1.3.0)
142 142
     sqlite3 (1.3.6)
143  
-    thor (0.15.4)
  143
+    thor (0.16.0)
144 144
     tilt (1.3.3)
145 145
     treetop (1.4.10)
146 146
       polyglot
2  app/assets/javascripts/collections/contacts.js.coffee
... ...
@@ -1,5 +1,5 @@
1 1
 class ContactsApp.Collections.Contacts extends Backbone.Collection
2 2
 
3  
-  Model: ContactsApp.Models.Contact
  3
+  model: ContactsApp.Models.Contact
4 4
 
5 5
   url: '/contacts'
1  app/assets/javascripts/models/contact.js.coffee
@@ -11,7 +11,6 @@ class ContactsApp.Models.Contact extends Backbone.Model
11 11
     @on('change:first_name', @setName, this)
12 12
     @on('change:last_name', @setName, this)
13 13
 
14  
-
15 14
   setName: ->
16 15
     fullname = @get('first_name') + ' ' + @get('last_name')
17 16
     @set("name", fullname, silent: true)
5  app/assets/javascripts/views/contact_view.js.coffee
@@ -10,10 +10,9 @@ class ContactsApp.Views.ContactView extends Backbone.View
10 10
     'click' : 'edit'
11 11
 
12 12
   initialize: ->
13  
-    @render()
14  
-
  13
+    
15 14
   edit: ->
16  
-    console.log "hej"
  15
+    new ContactsApp.Views.ContactEditView(model: @model)
17 16
 
18 17
   render: ->
19 18
     $(@el).html(@template(@model.toJSON()))
4  app/assets/javascripts/views/contacts_view.js.coffee
@@ -14,9 +14,9 @@ class ContactsApp.Views.ContactsView extends Backbone.View
14 14
     $(@el).html(@template)
15 15
 
16 16
   renderContacts: =>
17  
-   @collection.each(@appendView)
  17
+    @collection.each(@appendView)
18 18
 
19 19
   appendView: (model) =>
20 20
     view = new ContactsApp.Views.ContactView(model: model)
21  
-    @subviews.push view
  21
+    @subviews.push(view)
22 22
     $('.contacts', @el).append(view.render().el)
2  app/assets/templates/contacts/contact.jst.eco
... ...
@@ -1,5 +1,5 @@
1 1
 <ul>
2  
-  <li class="name"><%= @first_name %></li>
  2
+  <li class="name"><%= @name %></li>
3 3
   <li class="email"><%= @email %></li>
4 4
   <li class="phone"><%= @phone %></li>
5 5
 </ul>
1  app/controllers/contacts_controller.rb
@@ -3,4 +3,5 @@ class ContactsController < ApplicationController
3 3
   def index
4 4
     render json: Contact.all    
5 5
   end
  6
+
6 7
 end
2  spec/javascripts/collections/contacts_spec.js.coffee
@@ -5,3 +5,5 @@ describe 'collections/Contacts', ->
5 5
   it 'can be instantiated', ->
6 6
     collection = new ContactsApp.Collections.Contacts()
7 7
     expect(collection).not.toBeNull()
  8
+
  9
+  
17  spec/javascripts/models/contact_spec.js.coffee
@@ -19,6 +19,14 @@ describe 'models/Contact', ->
19 19
     model.set(first_name: "A", last_name: "B")
20 20
     expect(model.get('name')).toEqual("A B")
21 21
 
  22
+  it 'should set name on new instance', ->
  23
+    model = new ContactsApp.Models.Contact(
  24
+      first_name: "Erik",
  25
+      last_name: "Eldewall"
  26
+    )
  27
+
  28
+    expect(model.get('name')).toEqual("Erik Eldewall")
  29
+
22 30
   describe 'instance default values', ->
23 31
     beforeEach ->
24 32
       @contact = new ContactsApp.Models.Contact()
@@ -34,3 +42,12 @@ describe 'models/Contact', ->
34 42
 
35 43
     it 'has default value for phone', ->
36 44
       expect(@contact.get('phone')).toEqual('')
  45
+
  46
+  describe "JSON", ->
  47
+    beforeEach ->
  48
+      @contact = new ContactsApp.Models.Contact()
  49
+      
  50
+    it "should have name defined as json", ->
  51
+      json = @contact.toJSON()
  52
+      expect(json.name).toBeDefined()
  53
+
2  spec/javascripts/routers/contacts_router_spec.js.coffee
@@ -41,7 +41,7 @@ describe "routers/Contacts", ->
41 41
     
42 42
     afterEach ->
43 43
       Backbone.history.stop()
44  
-
  44
+ 
45 45
     describe "index", ->
46 46
       it "should have a index action", ->
47 47
         expect(@router.index).toBeDefined()
6  spec/javascripts/views/contact_view_spec.js.coffee
@@ -21,14 +21,18 @@ describe "ContactView", ->
21 21
   describe 'behaviour', ->
22 22
     it 'should call edit on click', ->
23 23
       view = new ContactsApp.Views.ContactView(model: @model)
24  
-      spy = spyOn(view, "edit")
  24
+      spy = spyOn(view, "edit").andCallThrough()
25 25
       view.delegateEvents()
26 26
       $(view.el).click()
27 27
       expect(spy).toHaveBeenCalled()
28 28
 
29 29
     describe 'edit', ->
30 30
       it "should create a edit view passing model", ->
  31
+        view = new ContactsApp.Views.ContactView(model: @model)
  32
+        spy = spyOn(ContactsApp.Views, "ContactEditView")
31 33
 
  34
+        view.edit()
  35
+        expect(spy).toHaveBeenCalledWith( { @model } )
32 36
       
33 37
   describe 'element', ->
34 38
     beforeEach ->

No commit comments for this range

Something went wrong with that request. Please try again.