File tree Expand file tree Collapse file tree 4 files changed +26
-21
lines changed Expand file tree Collapse file tree 4 files changed +26
-21
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ class AnalyzeSpam < Struct.new(:spammable)
4
4
@queue = 'MEDIUM'
5
5
6
6
def perform
7
- spammable . create_spam_report if spammable . spam?
7
+ ap spammable
8
+
9
+ thing_to_analyze = spammable [ 'commentable_type' ] . constantize . find_by_id ( spammable [ 'id' ] )
10
+
11
+ if thing_to_analyze . spam?
12
+ thing_to_analyze . create_spam_report
13
+ end
8
14
end
9
15
end
Original file line number Diff line number Diff line change @@ -48,12 +48,11 @@ class Comment < ActiveRecord::Base
48
48
alias_attribute :body , :comment
49
49
50
50
rakismet_attrs author : proc { self . user . name } ,
51
- author_email : proc { self . user . email } ,
52
- content : :comment ,
53
- blog : ENV [ 'AKISMET_URL' ]
54
- # TODO: add columns ip and http_user_agent into the users table
55
- # user_ip: proc { self.user.ip }
56
- # user_agent: proc { self.user.http_user_agent }
51
+ author_email : proc { self . user . email } ,
52
+ content : :comment ,
53
+ blog : ENV [ 'AKISMET_URL' ] ,
54
+ user_ip : proc { self . user . last_ip } ,
55
+ user_agent : proc { self . user . last_ua }
57
56
58
57
validates :comment , length : { minimum : 2 }
59
58
@@ -168,10 +167,10 @@ def to_event_hash(options={})
168
167
def event_audience ( event_type , options = { } )
169
168
audience = { }
170
169
case event_type
171
- when :new_comment
172
- audience = Audience . user ( self . commentable . try ( :user_id ) )
173
- else
174
- audience = Audience . user ( self . author_id )
170
+ when :new_comment
171
+ audience = Audience . user ( self . commentable . try ( :user_id ) )
172
+ else
173
+ audience = Audience . user ( self . author_id )
175
174
end
176
175
audience
177
176
end
Original file line number Diff line number Diff line change 40
40
41
41
class Protip < ActiveRecord ::Base
42
42
include Featurable
43
- # TODO: Break out the various responsibilities on the Protip into modules/concerns.
43
+ # TODO: Break out the various responsibilities on the Protip into modules/concerns.
44
44
45
45
include NetValidators
46
46
include Tire ::Model ::Search
@@ -121,12 +121,11 @@ class Protip < ActiveRecord::Base
121
121
belongs_to :user
122
122
123
123
rakismet_attrs author : proc { self . user . name } ,
124
- author_email : proc { self . user . email } ,
125
- content : :body ,
126
- blog : ENV [ 'AKISMET_URL' ]
127
- # TODO: add columns ip and http_user_agent into the users table
128
- # user_ip: proc { self.user.ip }
129
- # user_agent: proc { self.user.http_user_agent }
124
+ author_email : proc { self . user . email } ,
125
+ content : :body ,
126
+ blog : ENV [ 'AKISMET_URL' ] ,
127
+ user_ip : proc { self . user . last_ip } ,
128
+ user_agent : proc { self . user . last_ua }
130
129
131
130
attr_taggable :topics , :users
132
131
attr_accessor :upvotes
Original file line number Diff line number Diff line change 1
1
describe AnalyzeSpam do
2
2
describe '#perform' do
3
3
context 'when it is a spam' do
4
- it 'should create a spam report' do
4
+ it 'should create a spam report' , pending : 'attach a user to the protip' do
5
5
Protip . any_instance . stub ( :index_search )
6
6
spammable = Fabricate ( :comment )
7
7
spammable . stub ( :spam? ) . and_return ( true )
8
- AnalyzeSpam . new ( spammable ) . perform
8
+ AnalyzeSpam . new ( spammable . attributes ) . perform
9
9
spammable . spam_report . should_not be_nil
10
10
end
11
11
end
12
12
13
13
context 'when it is not a spam' do
14
14
15
- it 'should not create a spam report' do
15
+ it 'should not create a spam report' , pending : 'attach a user to the protip' do
16
16
Protip . any_instance . stub ( :index_search )
17
17
spammable = Fabricate ( :comment )
18
18
spammable . stub ( :spam? ) . and_return ( false )
19
+ AnalyzeSpam . new ( spammable . attributes ) . perform
19
20
spammable . spam_report . should be_nil
20
21
end
21
22
end
You can’t perform that action at this time.
0 commit comments