This commit is contained in:
r888888888
2017-05-30 12:13:08 -07:00
parent 3a49b3c54b
commit 6eb5a4c017
2 changed files with 3 additions and 2 deletions

View File

@@ -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!

View File

@@ -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