From 808460a28f52f972c239a1f3030630959ec55075 Mon Sep 17 00:00:00 2001 From: riking Date: Sun, 31 Aug 2014 19:36:31 -0700 Subject: [PATCH] Fix magic numbers, extra param references --- app/models/badge.rb | 6 +++--- app/services/badge_granter.rb | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/badge.rb b/app/models/badge.rb index a31580231..ad776da3f 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 46155e79c..143780aeb 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/