DEV: Stop polluting all Ruby classes

The `ReviewableScore` model was defining class methods on `self.class`
from a singleton context so instead of defining methods on
`ReviewableScore` it was defining them on `Class`, so basically on every
existing class.

This patch resolves this issue. Using `enum` from `ActiveRecord` in the
future will avoid this kind of problems.
This commit is contained in:
Loïc Guitaut 2021-12-08 11:03:42 +01:00 committed by Loïc Guitaut
parent 3c5b1faab4
commit 74387e83b6
1 changed files with 1 additions and 1 deletions

View File

@ -49,7 +49,7 @@ class ReviewableScore < ActiveRecord::Base
# Generate `pending?`, `rejected?`, etc helper methods
statuses.each do |name, id|
define_method("#{name}?") { status == id }
self.class.define_method(name) { where(status: id) }
singleton_class.define_method(name) { where(status: id) }
end
def score_type