fix unit tests
This commit is contained in:
@@ -4,7 +4,7 @@ class BulkRevert
|
||||
|
||||
class ConstraintTooGeneralError < Exception ; end
|
||||
|
||||
def process(creator, constraints)
|
||||
def process(creator, constraints = {})
|
||||
@constraints = constraints
|
||||
|
||||
ModAction.log("Processed bulk revert for #{constraints.inspect} by #{creator.name}")
|
||||
@@ -19,6 +19,7 @@ class BulkRevert
|
||||
end
|
||||
|
||||
def initialize
|
||||
@constraints = {}
|
||||
end
|
||||
|
||||
def preview
|
||||
|
||||
@@ -12,12 +12,32 @@ class PawooApiClient
|
||||
end
|
||||
|
||||
def initialize(json)
|
||||
@json = get
|
||||
@json = json
|
||||
end
|
||||
|
||||
def profile_url
|
||||
json["url"]
|
||||
end
|
||||
|
||||
def account_name
|
||||
json["username"]
|
||||
end
|
||||
|
||||
def image_url
|
||||
nil
|
||||
end
|
||||
|
||||
def image_urls
|
||||
[]
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
def commentary
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
class Status
|
||||
@@ -32,7 +52,7 @@ class PawooApiClient
|
||||
@json = json
|
||||
end
|
||||
|
||||
def account_profile_url
|
||||
def profile_url
|
||||
json["account"]["url"]
|
||||
end
|
||||
|
||||
@@ -60,9 +80,11 @@ class PawooApiClient
|
||||
end
|
||||
end
|
||||
|
||||
def get_status(url)
|
||||
def get(url)
|
||||
if id = Status.is_match?(url)
|
||||
Status.new(JSON.parse(access_token.get("/api/v1/statuses/#{id}").body))
|
||||
elsif id = Account.is_match?(url)
|
||||
Account.new(JSON.parse(access_token.get("/api/v1/accounts/#{id}").body))
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ module Sources::Strategies
|
||||
attr_reader :image_urls
|
||||
|
||||
def self.url_match?(url)
|
||||
PawooApiClient::Status.is_match?(url)
|
||||
PawooApiClient::Status.is_match?(url) || PawooApiClient::Account.is_match?(url)
|
||||
end
|
||||
|
||||
def referer_url
|
||||
@@ -28,13 +28,13 @@ module Sources::Strategies
|
||||
end
|
||||
|
||||
def api_response
|
||||
@response ||= PawooApiClient.new.get_status(normalized_url)
|
||||
@response ||= PawooApiClient.new.get(normalized_url)
|
||||
end
|
||||
|
||||
def get
|
||||
response = api_response
|
||||
@artist_name = response.account_name
|
||||
@profile_url = response.account_profile_url
|
||||
@profile_url = response.profile_url
|
||||
@image_url = response.image_urls.first
|
||||
@image_urls = response.image_urls
|
||||
@tags = response.tags
|
||||
@@ -54,6 +54,11 @@ module Sources::Strategies
|
||||
true
|
||||
end
|
||||
|
||||
def normalize_for_artist_finder!
|
||||
get
|
||||
@profile_url
|
||||
end
|
||||
|
||||
def dtext_artist_commentary_desc
|
||||
DText.from_html(artist_commentary_desc) do |element|
|
||||
if element.name == "a"
|
||||
|
||||
@@ -173,6 +173,7 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
|
||||
def add!(post_id)
|
||||
post_id = post_id.id if post_id.is_a?(Post)
|
||||
return if contains?(post_id)
|
||||
|
||||
clear_post_id_array
|
||||
@@ -180,12 +181,14 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.purge_post(post_id)
|
||||
post_id = post_id.id if post_id.is_a?(Post)
|
||||
for_post(post_id).find_each do |group|
|
||||
group.remove!(post_id)
|
||||
end
|
||||
end
|
||||
|
||||
def remove!(post_id)
|
||||
post_id = post_id.id if post_id.is_a?(Post)
|
||||
return unless contains?(post_id)
|
||||
|
||||
clear_post_id_array
|
||||
|
||||
@@ -13,7 +13,7 @@ class PostDisapproval < ApplicationRecord
|
||||
scope :disinterest, lambda {where(:reason => ["disinterest", "legacy"])}
|
||||
|
||||
def self.prune!
|
||||
PostDisapproval.where("post_id in (select _.post_id from post_disapprovals _ where _.created_at < ?)", DELETION_THRESHOLD.ago)
|
||||
PostDisapproval.where("post_id in (select _.post_id from post_disapprovals _ where _.created_at < ?)", DELETION_THRESHOLD.ago).delete_all
|
||||
end
|
||||
|
||||
def self.dmail_messages!
|
||||
|
||||
@@ -4,6 +4,8 @@ class DmailFilterTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
User.any_instance.stubs(:validate_sock_puppets).returns(true)
|
||||
|
||||
@receiver = FactoryGirl.create(:user)
|
||||
@sender = FactoryGirl.create(:user)
|
||||
end
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -4,6 +4,7 @@ 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user