Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when using multiple trackers. #196

Merged
merged 1 commit into from
Nov 1, 2017
Merged

Fix bug when using multiple trackers. #196

merged 1 commit into from
Nov 1, 2017

Conversation

ojbucao
Copy link
Collaborator

@ojbucao ojbucao commented Oct 20, 2017

Problem: when using multiple trackers for different classes, the history gets mixed up between the different trackers.

Solution: remove the line on tracker.rb that sets the global history tracker everytime a tracker is loaded.

@dblock
Copy link
Collaborator

dblock commented Oct 22, 2017

Looks legit. Need to fix the build, changelog, etc., maybe document what happens with multiple trackers?

CHANGELOG.md Outdated
@@ -1,6 +1,6 @@
### 0.6.2 (Next)

* Your contribution here.
* Fix bug when using multiple trackers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe the actual bug. Conform to other lines. Put back the contributing message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. thanks.

@@ -18,8 +18,6 @@ module Tracker

index(scope: 1)
index(association_chain: 1)

Mongoid::History.tracker_class_name = name.tableize.singularize.to_sym
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is anything changing for existing users because of this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this line was originally there so that you don't have to configure a default tracker. It would dynamically set the loaded tracker as default. When multiple trackers got supported, this line no longer works as expected.

So i'm guessing the ones that will be affected are the ones that don't have a default tracker configured and do not have a tracker class set in the trackable options.

@coveralls
Copy link

coveralls commented Oct 31, 2017

Coverage Status

Coverage increased (+0.003%) to 99.752% when pulling 52cf994 on biola:fix-multiple-trackers into 439c0e1 on mongoid:master.

Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is good, a couple of must haves still remain. Thanks for hanging in here!

CHANGELOG.md Outdated

* Your contribution here.

### 0.6.2 (2017/10/31)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't released, put this back, we update it when releasing, separately.


If you are using multiple trackers and the `tracker_class_name` parameter is
not specified, Mongoid::History will use the default tracker configured in the
initializer file or whatever the first tracker was loaded.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this is saying that the first tracker loaded is going to be load-order dependent. That's not what's happening here, no? What's the default tracker?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went by what the original readme said: "Mongoid::History will use the first loaded class to include Mongoid::History::Tracker as the default history tracker"

That's if there's no initializer. It looks to me that line 22 in tracker.rb would just set it to whatever gets loaded first.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Lets leave it as is and maybe open an issue about that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah maybe the default tracker shouldn't be optional but should be a required in the configuration.

before :all do
Mongoid::History.tracker_class_name = nil

class First
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, these are global classes despite what you may think. I would put them into a module like module MultipleHistoryTrackersSpec to make sure there's no conflict, and make sure to fix up anything in other specs the same way as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh i see. Yeah I was having conflict when I was using Foo. I'll do what you're suggesting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I did what you've asked but the tracker classes can't be put in a module as there's no way to specify the module when passing a tracker_class to #track_history. I still moved the trackables into their own modules though.

I also tried doing the same thing for the other specs but even that wasn't working because those specs are using a modifier and there's no way to specify a module in the modifier.

I think we should leave in a separate issue since I don't have time right now to work on these. Let me know if you want me to revert the changes to the spec that I've added.

@coveralls
Copy link

coveralls commented Oct 31, 2017

Coverage Status

Coverage increased (+0.003%) to 99.752% when pulling 51f3216 on biola:fix-multiple-trackers into 439c0e1 on mongoid:master.

@dblock
Copy link
Collaborator

dblock commented Oct 31, 2017

Thanks for changing the specs. Open an issue for the module limitations, seems like something we should fix.

You still have to change CHANGELOG here not to say 0.6.3, you're not releasing with this PR.

Problem: when using multiple trackers for different classes, the history gets mixed up between the different trackers.

Solution: only set Mongoid::History.tracker_class_name if it's not nil.
@coveralls
Copy link

coveralls commented Oct 31, 2017

Coverage Status

Coverage increased (+0.003%) to 99.752% when pulling cd7565b on biola:fix-multiple-trackers into 439c0e1 on mongoid:master.

@dblock dblock merged commit 5cf3cd1 into mongoid:master Nov 1, 2017
@ojbucao ojbucao deleted the fix-multiple-trackers branch November 1, 2017 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants