Skip to content

Commit

Permalink
fix some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
r888888888 committed Jan 2, 2018
1 parent 4a80d6c commit 604e9e9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -103,7 +103,7 @@ module Levels
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
Expand Down
10 changes: 6 additions & 4 deletions test/unit/moderator/ip_addr_search_test.rb
Expand Up @@ -8,7 +8,9 @@ class IpAddrSearchTest < ActiveSupport::TestCase
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
Expand All @@ -18,17 +20,17 @@ class IpAddrSearchTest < ActiveSupport::TestCase

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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/post_test.rb
Expand Up @@ -2129,7 +2129,7 @@ def teardown
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")

Expand Down
22 changes: 13 additions & 9 deletions test/unit/tag_alias_test.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/unit/user_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 604e9e9

Please sign in to comment.