The issue was that when we were moving the post using posts[1,2]
the ordering was not always consistent, so sometimes we moved post
number 1 for the topic and sometimes post number 2.
If post number 1 was moved, the PostMover just creates a copy of it
in the destination topic, as the OP of the topic cannot be moved.
If post number 2 was moved, then PostMover _actually_ moves it to
the destination topic, and thus leaves only one post behind in
the original topic, which causes the original topic to be closed
and makes the spec fail.
This change ensures that post number 1 is the one we are moving
in the test, making sure the order is constant.
Was able to reproduce a bug where votes were not properly moved when merging two topics together. We were only checking duplicate votes if either both votes were either active or archived, and not a mix of the two. As a result, there were cases where the plugin was trying to move votes that already existed on an open topic, causing the merge to partially fail with a duplicate index error.
What this commit does is as follows:
- Cleaned up the logic so it's more readable. Previously it was duplicative and difficult to read.
- We're now checking if a user has a vote on Topic A (active or archived) and Topic B (active or archived) that we're properly deleting the origin vote and keeping the destination vote instead of trying to merge in a duplicate. (This caused the original bug described above).
- Per the specs on meta, topic merges move all votes to the destination topic, and if this causes a user to go over the limit, they'll have to wait until enough votes are released.
- If the destination topic is closed, the votes will be archived; if the destination topic is open, those votes will be active. This is regardless of origin vote state.
Also, the Gemfile was missing a source declaration to allow installation of gems/dependencies, so I've added that.
We are trying to avoid custom tables. Changes:
CategoryCustomField -> DiscourseVoting::CategorySetting # contains infromation if voting is enabled for category
UserCustomField -> DiscourseVoting::Vote # user's votes
TopicCustomField -> DiscourseVoting::VoteCounter # cache count for topics
Merging two votes with topics will edit the moderator post describing
the move operation, to include information about how many votes were
moved and why some votes were not (because user already voted for the
destination topic).