forked from zdavatz/yus
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed MockPersistence to handle rename correctly
- Loading branch information
Showing
2 changed files
with
11 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
class MockPersistence | ||
attr_reader :entities | ||
def initialize | ||
@objects = {} | ||
@entities = {} | ||
end | ||
def find_entity(name) | ||
@objects[name] | ||
@entities[name] | ||
end | ||
def add_entity(entity) | ||
@objects[entity.name] = entity | ||
@entities[entity.name] = entity | ||
entity | ||
end | ||
def delete_entity(name) | ||
@objects.delete(name) | ||
@entities.delete(name) | ||
end | ||
def save_entity(entity) | ||
@objects[entity.name] = entity | ||
end | ||
def entities | ||
@objects | ||
if(@entities[entity.name]) | ||
@entities[entity.name] = entity | ||
else | ||
@entities.delete_if { |name, ent| ent.name == entity.name } | ||
add_entity(entity) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters