diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index 8b0e63f24..9b640cdcc 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -165,7 +165,7 @@ class PostFlag < ActiveRecord::Base def initialize_creator self.creator_id ||= CurrentUser.id - self.creator_ip_addr ||= CurrentUser.ip_addr + self.creator_ip_addr = CurrentUser.ip_addr if creator_ip_addr == "127.0.0.1" || creator_ip_addr.blank? end def resolve! diff --git a/test/unit/post_flag_test.rb b/test/unit/post_flag_test.rb index ea2afd5d0..57ca38d8b 100644 --- a/test/unit/post_flag_test.rb +++ b/test/unit/post_flag_test.rb @@ -7,7 +7,7 @@ class PostFlagTest < ActiveSupport::TestCase @alice = FactoryGirl.create(:gold_user) end CurrentUser.user = @alice - CurrentUser.ip_addr = "127.0.0.1" + CurrentUser.ip_addr = "127.0.0.2" @post = FactoryGirl.create(:post, :tag_string => "aaa") end @@ -91,6 +91,7 @@ class PostFlagTest < ActiveSupport::TestCase should "initialize its creator" do @post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false) assert_equal(@alice.id, @post_flag.creator_id) + assert_equal(IPAddr.new("127.0.0.2"), @post_flag.creator_ip_addr) end end end