fix unit tests

This commit is contained in:
r888888888
2017-11-20 16:10:35 -08:00
parent f11992bd91
commit 502f1298a9
25 changed files with 101 additions and 29 deletions

View File

@@ -40,7 +40,7 @@ class ArtistUrlTest < ActiveSupport::TestCase
should "normalize nico seiga artist urls" do
url = FactoryGirl.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/1826959")
assert_equal("http://seiga.nicovideo.jp/user/illust/1826959", url.normalized_url)
assert_equal("http://seiga.nicovideo.jp/user/illust/1826959/", url.normalized_url)
url = FactoryGirl.create(:artist_url, :url => "http://seiga.nicovideo.jp/seiga/im4937663")
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", url.normalized_url)

View File

@@ -1,6 +1,11 @@
require 'test_helper'
class BanTest < ActiveSupport::TestCase
def setup
super
User.any_instance.stubs(:validate_sock_puppets).returns(true)
end
context "A ban" do
context "created by an admin" do
setup do

View File

@@ -3,10 +3,12 @@ require 'test_helper'
class BulkRevertTest < ActiveSupport::TestCase
context "#find_post_versions" do
subject do
BulkRevert.new(added_tags: "hoge")
@user = FactoryGirl.create(:user)
BulkRevert.new
end
setup do
subject.stubs(:constraints).returns({added_tags: ["a"]})
subject.expects(:query_gbq).returns([1,2,3])
end

View File

@@ -2,6 +2,7 @@ require 'test_helper'
class CurrentUserTest < ActiveSupport::TestCase
setup do
User.any_instance.stubs(:validate_sock_puppets).returns(true)
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end

View File

@@ -17,6 +17,7 @@ class DmailTest < ActiveSupport::TestCase
context "spam" do
setup do
Dmail.any_instance.stubs(:spam?).returns(true)
@recipient = FactoryGirl.create(:user)
end

View File

@@ -32,7 +32,7 @@ module Downloads
@new_medium_thumbnail = "http://i1.pixiv.net/c/600x600/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"
@new_full_size_image = "http://i1.pixiv.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png"
@file_size = 1_083
@file_size = 1261
end
should "work when using new URLs" do
@@ -135,7 +135,7 @@ module Downloads
context "downloading a profile image" do
should "download new profile images" do
@file_url = "http://i2.pixiv.net/img130/profile/minono_aki/8733472.jpg"
@file_size = 23266
@file_size = 23_444
assert_not_rewritten(@file_url)
assert_downloaded(@file_size, @file_url)
@@ -146,7 +146,7 @@ module Downloads
context "downloading a background image" do
should "download the image" do
@file_url = "http://i1.pixiv.net/background/img/2016/05/17/12/05/48/2074388_d4ac52034f7ca0af3e083d59fde7e97f.jpg"
@file_size = 386_500
@file_size = 386_678
assert_not_rewritten(@file_url)
assert_downloaded(@file_size, @file_url)

View File

@@ -68,6 +68,7 @@ class FavoriteTest < ActiveSupport::TestCase
end
should "remove it from all favorite groups" do
assert_equal("#{@post.id}", @fav_group.post_ids)
@post.expunge!
@fav_group.reload
assert_equal("", @fav_group.post_ids)

View File

@@ -3,6 +3,7 @@ require 'test_helper'
class JanitorTrialTest < ActiveSupport::TestCase
context "A janitor trial" do
setup do
User.any_instance.stubs(:validate_sock_puppets).returns(true)
@admin = FactoryGirl.create(:admin_user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @admin

View File

@@ -1,6 +1,8 @@
require 'test_helper'
class PostArchiveTest < ActiveSupport::TestCase
include PoolArchiveTestHelper
context "A post" do
setup do
Timecop.travel(1.month.ago) do
@@ -70,6 +72,7 @@ class PostArchiveTest < ActiveSupport::TestCase
context "that is tagged with a pool:<name> metatag" do
setup do
mock_pool_archive_service!
@pool = FactoryGirl.create(:pool)
@post = FactoryGirl.create(:post, tag_string: "tagme pool:#{@pool.id}")
end
@@ -114,10 +117,11 @@ class PostArchiveTest < ActiveSupport::TestCase
end
should "not create a version if updating the post fails" do
@post.stubs(:apply_post_metatags).raises(NotImplementedError)
@post.stubs(:set_tag_counts).raises(NotImplementedError)
assert_equal(2, @post.versions.size)
assert_raise(NotImplementedError) { @post.update(rating: "s") }
assert_equal(1, @post.versions.size)
assert_equal(2, @post.versions.size)
end
should "should create a version if the rating changes" do

View File

@@ -1,6 +1,11 @@
require 'test_helper'
class PostDisapprovalTest < ActiveSupport::TestCase
def setup
super
User.any_instance.stubs(:validate_sock_puppets).returns(true)
end
context "In all cases" do
setup do
@alice = FactoryGirl.create(:moderator_user)

View File

@@ -1,7 +1,9 @@
require 'test_helper'
class PostPrunerTest < ActiveSupport::TestCase
setup do
def setup
super
@user = FactoryGirl.create(:admin_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@@ -21,7 +23,9 @@ class PostPrunerTest < ActiveSupport::TestCase
PostPruner.new.prune!
end
teardown do
def teardown
super
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end

View File

@@ -14,6 +14,8 @@ class PostReplacementTest < ActiveSupport::TestCase
end
def setup
super
mock_iqdb_service!
Delayed::Worker.delay_jobs = true # don't delete the old images right away
@@ -27,6 +29,8 @@ class PostReplacementTest < ActiveSupport::TestCase
end
def teardown
super
CurrentUser.user = nil
CurrentUser.ip_addr = nil
Delayed::Worker.delay_jobs = false

View File

@@ -1472,18 +1472,18 @@ class PostTest < ActiveSupport::TestCase
end
context "but doesn't have a pixiv id" do
should "not save the pixiv id" do
should "save the pixiv id" do
@post.pixiv_id = 1234
@post.update(source: "http://i1.pixiv.net/novel-cover-original/img/2016/11/03/20/10/58/7436075_f75af69f3eacd1656d3733c72aa959cf.jpg")
assert_nil(@post.pixiv_id)
assert_equal(7436075, @post.pixiv_id)
@post.pixiv_id = 1234
@post.update(source: "http://i2.pixiv.net/background/img/2016/10/30/12/27/30/7059005_da9946b806c10d391a81ed1117cd33d6.jpg")
assert_nil(@post.pixiv_id)
assert_equal(7059005, @post.pixiv_id)
@post.pixiv_id = 1234
@post.update(source: "http://i1.pixiv.net/img15/img/omega777/novel/2612734.jpg")
assert_nil(@post.pixiv_id)
assert_equal(2612734, @post.pixiv_id)
@post.pixiv_id = 1234
@post.update(source: "http://img08.pixiv.net/profile/nice/1408837.jpg")

View File

@@ -3,7 +3,8 @@ require 'test_helper'
class PostVoteTest < ActiveSupport::TestCase
def setup
super
User.any_instance.stubs(:validate_sock_puppets).returns(true)
@supervoter = FactoryGirl.create(:user, is_super_voter: true)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user

View File

@@ -6,12 +6,21 @@ class SavedSearchTest < ActiveSupport::TestCase
def setup
super
User.any_instance.stubs(:validate_sock_puppets).returns(true)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
mock_saved_search_service!
end
def teardown
super
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context ".labels_for" do
setup do
@user = FactoryGirl.create(:user)
FactoryGirl.create(:saved_search, user: @user, label_string: "blah", query: "blah")
FactoryGirl.create(:saved_search, user: @user, label_string: "zah", query: "blah")
end
@@ -28,7 +37,6 @@ class SavedSearchTest < ActiveSupport::TestCase
context ".queries_for" do
setup do
@user = FactoryGirl.create(:user)
FactoryGirl.create(:tag_alias, antecedent_name: "bbb", consequent_name: "ccc", creator: @user)
FactoryGirl.create(:saved_search, user: @user, label_string: "blah", query: "aaa")
FactoryGirl.create(:saved_search, user: @user, label_string: "zah", query: "CCC BBB AAA")
@@ -83,7 +91,6 @@ class SavedSearchTest < ActiveSupport::TestCase
context "Creating a saved search" do
setup do
@user = FactoryGirl.create(:gold_user)
FactoryGirl.create(:tag_alias, antecedent_name: "zzz", consequent_name: "yyy", creator: @user)
@saved_search = @user.saved_searches.create(:query => " ZZZ xxx ")
end
@@ -108,7 +115,6 @@ class SavedSearchTest < ActiveSupport::TestCase
context "Destroying a saved search" do
setup do
@user = FactoryGirl.create(:gold_user)
@saved_search = @user.saved_searches.create(:tag_query => "xxx")
@saved_search.destroy
end
@@ -122,6 +128,7 @@ class SavedSearchTest < ActiveSupport::TestCase
context "A user with max saved searches" do
setup do
@user = FactoryGirl.create(:gold_user)
CurrentUser.user = @user
User.any_instance.stubs(:max_saved_searches).returns(0)
@saved_search = @user.saved_searches.create(:query => "xxx")
end

View File

@@ -79,7 +79,7 @@ module Sources
end
should "get the image url" do
assert_equal("http://orig14.deviantart.net/cb25/f/2017/160/1/9/hidden_work_by_noizave-dbc3r29.png", @site.image_url)
assert_match(%r!https://orig\d+\.deviantart\.net/cb25/f/2017/160/1/9/hidden_work_by_noizave-dbc3r29\.png!, @site.image_url)
end
end

View File

@@ -17,7 +17,7 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase
context "with a bad cache and post counts" do
setup do
Cache.put("ta:aaa", "zzz")
Cache.put("ta:#{Cache.hash('aaa')}", "zzz")
Tag.where(:name => "aaa").update_all("post_count = -3")
@correction = TagAliasCorrection.new(@tag_alias.id)
end
@@ -46,7 +46,7 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase
end
should "now have the correct cache" do
assert_equal("bbb", Cache.get("ta:aaa"))
assert_equal("bbb", Cache.get("ta:#{Cache.hash('aaa')}"))
end
should "now have the correct count" do

View File

@@ -3,6 +3,7 @@ require 'test_helper'
class UserNameChangeRequestTest < ActiveSupport::TestCase
context "in all cases" do
setup do
User.any_instance.stubs(:validate_sock_puppets).returns(true)
@admin = FactoryGirl.create(:admin_user)
@requester = FactoryGirl.create(:user)
CurrentUser.user = @requester

View File

@@ -3,6 +3,8 @@ require 'test_helper'
class UserRevertTest < ActiveSupport::TestCase
context "Reverting a user's changes" do
setup do
User.any_instance.stubs(:validate_sock_puppets).returns(true)
@creator = FactoryGirl.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user