Commit 40426a5af4fb565097ca785abf8fa9c07696c174
1 parent
52500266
Exists in
master
and in
29 other branches
spammable: fail safe measures
* Avoiding module inclusion on models that doesn't have a spam attribute. * Avoiding named_scope filters on models that doesn't have named_scope.
Showing
2 changed files
with
6 additions
and
5 deletions
Show diff stats
lib/spammable.rb
1 | 1 | module Spammable |
2 | 2 | def self.included(recipient) |
3 | + raise "This model should have a spam attribute!" if !recipient.new.respond_to?('spam=') | |
3 | 4 | recipient.extend(ClassMethods) |
4 | 5 | end |
5 | 6 | |
6 | 7 | module ClassMethods |
7 | 8 | def self.extended (base) |
8 | - base.class_eval do | |
9 | - named_scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] | |
10 | - named_scope :spam, :conditions => ['spam = ?', true] | |
9 | + if base.respond_to?(:named_scope) | |
10 | + base.class_eval do | |
11 | + named_scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] | |
12 | + named_scope :spam, :conditions => ['spam = ?', true] | |
13 | + end | |
11 | 14 | end |
12 | 15 | end |
13 | 16 | end | ... | ... |
plugins/anti_spam/test/unit/anti_spam_plugin_test.rb