eBooru/test/unit/ip_ban_test.rb
2011-12-14 11:19:58 -05:00

31 lines
1001 B
Ruby

require 'test_helper'
class IpBanTest < ActiveSupport::TestCase
setup do
@user = Factory.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
end
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
comment = Factory.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)
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 = Factory.create(:comment, :body => "aaa")
counts = IpBan.query([comment.creator_id])
assert_equal([{"ip_addr" => "1.2.3.4", "count" => "1"}], counts["comments"])
end
end
end