diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 212e5b8..ff7e2e2 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -111,6 +111,7 @@ class ContentViewerController < ApplicationController def add_comment @comment.author = user if logged_in? @comment.article = @page + @comment.ip_address = request.remote_ip if (pass_without_comment_captcha? || verify_recaptcha(:model => @comment, :message => _('Please type the words correctly'))) && @comment.save @page.touch @comment = nil # clear the comment form diff --git a/db/migrate/20120307200651_add_ip_address_to_comment.rb b/db/migrate/20120307200651_add_ip_address_to_comment.rb new file mode 100644 index 0000000..f341099 --- /dev/null +++ b/db/migrate/20120307200651_add_ip_address_to_comment.rb @@ -0,0 +1,11 @@ +class AddIpAddressToComment < ActiveRecord::Migration + def self.up + add_column :comments, :ip_address, :string + add_column :comments, :spam, :boolean + end + + def self.down + remove_column :comments, :ip_address + remove_column :comments, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 4355d8a..18dc424 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111004184104) do +ActiveRecord::Schema.define(:version => 20120307200651) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -204,6 +204,8 @@ ActiveRecord::Schema.define(:version => 20111004184104) do t.string "email" t.datetime "created_at" t.integer "reply_of_id" + t.string "ip_address" + t.boolean "spam" end create_table "contact_lists", :force => true do |t| diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 104c2e1..1579e43 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -1370,4 +1370,13 @@ class ContentViewerControllerTest < ActionController::TestCase post :view_page, :profile => profile.identifier, :page => ['test'], :comment => {:body => "Some comment...", :author => profile}, :confirm => 'true' assert_not_nil assigns(:comment) end + + should 'store IP address for comments' do + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') + @request.stubs(:remote_ip).returns('33.44.55.66') + post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'title', :body => 'body', :name => "Spammer", :email => 'damn@spammer.com' }, :confirm => 'true' + comment = Comment.last + assert_equal '33.44.55.66', comment.ip_address + end + end -- libgit2 0.21.2