Open
Description
it "should allow an alternate method to be specified on object creation" do
class CustomTracker < MyModel
field :key
track_history on: :key, changes_method: :my_changes, track_create: true, track_update: true
def my_changes
changes.merge(key: "Save history-#{key}")
end
end
m = CustomTracker.create(key: "on object creation")
history_track = m.history_tracks.last
expect(history_track.modified[:key]).to eq("Save history-on object creation")
p history_track.inspect
m.update_attributes(key: "object updated")
history_track = m.history_tracks.last
p history_track.inspect
end
The above spec yields following output:
History Tracker on creation:
#<Tracker _id: 5783a04ac5f169421e5905f9, created_at: 2016-07-11 13:34:02 UTC, updated_at: 2016-07-11 13:34:02 UTC, association_chain: [{\"name\"=>\"CustomTracker\", \"id\"=>BSON::ObjectId('5783a04ac5f169421e5905fa')}], modified: {\"key\"=>\"Save history-on object creation\"}, original: {}, version: 1, action: \"create\", scope: \"my_model\", modifier_id: nil>
History Tracker on updation:
"#<Tracker _id: 5783a04ac5f169421e5905fb, created_at: 2016-07-11 13:34:02 UTC, updated_at: 2016-07-11 13:34:02 UTC, association_chain: [{\"name\"=>\"CustomTracker\", \"id\"=>BSON::ObjectId('5783a04ac5f169421e5905fa')}], modified: {}, original: {\"key\"=>\"Save history-object updated\"}, version: 2, action: \"update\", scope: \"my_model\", modifier_id: nil>"
Updation history trackers inserts with empty modified
value. Actually it shouldn't empty.