test/models/snapshot_test.rb in active_snapshot-0.2.4 vs test/models/snapshot_test.rb in active_snapshot-0.3.0

- old
+ new

@@ -43,11 +43,11 @@ instance = @snapshot_klass.new instance.valid? - [:item_id, :item_type, :identifier].each do |attr| + [:item_id, :item_type].each do |attr| assert instance.errors[attr].present? ### presence error end instance = @snapshot_klass.new(item: snapshot.item, identifier: snapshot.identifier) @@ -61,15 +61,15 @@ end def test_metadata @snapshot = @snapshot_klass.first - assert @snapshot.metadata.is_a?(HashWithIndifferentAccess) + assert @snapshot.metadata.is_a?(Hash) @snapshot.metadata = {foo: :bar} - assert_equal :bar, @snapshot.metadata['foo'] + assert_equal "bar", @snapshot.metadata['foo'] end def test_build_snapshot_item @snapshot = @snapshot_klass.first @@ -99,20 +99,20 @@ assert reified_items.first.readonly? children_hash = reified_items.last - assert children_hash.is_a?(HashWithIndifferentAccess) + assert children_hash.is_a?(Hash) assert children_hash.all?{|k,v| v.all?{|x| x.readonly?} } end def test_fetch_reified_items_with_sti_class post = SubPost.create!(a: 1, b: 2) comment_content = 'Example comment' post.comments.create!(content: comment_content) - post.create_snapshot!('v1') + post.create_snapshot!(identifier: 'v1') snapshot = post.snapshots.first reified_items = snapshot.fetch_reified_items assert_equal post, reified_items.first assert reified_items.first.readonly? @@ -120,21 +120,29 @@ end def test_single_model_snapshots_without_children instance = ParentWithoutChildren.create!({a: 1, b: 2}) - previous_attributes = instance.attributes + prev_attrs = instance.attributes - instance.create_snapshot!('v1') + instance.create_snapshot!(identifier: 'v1') instance.update!(a: 9, b: 9) snapshot = instance.snapshots.first reified_items = snapshot.fetch_reified_items assert_equal [instance, {}], reified_items - assert_equal previous_attributes, reified_items.first.attributes + new_attrs = reified_items.first.attributes + + prev_time_attrs = prev_attrs.extract!("created_at","updated_at") + new_time_attrs = new_attrs.extract!("created_at","updated_at") + + assert_equal new_time_attrs.values.map{|x| x.round(3)}, new_time_attrs.values + + ### rounding to 3 sometimes fails due to millisecond precision so we just test for 2 decimal places here + assert_equal prev_time_attrs.values.map{|x| x.round(2)}, new_time_attrs.values.map{|x| x.round(2)} end end