public
Description: Easy Akismet integration for your Rails app
Clone URL: git://github.com/jfrench/rakismet.git
Support arbitrary attribute mappings
jfrench (author)
Tue Jul 01 18:35:56 -0700 2008
commit  57a3a7a37ebf8fe49b0673bbaa54cbe90ae4e652
tree    01ddadcab5be4e5d71d4a8d649025f8d22e21aa6
parent  742f64f2f55a4909fa905ea9341f3825b52c40ff
...
16
17
18
19
 
20
21
22
 
 
 
 
23
24
25
...
16
17
18
 
19
20
21
 
22
23
24
25
26
27
28
0
@@ -16,10 +16,13 @@ module Rakismet
0
         [:comment_type, :author, :author_url, :author_email, :content].each do |field|
0
            # clunky, but throwing around +type+ will break your heart
0
            fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
0
- self.akismet_attrs[fieldname] = args[field] || field
0
+ self.akismet_attrs[fieldname] = args.delete(field) || field
0
         end
0
         [:user_ip, :user_agent, :referrer].each do |field|
0
- self.akismet_attrs[field] = (args[field] || field) if args.has_key?(field) or self.public_instance_methods.include?(field.to_s)
0
+ self.akismet_attrs[field] = (args.delete(field) || field) if args.has_key?(field) or self.public_instance_methods.include?(field.to_s)
0
+ end
0
+ args.each_pair do |f,v|
0
+ self.akismet_attrs[f] = v
0
         end
0
       end
0
     end
...
23
24
25
26
 
27
28
29
...
43
44
45
46
 
47
48
49
...
96
97
98
 
 
 
 
 
 
 
 
 
 
99
100
101
...
23
24
25
 
26
27
28
29
...
43
44
45
 
46
47
48
49
...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
0
@@ -23,7 +23,7 @@ describe AkismetModel do
0
   mapped_params = { :comment_type => :type2, :author => :author2, :content => :content2,
0
                     :author_email => :author_email2, :author_url => :author_url2 }
0
     
0
- describe override = AkismetModel.subclass('Override') { has_rakismet(mapped_params) } do
0
+ describe override = AkismetModel.subclass('Override') { has_rakismet(mapped_params.dup) } do
0
     it "should override default mappings" do
0
       [:comment_type, :author, :author_url, :author_email, :content].each do |field|
0
         fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
0
@@ -43,7 +43,7 @@ describe AkismetModel do
0
   extended_params = { :user_ip => :stored_ip, :user_agent => :stored_agent,
0
                       :referrer => :stored_referrer }
0
                       
0
- describe extended = AkismetModel.subclass('Extended') { has_rakismet(extended_params) } do
0
+ describe extended = AkismetModel.subclass('Extended') { has_rakismet(extended_params.dup) } do
0
     
0
     before do
0
       @extended = extended.new
0
@@ -96,6 +96,16 @@ describe AkismetModel do
0
     end
0
   end
0
 
0
+ extra_params = { :extra => :extra, :another => lambda { } }
0
+
0
+ describe extra = AkismetModel.subclass('ExtraParams') { has_rakismet(extra_params.dup) } do
0
+ it "should map additional attributes" do
0
+ [:extra, :another].each do |field|
0
+ extra.akismet_attrs[field].should eql(extra_params[field])
0
+ end
0
+ end
0
+ end
0
+
0
   describe ".spam?" do
0
     
0
     before do

Comments

    No one has commented yet.