Skip to content

Commit

Permalink
🐛 Fix saveAs not changing the csv editor path
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Oct 6, 2015
1 parent 73445bb commit dbaf82b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/csv-editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,24 @@ class CSVEditor
@options ?= {}
@subscriptions = new CompositeDisposable
@emitter = new Emitter
@file = new File(filePath)
@previousPath = filePath
@subscribeToFile()
@setPath(filePath)

setPath: (filePath) ->
return if filePath is @getPath()

if filePath
@file = new File(filePath)
@previousPath = filePath
@subscribeToFile()
else
@file = null

@emitter.emit 'did-change-path', @getPath()
@emitter.emit 'did-change-title', @getTitle()

subscribeToFile: ->
@fileSubscriptions?.dispose()

@fileSubscriptions = new CompositeDisposable

changeFired = false
Expand Down Expand Up @@ -92,7 +105,7 @@ class CSVEditor
else
'untitled'

getPath: -> @file.getPath()
getPath: -> @file?.getPath()

getURI: -> @getPath()

Expand Down Expand Up @@ -177,6 +190,7 @@ class CSVEditor
options = _.clone(@options)
options.columns = @editor.getColumns() if options.header

@setPath(path)
@saveLayout()

csv.stringify @editor.getTable().getRows(), options, (err, data) =>
Expand Down
28 changes: 28 additions & 0 deletions spec/csv-editor-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,34 @@ describe "CSVEditor", ->
expect(tableEditorElement).toExist()
expect(csvEditorElement.children.length).toEqual(1)

describe '::saveAs', ->
newPath = null
beforeEach ->
newPath = "#{projectPath}/other-sample.csv"

waitsForPromise ->
csvEditor.saveAs(newPath)

it 'saves the csv at the specified path', ->
expect(fs.existsSync(newPath)).toBeTruthy()

it 'changes the csvEditor path', ->
expect(csvEditor.getPath()).toEqual(newPath)

it 'saves the layout and display settings at the new path', ->
expect(tableEditPackage.csvConfig.get(newPath, 'layout')).toEqual({
columns: [
{}
{}
{}
]
rowHeights: [
undefined
undefined
undefined
]
})

describe '::copy', ->
it 'returns a CSVEditor in a pending state', ->
copy = csvEditor.copy()
Expand Down

0 comments on commit dbaf82b

Please sign in to comment.