Skip to content

Commit

Permalink
Add integregation spect to test mongoid#187
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateus Pontes committed Apr 12, 2017
1 parent 1ce4549 commit 4b2c393
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

describe Mongoid::History::Tracker, focus: true do
before :all do
# Child model (will be embedded in Parent)
class Child
include Mongoid::Document
include Mongoid::History::Trackable

field :name
embedded_in :parent, inverse_of: :child
end

# Parent model (embeds one Child)
class Parent
include Mongoid::Document
include Mongoid::History::Trackable

field :name, type: String
embeds_one :child

track_history on: %i[(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

0 comments on commit 4b2c393

Please sign in to comment.