Files
danbooru/test/unit/moderator/ip_addr_search_test.rb
evazion b4ce2d83a6 models: remove belongs_to_creator macro.
The belongs_to_creator macro was used to initialize the creator_id field
to the CurrentUser. This made tests complicated because it meant you had
to create and set the current user every time you wanted to create an
object, when lead to the current user being set over and over again. It
also meant you had to constantly be aware of what the CurrentUser was in
many different contexts, which was often confusing. Setting creators
explicitly simplifies everything greatly.
2020-01-21 00:09:38 -06:00

39 lines
1.2 KiB
Ruby

require "test_helper"
module Moderator
class IpAddrSearchTest < ActiveSupport::TestCase
context "an ip addr search" do
setup do
@user = FactoryBot.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
@comment = create(:comment, creator: @user, creator_ip_addr: "127.0.0.1")
PoolArchive.stubs(:enabled?).returns(false)
PostArchive.stubs(:enabled?).returns(false)
@user.reload
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "find by ip addr" do
@search = IpAddrSearch.new(:ip_addr => "127.0.0.1")
assert_equal({@user => 1, @comment.post.uploader => 1}, @search.execute)
end
should "find by user id" do
@search = IpAddrSearch.new(:user_id => @user.id.to_s)
assert_equal({IPAddr.new("127.0.0.1") => 1}, @search.execute)
end
should "find by user name" do
@search = IpAddrSearch.new(:user_name => @user.name)
assert_equal({IPAddr.new("127.0.0.1") => 1}, @search.execute)
end
end
end
end