Skip to content

Commit

Permalink
added 'delete' as alias for 'remove'
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjunker committed May 6, 2012
1 parent 38494aa commit e39fcb1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
9 changes: 4 additions & 5 deletions domain/archivist/Archivist.agent.coffee
Expand Up @@ -5,11 +5,10 @@ remove = require './services/remove'

class Archivist
setArchive: (location) -> @archive = location
setStorageStrategy: (strategy) -> @strategy = strategy

create: (data) -> create(data, @archive, @strategy)
read: (id) -> read(id, @archive)
update: (id, newData) -> update(id, @archive, newData)
remove: (id) -> remove(id, @archive)
create: (data) -> create(data, @archive, @strategy)
read: (id) -> read(id, @archive)
update: (id, newData) -> update(id, @archive, newData)
remove: (id) -> remove(id, @archive)

module.exports = Archivist
12 changes: 7 additions & 5 deletions domain/archivist/models/Archive.coffee
Expand Up @@ -5,7 +5,6 @@ class Archive

create: (data) ->
newId = @generateId()
console.log newId
record = new Record(newId, data)
@storage.push(record)
return record
Expand All @@ -18,17 +17,20 @@ class Archive
toUpdate.setProperty(key, value) for key, value of data
return toUpdate

delete: (id) ->
@remove id

remove: (id) ->
toDelete = @find(id)
@storage.splice(toDelete.id-1, 1)
return toDelete

getSize: () -> @storage.length

generateId: () -> @getSize() + 1

find:(id) ->
result = record for record in @storage when record.id is id
return result

getSize: () -> @storage.length

generateId: () -> @getSize() + 1

module.exports = Archive
14 changes: 13 additions & 1 deletion domain/archivist/models/specs/Archive.spec.coffee
Expand Up @@ -42,6 +42,18 @@ describe 'Archive', ->
result.name.should.eql boogie.name
result.age.should.eql boogie.age
result.emotion.should.eql boogie.emotion
console.log archive.storage
newSize = archive.getSize()
newSize.should.eql 0

describe '#delete', ->
it 'should return the deleted record from a given id and delete it when the record exists', ->
boogie = createData()
archive = new Archive("Dog")
dog = archive.create(boogie)
result = archive.delete(1)
result.name.should.eql boogie.name
result.age.should.eql boogie.age
result.emotion.should.eql boogie.emotion
newSize = archive.getSize()
newSize.should.eql 0

1 change: 0 additions & 1 deletion domain/archivist/models/specs/Record.spec.coffee
Expand Up @@ -8,7 +8,6 @@ describe 'Record', ->
age: 26

result = new Record(0, data)
console.log result
result.id.should.eql 0
result.name.should.eql "Nick"
result.age.should.eql 26
Expand Down
7 changes: 0 additions & 7 deletions domain/archivist/services/specs/mocks/createData.coffee~

This file was deleted.

0 comments on commit e39fcb1

Please sign in to comment.