fix some unit tests

This commit is contained in:
r888888888
2018-01-02 15:12:48 -08:00
parent 4a80d6c337
commit 604e9e9866
5 changed files with 22 additions and 15 deletions

View File

@@ -103,7 +103,7 @@ class User < ApplicationRecord
has_many :note_versions, :foreign_key => "updater_id"
has_many :dmails, lambda {order("dmails.id desc")}, :foreign_key => "owner_id"
has_many :saved_searches
has_many :forum_posts, lambda {order("forum_posts.created_at")}, :foreign_key => "creator_id"
has_many :forum_posts, lambda {order("forum_posts.created_at, forum_posts.id")}, :foreign_key => "creator_id"
has_many :user_name_change_requests, lambda {visible.order("user_name_change_requests.created_at desc")}
belongs_to :inviter, :class_name => "User"
after_update :create_mod_action

View File

@@ -8,7 +8,9 @@ module Moderator
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
FactoryGirl.create(:comment)
@comment = FactoryGirl.create(:comment)
PoolArchive.stubs(:enabled?).returns(false)
PostArchive.stubs(:enabled?).returns(false)
end
teardown do
@@ -18,17 +20,17 @@ module Moderator
should "find by ip addr" do
@search = IpAddrSearch.new(:ip_addr => "127.0.0.1")
assert_equal({@user => 2}, @search.execute)
assert_equal({@user => 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") => 2}, @search.execute)
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") => 2}, @search.execute)
assert_equal({IPAddr.new("127.0.0.1") => 1}, @search.execute)
end
end
end

View File

@@ -2129,7 +2129,7 @@ class PostTest < ActiveSupport::TestCase
assert_tag_match([flagged], "status:flagged")
assert_tag_match([deleted], "status:deleted")
assert_tag_match([banned], "status:banned")
assert_tag_match([flagged], "status:active")
assert_tag_match([], "status:active")
assert_tag_match(all, "status:any")
assert_tag_match(all, "status:all")

View File

@@ -138,27 +138,31 @@ class TagAliasTest < ActiveSupport::TestCase
context "with an associated forum topic" do
setup do
@admin = FactoryGirl.create(:admin_user)
@topic = FactoryGirl.create(:forum_topic, :title => TagAliasRequest.topic_title("aaa", "bbb"))
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => TagAliasRequest.command_string("aaa", "bbb"))
@alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
CurrentUser.scoped(@admin) do
@topic = FactoryGirl.create(:forum_topic, :title => TagAliasRequest.topic_title("aaa", "bbb"))
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => TagAliasRequest.command_string("aaa", "bbb"))
@alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
end
end
context "and conflicting wiki pages" do
setup do
@wiki1 = FactoryGirl.create(:wiki_page, :title => "aaa")
@wiki2 = FactoryGirl.create(:wiki_page, :title => "bbb")
@alias.approve!(approver: @admin)
CurrentUser.scoped(@admin) do
@wiki1 = FactoryGirl.create(:wiki_page, :title => "aaa")
@wiki2 = FactoryGirl.create(:wiki_page, :title => "bbb")
@alias.approve!(approver: @admin)
end
@admin.reload # reload to get the forum post the approval created.
@topic.reload
end
should "update the forum topic when approved" do
assert_equal("[APPROVED] Tag alias: aaa -> bbb", @topic.title)
assert_match(/The tag alias .* been approved/m, @admin.forum_posts[-2].body)
assert_match(/The tag alias .* been approved/m, @topic.posts[-2].body)
end
should "warn about conflicting wiki pages when approved" do
assert_match(/has conflicting wiki pages/m, @admin.forum_posts[-1].body)
assert_match(/has conflicting wiki pages/m, @topic.posts[-1].body)
end
end
@@ -189,7 +193,7 @@ class TagAliasTest < ActiveSupport::TestCase
assert_equal("[FAILED] Tag alias: aaa -> bbb", @topic.title)
assert_match(/error: oh no/, @alias.status)
assert_match(/The tag alias .* failed during processing/, @admin.forum_posts.last.body)
assert_match(/The tag alias .* failed during processing/, @topic.posts.last.body)
end
end
end

View File

@@ -301,6 +301,7 @@ class UserTest < ActiveSupport::TestCase
context "that might be a sock puppet" do
setup do
@user = FactoryGirl.create(:user, last_ip_addr: "127.0.0.2")
Danbooru.config.unstub(:enable_sock_puppet_validation?)
end
should "not validate" do