Sha256: 0781daf8d1829d485a48887b342ce5d7ae60610c5b51de0a0b9b138aa32313f8
Contents?: true
Size: 1.83 KB
Versions: 3
Compression:
Stored size: 1.83 KB
Contents
require 'spec_helper' describe Mongoid::History::Tracker do before :all do class Model include Mongoid::Document include Mongoid::History::Trackable field :name, type: String belongs_to :user, inverse_of: :models has_and_belongs_to_many :external_users, class_name: "User", inverse_of: :external_models track_history on: [:name, :user, :external_user_ids], # track title and body fields only, default is :all modifier_field: :modifier, # adds "referenced_in :modifier" to track who made the change, default is :modifier modifier_field_inverse_of: nil, # no inverse modifier relationship version_field: :version, # adds "field :version, :type => Integer" to track current version, default is :version track_create: false, # track document creation, default is false track_update: true, # track document updates, default is true track_destroy: false # track document destruction, default is false end class User include Mongoid::Document has_many :models, dependent: :destroy, inverse_of: :user has_and_belongs_to_many :external_model, class_name: "Model", inverse_of: :external_users end end it "should be possible to undo when having multiple relations to modifier class" do user = User.new user.save model = Model.new model.name = "Foo" model.user = user model.save! model.name = "Bar" model.save! model.undo! user model.name.should == "Foo" model.redo! user, 1 model.name.should == "Bar" end it "should track foreign key relations" do Model.tracked_field?(:external_user_ids).should be true Model.tracked_field?(:user).should be true Model.tracked_field?(:user_id).should be true end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mongoid-history-0.4.4 | spec/integration/multi_relation_spec.rb |
mongoid-history-0.4.3 | spec/integration/multi_relation_spec.rb |
mongoid-history-0.4.2 | spec/integration/multi_relation_spec.rb |