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: release/reclaim votes on moving topics to different category #34

Merged
merged 3 commits into from
Aug 15, 2018
Merged

FIX: release/reclaim votes on moving topics to different category #34

merged 3 commits into from
Aug 15, 2018

Conversation

OsamaSayegh
Copy link
Member

No description provided.


it "enqueus a job to reclaim votes if voting is enabled for the new category" do
PostRevisor.new(post1).revise!(admin, category_id: category1.id)
expect(Jobs::VoteReclaim.jobs.first["args"].first["topic_id"]).to eq(post1.reload.topic_id)
Copy link
Member

Choose a reason for hiding this comment

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

A problem with this style of test is that it does not properly test if the thing works, the job may fire and crash for all you know... the better way is just to test that votes actually get reclaimed.

Can you change that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, let me what you think :D

plugin.rb Outdated
@@ -274,6 +274,17 @@ def execute(args)
end
end

DiscourseEvent.on(:post_edited) do |post, topic_changed|
if topic_changed && SiteSetting.voting_enabled
Copy link
Member

Choose a reason for hiding this comment

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

before queuing the job can you do quick check on the topic to see if it has more than 0 votes?

also I guess this leave a whole around bulk actions, does that fire a post edited? (select multiple topics from web and then change category)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I've made it so that it doesn't enqueue a job unless there are votes to release or reclaim.

And yes this event doesn't trigger when moving topics in bulk because we don't use PostRevisor there. Should I simply trigger the event or make bulk actions user PostRevisor?

@@ -274,6 +274,17 @@ def execute(args)
end
end

DiscourseEvent.on(:post_edited) do |post, topic_changed|
if topic_changed && SiteSetting.voting_enabled && UserCustomField.where(value: post.topic_id).where("name = 'votes_archive' OR name = 'votes'").exists?
Copy link
Member

@SamSaffron SamSaffron Aug 15, 2018

Choose a reason for hiding this comment

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

.where("value = ? AND name in ('votes', 'votes_archive')", post.topic_id)

we should do a follow up PR to introduce a const for "votes" and "votes_archive" cause it is somewhat not nice

@SamSaffron SamSaffron merged commit 0707811 into discourse:master Aug 15, 2018
spajus pushed a commit to webgroup-limited/discourse-voting that referenced this pull request May 15, 2019
…scourse#34)

* FIX: release/reclaim votes on moving topics to different category

* test jobs

* don't enqueue job if there are no votes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants