From 6bdba313d18f7b04b134bd20c21be0bcd2444e14 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 15 Mar 2012 16:10:55 -0600 Subject: [PATCH] Don't add to the same window to the atom.windows array twice --- spec/atom/app-spec.coffee | 29 +++++++++++++++++++++++++---- src/atom/app.coffee | 10 +--------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/spec/atom/app-spec.coffee b/spec/atom/app-spec.coffee index 619273deb..b438293f6 100644 --- a/spec/atom/app-spec.coffee +++ b/spec/atom/app-spec.coffee @@ -2,13 +2,20 @@ App = require 'app' fs = require 'fs' describe "App", -> - afterEach -> + closeAllWindows = -> window.close() for window in atom.windows waitsFor "there to be no windows", -> atom.windows.length == 0 - describe "open", -> - describe "when opening a filePath", -> + + describe ".open(path)", -> + beforeEach -> + closeAllWindows() + + afterEach -> + closeAllWindows() + + describe "when opening a file", -> it "displays it in a new window with the contents of the file loaded", -> filePath = null @@ -18,10 +25,24 @@ describe "App", -> atom.open filePath waitsFor "window to open", -> - atom.windows.length > 0 + atom.windows.length > 0 runs -> expect(atom.windows.length).toBe 1 newWindow = atom.windows[0] expect(newWindow.rootView.editor.buffer.url).toEqual filePath expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath) + + describe ".windowOpened(window)", -> + app = null + + beforeEach -> + app = new App + + it "adds the window to the windows array if it isn't already present", -> + app.windowOpened window + app.windowOpened window + expect(app.windows).toEqual [window] + + + diff --git a/src/atom/app.coffee b/src/atom/app.coffee index a48737df9..c4db24831 100644 --- a/src/atom/app.coffee +++ b/src/atom/app.coffee @@ -25,16 +25,8 @@ class App quit: -> $native.terminate null - windowIdCounter: 1 - windowOpened: (window) -> - id = @windowIdCounter++ - console.log "window opened! #{id}" - window.id = id - @windows.push window + @windows.push(window) unless _.contains(@windows, window) windowClosed: (window) -> - console.log "windowClosed #{window.id}" - console.log "windows length before #{@windows.length}" _.remove(@windows, window) - console.log "windows length after #{@windows.length}"