mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
Fix magic numbers, extra param references
This commit is contained in:
parent
1833b43ae2
commit
808460a28f
2 changed files with 5 additions and 3 deletions
|
@ -33,15 +33,15 @@ class Badge < ActiveRecord::Base
|
|||
UserChange = 8
|
||||
|
||||
def self.is_none?(trigger)
|
||||
[0].include? trigger
|
||||
[None].include? trigger
|
||||
end
|
||||
|
||||
def self.uses_user_ids?(trigger)
|
||||
[4, 8].include? trigger
|
||||
[TrustLevelChange, UserChange].include? trigger
|
||||
end
|
||||
|
||||
def self.uses_post_ids?(trigger)
|
||||
[1, 2].include? trigger
|
||||
[PostAction, PostRevision].include? trigger
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -139,9 +139,11 @@ class BadgeGranter
|
|||
return unless sql.present?
|
||||
if Badge::Trigger.uses_post_ids?(opts[:trigger])
|
||||
raise "Contract violation:\nQuery triggers on posts, but does not reference the ':post_ids' array" unless sql.match /:post_ids/
|
||||
raise "Contract violation:\nQuery triggers on posts, but references the ':user_ids' array" if sql.match /:user_ids/
|
||||
end
|
||||
if Badge::Trigger.uses_user_ids?(opts[:trigger])
|
||||
raise "Contract violation:\nQuery triggers on users, but does not reference the ':user_ids' array" unless sql.match /:user_ids/
|
||||
raise "Contract violation:\nQuery triggers on users, but references the ':post_ids' array" if sql.match /:post_ids/
|
||||
end
|
||||
if opts[:trigger] && !Badge::Trigger.is_none?(opts[:trigger])
|
||||
raise "Contract violation:\nQuery is triggered, but does not reference the ':backfill' parameter.\n(Hint: if :backfill is TRUE, you should ignore the :post_ids/:user_ids)" unless sql.match /:backfill/
|
||||
|
|
Loading…
Reference in a new issue