Fix #4038: Attempting to create an IP-ban bans the creator.

* Rename comments.ip_addr to comments.creator_ip_addr.
* Fix belongs_to_creator to not clobber ip_addr field.
This commit is contained in:
evazion
2019-01-09 15:15:57 -06:00
parent fa6d86e882
commit 80f43f9a7c
7 changed files with 26 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class IpBanTest < ActiveSupport::TestCase
setup do
@user = FactoryBot.create(:user)
CurrentUser.user = @user
CurrentUser.user = FactoryBot.create(:mod_user)
CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
end
@@ -15,15 +15,22 @@ class IpBanTest < ActiveSupport::TestCase
should "be able to count the number of comments an IP address is associated with" do
comment = FactoryBot.create(:comment)
counts = IpBan.count_by_ip_addr("comments", [comment.creator_id], "creator_id", "ip_addr")
assert_equal([{"ip_addr" => "127.0.0.1", "count" => 1}], counts)
counts = IpBan.count_by_ip_addr("comments", [comment.creator_id], "creator_id", "creator_ip_addr")
assert_equal([{"creator_ip_addr" => "127.0.0.1", "count" => 1}], counts)
end
should "be able to count any updates from a user, groupiny by IP address" do
CurrentUser.scoped(@user, "1.2.3.4") do
comment = FactoryBot.create(:comment, :body => "aaa")
counts = IpBan.query([comment.creator_id])
assert_equal([{"ip_addr" => "1.2.3.4", "count" => 1}], counts["comments"])
assert_equal([{"creator_ip_addr" => "1.2.3.4", "count" => 1}], counts["comments"])
end
end
should "be able to ban a user" do
ip_ban = IpBan.create(ip_addr: "1.2.3.4", reason: "test")
assert_equal("1.2.3.4", ip_ban.ip_addr.to_s)
assert(IpBan.is_banned?("1.2.3.4"))
end
end