diff --git a/app/models/badge.rb b/app/models/badge.rb index a31580231df..ad776da3f5a 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -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 diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb index 46155e79cea..143780aebe6 100644 --- a/app/services/badge_granter.rb +++ b/app/services/badge_granter.rb @@ -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/