Browse files

fixed a bug where annotations weren't accessible after the document i…

…s re-retrieved from the database; added tests
  • Loading branch information...
1 parent c7f1b47 commit e4f8bf2cd11dd334b0452c948cf535172613a6e3 @moonmaster9000 moonmaster9000 committed Jan 12, 2011
Showing with 22 additions and 3 deletions.
  1. +5 −1 features/milestones.feature
  2. +7 −0 features/step_definitions/milestone_steps.rb
  3. +10 −2 lib/memories/base.rb
View
6 features/milestones.feature
@@ -4,11 +4,15 @@ Feature: Marking versions as milestones
Given I have a document
When I mark that document as a milestone
Then that revision should show up as the newest milestone
-
+
+ @focus
Scenario: Annotating a milestone
Given I have a document
When I mark that document as a milestone with an annotation
Then I should be able to retrieve that annotation from the milestone properties
+ When I re-retrieve that document from the database
+ Then I should be able to retrieve that annotation from the milestone properties
+
@focus
Scenario: Accessing the milestone version data
View
7 features/step_definitions/milestone_steps.rb
@@ -20,9 +20,16 @@
Then /^I should be able to retrieve that annotation from the milestone properties$/ do
@book.latest_milestone.annotations.name.should == "First Milestone!"
+ @book.milestones.last.annotations.name.should == "First Milestone!"
@book.latest_milestone.annotations.notes.should == "This milestone is the first milestone ever created!"
+ @book.milestones.last.annotations.notes.should == "This milestone is the first milestone ever created!"
end
+When /^I re\-retrieve that document from the database$/ do
+ @book = Book.get @book.id
+end
+
+
Given /^I have a document with (\d+) milestones$/ do |num_milestones|
num_milestones = num_milestones.to_i
@book = Book.new
View
12 lib/memories/base.rb
@@ -3,7 +3,15 @@ module Memories
def self.included(base)
base.property(:milestone_memories) do |milestone_memory|
milestone_memory.property :version
- milestone_memory.property :annotations, Memories::Annotation
+ milestone_memory.property :annotations,
+ Memories::Annotation,
+ :init_method => proc { |value|
+ a = Memories::Annotation.new
+ value.keys.each do |key|
+ a.send key, value[key]
+ end
+ a
+ }
end
base.before_update :add_version_attachment
@@ -237,7 +245,7 @@ def versions
def milestone!(&block)
annotations = Memories::Annotation.new
annotations.instance_eval(&block) if block
- self.milestone_memories << {:version => self.rev, :annotations => annotations}
+ self.milestone_memories << {:version => self.rev, :annotations => annotations.to_hash}
self.save
end

0 comments on commit e4f8bf2

Please sign in to comment.