Fix magic numbers, extra param references
This commit is contained in:
parent
1833b43ae2
commit
808460a28f
|
@ -33,15 +33,15 @@ class Badge < ActiveRecord::Base
|
||||||
UserChange = 8
|
UserChange = 8
|
||||||
|
|
||||||
def self.is_none?(trigger)
|
def self.is_none?(trigger)
|
||||||
[0].include? trigger
|
[None].include? trigger
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.uses_user_ids?(trigger)
|
def self.uses_user_ids?(trigger)
|
||||||
[4, 8].include? trigger
|
[TrustLevelChange, UserChange].include? trigger
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.uses_post_ids?(trigger)
|
def self.uses_post_ids?(trigger)
|
||||||
[1, 2].include? trigger
|
[PostAction, PostRevision].include? trigger
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -139,9 +139,11 @@ class BadgeGranter
|
||||||
return unless sql.present?
|
return unless sql.present?
|
||||||
if Badge::Trigger.uses_post_ids?(opts[:trigger])
|
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 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
|
end
|
||||||
if Badge::Trigger.uses_user_ids?(opts[:trigger])
|
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 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
|
end
|
||||||
if opts[:trigger] && !Badge::Trigger.is_none?(opts[:trigger])
|
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/
|
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 New Issue