Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test persistence more thoroughly, pass tests

  • Loading branch information...
commit ea41038a4c5cc0601be4d0c56b29b882f7422903 1 parent 8904790
@bkerley authored
Showing with 20 additions and 10 deletions.
  1. +16 −6 lib/hanover/persistence.rb
  2. +4 −4 test/persistence_test.rb
View
22 lib/hanover/persistence.rb
@@ -22,8 +22,9 @@ def method_missing(name, *args, &block)
def initialize_from_key(key)
@key = key
@robject = bucket.get key
- @klass = Hanover.const_get(@robject.data['type'])
- @content = @klass.from_json @robject.raw_data
+
+ get_klass
+ @content = @klass.new
perform_merges
end
@@ -65,10 +66,19 @@ def create
end
def perform_merges
- @content.merge @klass.from_json @robject.raw_data
- return unless @robject.conflict?
-
- @robject.siblings.each {|s| @content.merge @klass.from_json s.raw_data }
+ if @robject.conflict?
+ @robject.siblings.each {|s| @content.merge @klass.from_json s.raw_data }
+ else
+ @content.merge @klass.from_json @robject.raw_data
+ end
+ end
+
+ def get_klass
+ if @robject.conflict?
+ @klass = Hanover.const_get @robject.siblings.first.data['type']
+ else
+ @klass = Hanover.const_get @robject.data['type']
+ end
end
def bucket
View
8 test/persistence_test.rb
@@ -40,13 +40,13 @@ class PersistenceTest < HanoverCase
subject.add 'alpha'
other.add 'bravo'
subject.reload
- other.reload
+
+ third = Persistence.find subject.key
assert_includes subject, 'alpha'
assert_includes subject, 'bravo'
- assert_includes other, 'alpha'
- assert_includes other, 'bravo'
+ assert_includes third, 'alpha'
+ assert_includes third, 'bravo'
end
- should 'save after add'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.