test: move test/models/* to test/unit/*.

This commit is contained in:
evazion
2020-01-18 19:56:53 -06:00
parent 79015b4341
commit b62cdc4cfe
5 changed files with 0 additions and 11 deletions

View File

@@ -0,0 +1,42 @@
require 'test_helper'
class SuperVoterTest < ActiveSupport::TestCase
def setup
super
@user = FactoryBot.create(:user)
end
context "#init" do
setup do
@admin = FactoryBot.create(:admin_user)
@user_mock = mock("user")
@user_mock.expects(:user_id).twice.returns(@user.id)
@admin_mock = mock("admin")
@admin_mock.expects(:user_id).twice.returns(@admin.id)
PostVoteSimilarity.any_instance.stubs(:calculate_positive).returns([@admin_mock, @user_mock])
end
should "create super voter objects" do
assert_difference("SuperVoter.count", 2) do
SuperVoter.init!
end
end
end
context "creation" do
should "update the is_super_voter field on the user object" do
FactoryBot.create(:super_voter, user: @user)
@user.reload
assert_equal(true, @user.is_super_voter?)
end
end
context "destruction" do
should "update the is_super_voter field on the user object" do
voter = FactoryBot.create(:super_voter, user: @user)
voter.destroy
@user.reload
assert_equal(false, @user.is_super_voter?)
end
end
end

View File

@@ -0,0 +1,115 @@
require 'test_helper'
class TagAutocompleteTest < ActiveSupport::TestCase
subject { TagAutocomplete }
context "#search" do
should "be case insensitive" do
create(:tag, name: "abcdef", post_count: 1)
assert_equal(["abcdef"], subject.search("A").map(&:name))
end
should "not return duplicates" do
create(:tag, name: "red_eyes", post_count: 5001)
assert_equal(%w[red_eyes], subject.search("re").map(&:name))
end
end
context "#search_exact" do
setup do
@tags = [
create(:tag, name: "abcdef", post_count: 1),
create(:tag, name: "abczzz", post_count: 2),
create(:tag, name: "abcyyy", post_count: 0),
create(:tag, name: "bbbbbb")
]
end
should "find the tags" do
expected = [
@tags[1],
@tags[0]
].map(&:name)
assert_equal(expected, subject.search_exact("abc", 3).map(&:name))
end
end
context "#search_correct" do
setup do
CurrentUser.stubs(:id).returns(1)
@tags = [
create(:tag, name: "abcde", post_count: 1),
create(:tag, name: "abcdz", post_count: 2),
# one char mismatch
create(:tag, name: "abcez", post_count: 2),
# too long
create(:tag, name: "abcdefghijk", post_count: 2),
# wrong prefix
create(:tag, name: "bbcdef", post_count: 2),
# zero post count
create(:tag, name: "abcdy", post_count: 0),
# completely different
create(:tag, name: "bbbbb")
]
end
should "find the tags" do
expected = [
@tags[0],
@tags[1],
@tags[2]
].map(&:name)
assert_equal(expected, subject.search_correct("abcd", 3).map(&:name))
end
end
context "#search_prefix" do
setup do
@tags = [
create(:tag, name: "abcdef", post_count: 1),
create(:tag, name: "alpha_beta_cat", post_count: 2),
create(:tag, name: "alpha_beta_dat", post_count: 0),
create(:tag, name: "alpha_beta_(cane)", post_count: 2),
create(:tag, name: "alpha_beta/cane", post_count: 2)
]
end
should "find the tags" do
expected = [
@tags[1],
@tags[3],
@tags[4]
].map(&:name)
assert_equal(expected, subject.search_prefix("abc", 3).map(&:name))
end
end
context "#search_aliases" do
setup do
@user = create(:user)
@tags = [
create(:tag, name: "/abc", post_count: 0),
create(:tag, name: "abcdef", post_count: 1),
create(:tag, name: "zzzzzz", post_count: 1)
]
as_user do
@aliases = [
create(:tag_alias, antecedent_name: "/abc", consequent_name: "abcdef", status: "active")
]
end
end
should "find the tags" do
results = subject.search_aliases("/abc", 3)
assert_equal(1, results.size)
assert_equal("abcdef", results[0].name)
assert_equal("/abc", results[0].antecedent_name)
end
end
end

View File

@@ -0,0 +1,62 @@
require 'test_helper'
class TagRelationshipRetirementServiceTest < ActiveSupport::TestCase
context ".forum_topic" do
subject { TagRelationshipRetirementService }
should "create a new topic if one doesn't already exist" do
assert_difference(-> { ForumTopic.count }) do
subject.forum_topic
end
end
should "create a new post if one doesn't already exist" do
assert_difference(-> { ForumPost.count }) do
subject.forum_topic
end
end
end
context ".each_candidate" do
subject { TagRelationshipRetirementService }
setup do
subject.stubs(:is_unused?).returns(true)
@new_alias = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
@old_alias = create(:tag_alias, antecedent_name: "ccc", consequent_name: "ddd", created_at: 3.years.ago)
end
should "find old tag relationships" do
subject.each_candidate(TagAlias) do |rel|
assert_equal(@old_alias, rel)
end
end
should "not find new tag relationships" do
subject.each_candidate(TagAlias) do |rel|
assert_not_equal(@new_alias, rel)
end
end
end
context ".is_unused?" do
subject { TagRelationshipRetirementService }
setup do
@new_alias = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
@new_post = create(:post, tag_string: "bbb")
@old_alias = create(:tag_alias, antecedent_name: "ccc", consequent_name: "ddd", created_at: 3.years.ago)
@old_post = create(:post, tag_string: "ddd", created_at: 3.years.ago)
end
should "return true if no recent post exists" do
assert(subject.is_unused?("ddd"))
end
should "return false if a recent post exists" do
refute(subject.is_unused?("bbb"))
end
end
end

File diff suppressed because it is too large Load Diff