Commit 9f64608

mo khan <mo@mokhan.ca>
2015-06-20 17:38:59
start adding tests for google sync button.
1 parent 7947bfa
Changed files (2)
app
assets
spec
app/assets/javascripts/views/google_sync_button.js.coffee
@@ -2,12 +2,12 @@ Stronglifters.GoogleSyncButton = Ractive.extend
   template: "<button on-click='synchronize'><i class='fa {{icon}}'></i> {{text}}</button>",
   oninit: ->
     @set(text: 'Sync With Google', icon: 'fa-camera-retro')
-    @on 'synchronize', (event) =>
-      @synchronize()
-
-  synchronize: ->
-    @set(text: 'Syncing...', icon: 'fa-spin fa-spinner')
-    new Stronglifters.GoogleDrive({
+    @drive = new Stronglifters.GoogleDrive
       client_id: @get('client_id')
       drive_upload_path: @get('drive_upload_path')
-    }).syncFile()
+    @on 'synchronize', (event) ->
+      @synchronize(@drive)
+
+  synchronize: (drive) ->
+    @set(text: 'Syncing...', icon: 'fa-spin fa-spinner')
+    drive.syncFile()
spec/javascripts/views/google_sync_button_spec.js.coffee
@@ -0,0 +1,12 @@
+#= require views/google_sync_button
+describe "GoogleSyncButton", ->
+  beforeEach ->
+    @subject = new Stronglifters.GoogleSyncButton()
+
+  describe "synchronize", ->
+    it 'synchronizes the drive', ->
+      drive = { syncFile: null }
+      spyOn(drive, 'syncFile')
+      @subject.synchronize(drive)
+      expect(drive).to haveCalled('syncFile')
+