forked from mongoid/mongoid-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnested_embedded_documents_tracked_in_parent_spec.rb
49 lines (39 loc) · 1.23 KB
/
nested_embedded_documents_tracked_in_parent_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'spec_helper'
describe Mongoid::History::Tracker do
before :all do
class Child
include Mongoid::Document
include Mongoid::History::Trackable
field :name
embedded_in :parent, inverse_of: :child
end
class Parent
include Mongoid::Document
include Mongoid::History::Trackable
field :name, type: String
embeds_one :child
track_history on: [:fields, :embedded_relations],
version_field: :version,
track_create: true,
track_update: true,
track_destroy: false
end
end
it 'should be able to track history for nested embedded documents in parent' do
p = Parent.new(name: 'bowser')
p.child = Child.new(name: 'todd')
p.save!
expect(p.history_tracks.length).to eq(1)
change = p.history_tracks.last
expect(change.modified['name']).to eq('bowser')
expect(change.modified['child']['name']).to eq('todd')
p.child.name = 'mario'
p.save!
expect(p.history_tracks.length).to eq(2)
expect(p.history_tracks.last.modified['child']['name']).to eq('mario')
end
after :all do
Object.send(:remove_const, :Parent)
Object.send(:remove_const, :Child)
end
end