Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Conversation

@fzngagan
Copy link
Contributor

@fzngagan fzngagan commented Apr 11, 2022

The voting plugin's category setting is broken per https://meta.discourse.org/t/223880 and https://meta.discourse.org/t/223753

This PR fixes the reported issue.

Earlier the code was checking params[:custom_fields].delete(:enable_topic_voting) == "true" which assumes we'll get a "true" string but we don't. This value is populated from
https://github.com/discourse/discourse-voting/blob/3d9f4c2996c98cca33380981fbac14bdcc702006/assets/javascripts/discourse/templates/connectors/category-custom-settings/feature-voting-settings.hbs#L5
and the controller converts this to a ruby boolean and hence the condition fails.

@jjaffeux
Copy link
Contributor

What was broken before this?
Can you explain it in the PR for history or even better write a test please?

custom_fields: { "enable_topic_voting" => true }
}
expect(Category.can_vote?(category.id)).to eq(true)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice nice, can you add a failing scenario please too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I think the failure should be with a simple false value. Reason being, we don't need to exercise ActiveRecord::Type::Boolean here right?

Copy link
Contributor

@nattsw nattsw Apr 11, 2022

Choose a reason for hiding this comment

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

Yup! Actually there's other cases where other custom_fields may exist after deleting enable_topic_voting. But that's alright. I trust you clicked through the scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the following piece of code(with category_setting_attributes) should also be tested I agree. But I didn't test that coz it doesn't have to do anything with my fix. 😅

fab!(:admin) { Fabricate(:user, admin: true) }

before do
SiteSetting.voting_enabled = true
Copy link
Contributor

@nattsw nattsw Apr 11, 2022

Choose a reason for hiding this comment

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

Btw is this needed? (I don't see it used above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed yes. Category.can_vote? will be false if the plugin is disabled.

Copy link
Contributor

@nattsw nattsw left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@fzngagan fzngagan merged commit 1da6677 into main Apr 11, 2022
@fzngagan fzngagan deleted the fix-enabled-setting branch April 11, 2022 12:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants