Commit 87d2732915cd970296e73527590e466eeb9a731f
1 parent
5944bfde
Exists in
master
and in
29 other branches
Store User-Agent and Referre on comments
Showing
5 changed files
with
31 additions
and
2 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
... | ... | @@ -127,6 +127,8 @@ class ContentViewerController < ApplicationController |
127 | 127 | @comment.author = user if logged_in? |
128 | 128 | @comment.article = @page |
129 | 129 | @comment.ip_address = request.remote_ip |
130 | + @comment.user_agent = request.user_agent | |
131 | + @comment.referrer = request.referrer | |
130 | 132 | plugins_filter_comment(@comment) |
131 | 133 | return if @comment.rejected? |
132 | 134 | if (pass_without_comment_captcha? || verify_recaptcha(:model => @comment, :message => _('Please type the words correctly'))) && @comment.save | ... | ... |
db/migrate/20120825185219_add_user_agent_and_referrer_to_comments.rb
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +class AddUserAgentAndReferrerToComments < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + add_column :comments, :user_agent, :string | |
4 | + add_column :comments, :referrer, :string | |
5 | + end | |
6 | + | |
7 | + def self.down | |
8 | + remove_column :comments, :user_agent | |
9 | + remove_column :comments, :referrer | |
10 | + end | |
11 | +end | ... | ... |
db/schema.rb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | # |
10 | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | |
12 | -ActiveRecord::Schema.define(:version => 20120818030329) do | |
12 | +ActiveRecord::Schema.define(:version => 20120825185219) do | |
13 | 13 | |
14 | 14 | create_table "abuse_reports", :force => true do |t| |
15 | 15 | t.integer "reporter_id" |
... | ... | @@ -213,6 +213,8 @@ ActiveRecord::Schema.define(:version => 20120818030329) do |
213 | 213 | t.string "ip_address" |
214 | 214 | t.boolean "spam" |
215 | 215 | t.string "source_type" |
216 | + t.string "user_agent" | |
217 | + t.string "referrer" | |
216 | 218 | end |
217 | 219 | |
218 | 220 | create_table "contact_lists", :force => true do |t| | ... | ... |
test/functional/content_viewer_controller_test.rb
... | ... | @@ -1375,12 +1375,16 @@ end |
1375 | 1375 | assert_not_nil assigns(:comment) |
1376 | 1376 | end |
1377 | 1377 | |
1378 | - should 'store IP address for comments' do | |
1378 | + should 'store IP address, user agent and referrer for comments' do | |
1379 | 1379 | page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') |
1380 | 1380 | @request.stubs(:remote_ip).returns('33.44.55.66') |
1381 | + @request.stubs(:referrer).returns('http://example.com') | |
1382 | + @request.stubs(:user_agent).returns('MyBrowser') | |
1381 | 1383 | post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'title', :body => 'body', :name => "Spammer", :email => 'damn@spammer.com' }, :confirm => 'true' |
1382 | 1384 | comment = Comment.last |
1383 | 1385 | assert_equal '33.44.55.66', comment.ip_address |
1386 | + assert_equal 'MyBrowser', comment.user_agent | |
1387 | + assert_equal 'http://example.com', comment.referrer | |
1384 | 1388 | end |
1385 | 1389 | |
1386 | 1390 | should 'not save a comment if a plugin rejects it' do | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -536,6 +536,16 @@ class CommentTest < ActiveSupport::TestCase |
536 | 536 | assert_equal c, SpamNotification.marked_as_ham |
537 | 537 | end |
538 | 538 | |
539 | + should 'store User-Agent' do | |
540 | + c = Comment.new(:user_agent => 'foo') | |
541 | + assert_equal 'foo', c.user_agent | |
542 | + end | |
543 | + | |
544 | + should 'store referrer' do | |
545 | + c = Comment.new(:referrer => 'bar') | |
546 | + assert_equal 'bar', c.referrer | |
547 | + end | |
548 | + | |
539 | 549 | private |
540 | 550 | |
541 | 551 | def create_comment(args = {}) | ... | ... |