From 2123fabae6fcf4d4c67d23d7a74b1f4f90030989 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Wed, 20 Feb 2013 11:30:39 -0800 Subject: [PATCH] Window is only shutdown if a rootView and project exist Keeping the shutdown state as a local var in window.coffee causes spec failures because window.shutdown can only be called once in the entire spec suite --- spec/app/window-spec.coffee | 19 ++++++++++--------- spec/spec-helper.coffee | 4 +++- src/app/window.coffee | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index ff82cc5fa..f229e426e 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -2,17 +2,17 @@ $ = require 'jquery' fs = require 'fs' describe "Window", -> - [rootView] = [] + projectPath = null beforeEach -> - window.handleWindowEvents() spyOn(atom, 'getPathToOpen').andReturn(project.getPath()) + window.handleWindowEvents() window.buildProjectAndRootView() - rootView = window.rootView + projectPath = project.getPath() afterEach -> window.shutdown() - atom.setRootViewStateForPath(project.getPath(), null) + atom.setRootViewStateForPath(projectPath, null) $(window).off 'beforeunload' describe "when the window is loaded", -> @@ -87,16 +87,17 @@ describe "Window", -> removeStylesheet(cssPath) expect($(document.body).css('font-weight')).not.toBe("bold") - describe "shutdown()", -> + describe ".shutdown()", -> it "saves the serialized state of the project and root view to the atom object so it can be rehydrated after reload", -> - expect(atom.getRootViewStateForPath(project.getPath())).toBeUndefined() + projectPath = project.getPath() + expect(atom.getRootViewStateForPath(projectPath)).toBeUndefined() # JSON.stringify removes keys with undefined values rootViewState = JSON.parse(JSON.stringify(rootView.serialize())) projectState = JSON.parse(JSON.stringify(project.serialize())) - shutdown() + window.shutdown() - expect(atom.getRootViewStateForPath(project.getPath())).toEqual + expect(atom.getRootViewStateForPath(projectPath)).toEqual project: projectState rootView: rootViewState @@ -106,7 +107,7 @@ describe "Window", -> editor2 = editor1.splitRight() expect(window.rootView.getEditors().length).toBe 2 - shutdown() + window.shutdown() expect(editor1.getBuffer().subscriptionCount()).toBe 0 diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 98800c830..721932fdf 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -59,7 +59,9 @@ afterEach -> if rootView? rootView.deactivate() window.rootView = null - project.destroy() + if project? + project.destroy() + window.project = null $('#jasmine-content').empty() ensureNoPathSubscriptions() waits(0) # yield to ui thread to make screen update more frequently diff --git a/src/app/window.coffee b/src/app/window.coffee index b181d4f0a..58547efb9 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -8,7 +8,6 @@ require 'underscore-extensions' require 'space-pen-extensions' deserializers = {} -wasShutdown = false windowAdditions = rootViewParentSelector: 'body' @@ -69,8 +68,7 @@ windowAdditions = $(rootViewParentSelector).append(rootView) shutdown: -> - return if wasShutdown - wasShutdown = true + return if not project and not rootView atom.setWindowState('pathToOpen', project.getPath()) atom.setRootViewStateForPath project.getPath(), project: project.serialize() @@ -78,6 +76,8 @@ windowAdditions = rootView.deactivate() project.destroy() $(window).off('focus blur before') + window.rootView = null + window.project = null stylesheetElementForId: (id) -> $("head style[id='#{id}']")