2011-07-29 18:04:50 -04:00
|
|
|
require 'test_helper'
|
2010-03-18 17:55:57 -04:00
|
|
|
|
|
|
|
class IpBanTest < ActiveSupport::TestCase
|
2010-08-26 14:36:02 -04:00
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
@user = FactoryBot.create(:user)
|
2019-01-09 16:15:57 -05:00
|
|
|
CurrentUser.user = FactoryBot.create(:mod_user)
|
2010-08-26 14:36:02 -04:00
|
|
|
CurrentUser.ip_addr = "127.0.0.1"
|
2011-12-14 11:19:58 -05:00
|
|
|
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
|
2010-08-26 14:36:02 -04:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-08-26 14:36:02 -04:00
|
|
|
teardown do
|
|
|
|
CurrentUser.user = nil
|
|
|
|
CurrentUser.ip_addr = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
should "be able to count the number of comments an IP address is associated with" do
|
2018-04-02 13:51:26 -04:00
|
|
|
comment = FactoryBot.create(:comment)
|
2019-01-09 16:15:57 -05:00
|
|
|
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)
|
2010-04-29 17:32:15 -04:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-08-26 14:36:02 -04:00
|
|
|
should "be able to count any updates from a user, groupiny by IP address" do
|
2010-10-27 20:16:43 -04:00
|
|
|
CurrentUser.scoped(@user, "1.2.3.4") do
|
2018-04-02 13:51:26 -04:00
|
|
|
comment = FactoryBot.create(:comment, :body => "aaa")
|
2011-01-14 15:50:17 -05:00
|
|
|
counts = IpBan.query([comment.creator_id])
|
2019-01-09 16:15:57 -05:00
|
|
|
assert_equal([{"creator_ip_addr" => "1.2.3.4", "count" => 1}], counts["comments"])
|
2010-10-27 20:16:43 -04:00
|
|
|
end
|
2010-04-29 17:32:15 -04:00
|
|
|
end
|
2019-01-09 16:15:57 -05:00
|
|
|
|
|
|
|
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
|
2010-03-18 17:55:57 -04:00
|
|
|
end
|