From 40426a5af4fb565097ca785abf8fa9c07696c174 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 24 Oct 2013 19:15:25 -0300 Subject: [PATCH] spammable: fail safe measures --- lib/spammable.rb | 9 ++++++--- plugins/anti_spam/test/unit/anti_spam_plugin_test.rb | 2 -- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/spammable.rb b/lib/spammable.rb index 9b322d5..bbf1623 100644 --- a/lib/spammable.rb +++ b/lib/spammable.rb @@ -1,13 +1,16 @@ module Spammable def self.included(recipient) + raise "This model should have a spam attribute!" if !recipient.new.respond_to?('spam=') recipient.extend(ClassMethods) end module ClassMethods def self.extended (base) - base.class_eval do - named_scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] - named_scope :spam, :conditions => ['spam = ?', true] + if base.respond_to?(:named_scope) + base.class_eval do + named_scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] + named_scope :spam, :conditions => ['spam = ?', true] + end end end end diff --git a/plugins/anti_spam/test/unit/anti_spam_plugin_test.rb b/plugins/anti_spam/test/unit/anti_spam_plugin_test.rb index 6cb88e4..0101578 100644 --- a/plugins/anti_spam/test/unit/anti_spam_plugin_test.rb +++ b/plugins/anti_spam/test/unit/anti_spam_plugin_test.rb @@ -4,8 +4,6 @@ class AntiSpamPluginTest < ActiveSupport::TestCase class SpammableContent attr_accessor :spam - def self.named_scope(*args); end - include Spammable def save!; end -- libgit2 0.21.2