Commit 46a07c2 1 parent ec6c90f commit 46a07c2 Copy full SHA for 46a07c2
File tree 7 files changed +53
-0
lines changed
7 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,15 @@ def logged_in_with_matching_email?
26
26
27
27
def akismet_attributes
28
28
name = username ? username : ""
29
+ # If the user is logged in and we're sending info to Akismet, we can assume
30
+ # the email does not match.
31
+ role = User . current_user . present? ? "user-with-nonmatching-email" : "guest"
29
32
{
30
33
comment_type : "contact-form" ,
31
34
key : ArchiveConfig . AKISMET_KEY ,
32
35
blog : ArchiveConfig . AKISMET_NAME ,
33
36
user_ip : ip_address ,
37
+ user_role : role ,
34
38
comment_author : name ,
35
39
comment_author_email : email ,
36
40
comment_content : comment
Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ def akismet_attributes
98
98
blog : ArchiveConfig . AKISMET_NAME ,
99
99
user_ip : ip_address ,
100
100
user_agent : user_agent ,
101
+ user_role : "guest" ,
101
102
comment_author : name ,
102
103
comment_author_email : email ,
103
104
comment_content : comment_content
Original file line number Diff line number Diff line change @@ -23,11 +23,16 @@ def logged_in_with_matching_email?
23
23
end
24
24
25
25
def akismet_attributes
26
+ # If the user is logged in and we're sending info to Akismet, we can assume
27
+ # the email does not match.
28
+ role = User . current_user . present? ? "user-with-nonmatching-email" : "guest"
26
29
{
30
+ comment_type : "contact-form" ,
27
31
key : ArchiveConfig . AKISMET_KEY ,
28
32
blog : ArchiveConfig . AKISMET_NAME ,
29
33
user_ip : ip_address ,
30
34
user_agent : user_agent ,
35
+ user_role : role ,
31
36
comment_author_email : email ,
32
37
comment_content : comment
33
38
}
Original file line number Diff line number Diff line change @@ -1098,6 +1098,7 @@ def akismet_attributes
1098
1098
key : ArchiveConfig . AKISMET_KEY ,
1099
1099
blog : ArchiveConfig . AKISMET_NAME ,
1100
1100
user_ip : ip_address ,
1101
+ user_role : "user" ,
1101
1102
comment_date_gmt : created_at . to_time . iso8601 ,
1102
1103
blog_lang : language . short ,
1103
1104
comment_author : user . login ,
Original file line number Diff line number Diff line change 353
353
end
354
354
end
355
355
356
+ context "when report is submitted to Akismet" do
357
+ let ( :report ) { build ( :abuse_report ) }
358
+
359
+ it "has comment_type \" contact-form\" " do
360
+ expect ( report . akismet_attributes [ :comment_type ] ) . to eq ( "contact-form" )
361
+ end
362
+
363
+ it "has user_role \" user-with-nonmatching-email\" when reporter is logged in" do
364
+ User . current_user = create ( :user )
365
+ expect ( report . akismet_attributes [ :user_role ] ) . to eq ( "user-with-nonmatching-email" )
366
+ end
367
+
368
+ it "has user_role \" guest\" when reporter is logged out" do
369
+ expect ( report . akismet_attributes [ :user_role ] ) . to eq ( "guest" )
370
+ end
371
+ end
372
+
356
373
describe "#attach_work_download" do
357
374
include ActiveJob ::TestHelper
358
375
Original file line number Diff line number Diff line change 28
28
. to raise_error ( ActiveRecord ::RecordNotFound )
29
29
end
30
30
end
31
+
32
+ context "when submitting comment to Akismet" do
33
+ subject { build ( :comment ) }
34
+
35
+ it "has user_role \" guest\" " do
36
+ expect ( subject . akismet_attributes [ :user_role ] ) . to eq ( "guest" )
37
+ end
38
+ end
31
39
end
32
40
33
41
context "with an existing comment from the same user" do
Original file line number Diff line number Diff line change 83
83
expect ( safe_report . save ) . to be_truthy
84
84
end
85
85
end
86
+
87
+ context "when report is submitted to Akismet" do
88
+ let ( :report ) { build ( :feedback ) }
89
+
90
+ it "has comment_type \" contact-form\" " do
91
+ expect ( report . akismet_attributes [ :comment_type ] ) . to eq ( "contact-form" )
92
+ end
93
+
94
+ it "has user_role \" user-with-nonmatching-email\" when reporter is logged in" do
95
+ User . current_user = create ( :user )
96
+ expect ( report . akismet_attributes [ :user_role ] ) . to eq ( "user-with-nonmatching-email" )
97
+ end
98
+
99
+ it "has user_role \" guest\" when reporter is logged out" do
100
+ expect ( report . akismet_attributes [ :user_role ] ) . to eq ( "guest" )
101
+ end
102
+ end
86
103
end
You can’t perform that action at this time.
0 commit comments