rubocop: fix various style issues.

This commit is contained in:
evazion
2019-12-22 16:21:58 -06:00
parent 09f6a84660
commit 309821bf73
288 changed files with 912 additions and 962 deletions

View File

@@ -5,4 +5,3 @@ FactoryBot.define do
association :creator, factory: :user
end
end

View File

@@ -1,6 +1,6 @@
FactoryBot.define do
factory(:pool) do
name {"pool_" + (rand(1_000_000) + 100).to_s}
name {"pool_" + rand(100..1000099).to_s}
association :creator, :factory => :user
description {FFaker::Lorem.sentences.join(" ")}
end

View File

@@ -39,4 +39,3 @@ FactoryBot.define do
end
end
end

View File

@@ -59,4 +59,3 @@ FactoryBot.define do
end
end
end

View File

@@ -5,7 +5,7 @@ class Admin::DashboardsControllerTest < ActionDispatch::IntegrationTest
setup do
@admin = create(:admin_user)
end
context "show action" do
should "render" do
get_auth admin_dashboard_path, @admin

View File

@@ -21,10 +21,10 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest
params = {
search: {
text_matches: @commentary1.original_title,
post_id: @commentary1.post_id,
post_id: @commentary1.post_id,
original_present: "yes",
translated_present: "yes",
post_tags_match: @commentary1.post.tag_array.first,
post_tags_match: @commentary1.post.tag_array.first
}
}
@@ -48,7 +48,7 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest
params = {
artist_commentary: {
original_title: "foo",
post_id: FactoryBot.create(:post).id,
post_id: FactoryBot.create(:post).id
},
format: "js"
}
@@ -63,7 +63,7 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest
params = {
artist_commentary: {
post_id: @commentary1.post_id,
original_title: "foo",
original_title: "foo"
},
format: "js"
}

View File

@@ -12,7 +12,7 @@ class ArtistUrlsControllerTest < ActionDispatch::IntegrationTest
@artist = FactoryBot.create(:artist, name: "bkub", url_string: "-http://bkub.com")
get artist_urls_path(search: {
artist: { name: "bkub", },
artist: { name: "bkub" },
url_matches: "*bkub*",
is_active: "false",
order: "created_at"

View File

@@ -185,7 +185,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
end
end
context "create action"do
context "create action" do
should "create a comment" do
assert_difference("Comment.count", 1) do
post_auth comments_path, @user, params: {comment: FactoryBot.attributes_for(:comment, post_id: @post.id)}

View File

@@ -117,16 +117,16 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
get forum_topics_path, params: {:search => {:title_matches => "forum"}}
assert_response :success
assert_select "a.forum-post-link", @forum_topic.title
assert_select "a.forum-post-link", {count: 0, text: @topic1.title}
assert_select "a.forum-post-link", {count: 0, text: @topic2.title}
assert_select "a.forum-post-link", count: 0, text: @topic1.title
assert_select "a.forum-post-link", count: 0, text: @topic2.title
end
should "list nothing for when the search matches nothing" do
get forum_topics_path, params: {:search => {:title_matches => "bababa"}}
assert_response :success
assert_select "a.forum-post-link", {count: 0, text: @forum_topic.title}
assert_select "a.forum-post-link", {count: 0, text: @topic1.title}
assert_select "a.forum-post-link", {count: 0, text: @topic2.title}
assert_select "a.forum-post-link", count: 0, text: @forum_topic.title
assert_select "a.forum-post-link", count: 0, text: @topic1.title
assert_select "a.forum-post-link", count: 0, text: @topic2.title
end
end
end

View File

@@ -24,4 +24,4 @@ module Maintenance
end
end
end
end
end

View File

@@ -36,4 +36,4 @@ module Maintenance
end
end
end
end
end

View File

@@ -64,7 +64,7 @@ module Moderator
end
end
context "for notes"do
context "for notes" do
setup do
as(@user) do
@post = create(:post)

View File

@@ -6,7 +6,7 @@ module Moderator
setup do
PoolArchive.delete_all
PostArchive.delete_all
travel_to(1.month.ago) do
@user = create(:moderator_user)
end

View File

@@ -26,7 +26,7 @@ module Moderator
assert_difference("PostDisapproval.count", 1) do
post_auth moderator_post_disapprovals_path, @admin, params: { post_disapproval: { post_id: @post.id, reason: "breaks_rules" }, format: "json" }
end
assert_response :success
assert_response :success
end
end
end

View File

@@ -9,7 +9,7 @@ module Moderator
travel_to(1.month.ago) do
@user = create(:gold_user)
end
as_user do
@post = create(:post)
end
@@ -69,7 +69,7 @@ module Moderator
@child = create(:post, parent: @parent)
end
users = FactoryBot.create_list(:user, 2)
users.each do |u|
users.each do |u|
@child.add_favorite!(u)
@child.reload
end

View File

@@ -24,7 +24,7 @@ class NotesControllerTest < ActionDispatch::IntegrationTest
post_id: @note.post_id,
post_tags_match: @note.post.tag_array.first,
creator_name: @note.creator.name,
creator_id: @note.creator_id,
creator_id: @note.creator_id
}
}

View File

@@ -16,7 +16,7 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest
format: :json,
post_id: @post.id,
post_replacement: {
replacement_url: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg",
replacement_url: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
}
}
@@ -42,7 +42,7 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest
id: @post_replacement.id,
post_replacement: {
file_size_was: 23,
file_size: 42,
file_size: 42
}
}

View File

@@ -32,7 +32,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
end
end
context "preprocess action" do
context "preprocess action" do
should "prefer the file over the source when preprocessing" do
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
post_auth preprocess_uploads_path, @user, params: {:upload => {:source => "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", :file => file}}
@@ -154,7 +154,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
source_matches: @upload.source,
rating: @upload.rating,
status: @upload.status,
server: @upload.server,
server: @upload.server
}
get uploads_path, params: { search: search_params }
@@ -192,13 +192,13 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
end
should "update the predecessor" do
assert_difference(->{ Post.count }, 1) do
assert_difference(->{ Upload.count }, 0) do
assert_difference(-> { Post.count }, 1) do
assert_difference(-> { Upload.count }, 0) do
post_auth uploads_path, @user, params: {:upload => {:tag_string => "aaa", :rating => "q", :source => @source, :referer_url => @ref}}
end
end
post = Post.last
assert_match(/aaa/, post.tag_string)
assert_match(/aaa/, post.tag_string)
end
end
@@ -212,13 +212,13 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
end
should "update the predecessor" do
assert_difference(->{ Post.count }, 1) do
assert_difference(->{ Upload.count }, 0) do
assert_difference(-> { Post.count }, 1) do
assert_difference(-> { Upload.count }, 0) do
post_auth uploads_path, @user, params: {:upload => {:tag_string => "aaa", :rating => "q", :source => @source, :referer_url => @ref}}
end
end
post = Post.last
assert_match(/aaa/, post.tag_string)
assert_match(/aaa/, post.tag_string)
end
end
end

View File

@@ -105,7 +105,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
setup do
Danbooru.config.stubs(:enable_recaptcha?).returns(false)
end
should "render" do
get new_user_path
assert_response :success
@@ -121,7 +121,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
context "with sockpuppet validation enabled" do
setup do
Danbooru.config.unstub(:enable_sock_puppet_validation?)
Danbooru.config.unstub(:enable_sock_puppet_validation?)
@user.update(last_ip_addr: "127.0.0.1")
end

View File

@@ -1,7 +1,8 @@
require 'test_helper'
class TestJob < ApplicationJob
def perform(record); end
def perform(record)
end
end
class ApplicationJobTest < ActiveJob::TestCase

View File

@@ -96,7 +96,7 @@ class TagAutocompleteTest < ActiveSupport::TestCase
@tags = [
create(:tag, name: "/abc", post_count: 0),
create(:tag, name: "abcdef", post_count: 1),
create(:tag, name: "zzzzzz", post_count: 1),
create(:tag, name: "zzzzzz", post_count: 1)
]
as_user do
@aliases = [

View File

@@ -68,8 +68,7 @@ class TagRelationshipRetirementServiceTest < ActiveSupport::TestCase
end
should "return false if a recent post exists" do
refute(subject.is_unused?("bbb"))
refute(subject.is_unused?("bbb"))
end
end
end

View File

@@ -20,7 +20,7 @@ class UploadServiceTest < ActiveSupport::TestCase
context "#get_file_for_upload" do
context "for a non-source site" do
setup do
@source = "https://upload.wikimedia.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg"
@source = "https://upload.wikimedia.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg"
@upload = Upload.new
@upload.source = @source
end
@@ -163,7 +163,7 @@ class UploadServiceTest < ActiveSupport::TestCase
end
end
context "for an image" do
context "for an image" do
setup do
@file = File.open("test/files/test.jpg", "rb")
@upload = Upload.new(file_ext: "jpg")
@@ -211,7 +211,7 @@ class UploadServiceTest < ActiveSupport::TestCase
setup do
context = UGOIRA_CONTEXT
@file = File.open("test/fixtures/ugoira.zip", "rb")
@upload = mock()
@upload = mock
@upload.stubs(:is_video?).returns(false)
@upload.stubs(:is_ugoira?).returns(true)
@upload.stubs(:context).returns(context)
@@ -243,7 +243,7 @@ class UploadServiceTest < ActiveSupport::TestCase
context "for an mp4" do
setup do
@file = File.open("test/files/test-300x300.mp4", "rb")
@upload = mock()
@upload = mock
@upload.stubs(:is_video?).returns(true)
@upload.stubs(:is_ugoira?).returns(false)
end
@@ -266,7 +266,7 @@ class UploadServiceTest < ActiveSupport::TestCase
context "for a webm" do
setup do
@file = File.open("test/files/test-512x512.webm", "rb")
@upload = mock()
@upload = mock
@upload.stubs(:is_video?).returns(true)
@upload.stubs(:is_ugoira?).returns(false)
end
@@ -293,7 +293,7 @@ class UploadServiceTest < ActiveSupport::TestCase
end
setup do
@upload = mock()
@upload = mock
@upload.stubs(:is_video?).returns(false)
@upload.stubs(:is_ugoira?).returns(false)
@upload.stubs(:is_image?).returns(true)
@@ -414,8 +414,8 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal(9800, @upload.file_size)
assert_equal("png", @upload.file_ext)
assert_equal("f5fe24f3a3a13885285f6627e04feec9", @upload.md5)
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "png", :original)))
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "png", :preview)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "png", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "png", :preview)))
end
end
@@ -436,8 +436,8 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal(294591, @upload.file_size)
assert_equal("jpg", @upload.file_ext)
assert_equal("3cb1ef624714c15dbb2d6e7b1d57faef", @upload.md5)
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :preview)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :preview)))
end
end
@@ -459,8 +459,8 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal(2804, @upload.file_size)
assert_equal("zip", @upload.file_ext)
assert_equal("cad1da177ef309bf40a117c17b8eecf5", @upload.md5)
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "zip", :original)))
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "zip", :large)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "zip", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "zip", :large)))
end
end
@@ -480,9 +480,9 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal(181309, @upload.file_size)
assert_equal("jpg", @upload.file_ext)
assert_equal("93f4dd66ef1eb11a89e56d31f9adc8d0", @upload.md5)
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :large)))
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :preview)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :large)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :preview)))
end
end
@@ -499,8 +499,8 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal("mp4", @upload.file_ext)
assert_operator(@upload.file_size, :>, 0)
assert_not_nil(@upload.source)
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "mp4", :original)))
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "mp4", :preview)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "mp4", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "mp4", :preview)))
end
end
@@ -509,7 +509,7 @@ class UploadServiceTest < ActiveSupport::TestCase
@source = "https://raikou1.donmai.us/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
HTTParty.stubs(:get).raises(Net::ReadTimeout)
end
should "leave the upload in an error state" do
@service = subject.new(source: @source)
@upload = @service.start!
@@ -536,7 +536,7 @@ class UploadServiceTest < ActiveSupport::TestCase
should "overwrite the attributes" do
@service = subject.new(source: @source, rating: 'e')
@upload = @service.start!
@upload = @service.start!
@service.finish!
@upload.reload
assert_equal('e', @upload.rating)
@@ -558,7 +558,7 @@ class UploadServiceTest < ActiveSupport::TestCase
@post.stubs(:queue_delete_files)
@replacement = FactoryBot.create(:post_replacement, post: @post, replacement_url: "", replacement_file: @new_file)
end
end
end
subject { UploadService::Replacer.new(post: @post, replacement: @replacement) }
@@ -614,7 +614,7 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal(28086, @post.file_size)
assert_equal("jpg", @post.file_ext)
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @post.md5)
assert(File.exists?(@post.file.path))
assert(File.exist?(@post.file.path))
end
end
@@ -856,7 +856,7 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal("cad1da177ef309bf40a117c17b8eecf5", Digest::MD5.file(@post.file).hexdigest)
assert_equal("https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @post.source)
assert_equal([{"delay"=>125, "file"=>"000000.jpg"}, {"delay"=>125,"file"=>"000001.jpg"}], @post.pixiv_ugoira_frame_data.data)
assert_equal([{"delay" => 125, "file" => "000000.jpg"}, {"delay" => 125, "file" => "000001.jpg"}], @post.pixiv_ugoira_frame_data.data)
rescue Net::OpenTimeout
skip "Remote connection to Pixiv failed"
end
@@ -870,7 +870,7 @@ class UploadServiceTest < ActiveSupport::TestCase
@post.unstub(:queue_delete_files)
# this is called thrice to delete the file for 62247364
FileUtils.expects(:rm_f).times(3)
FileUtils.expects(:rm_f).times(3)
as_user do
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
@@ -1018,7 +1018,7 @@ class UploadServiceTest < ActiveSupport::TestCase
context "that is too large" do
setup do
Danbooru.config.stubs(:max_image_resolution).returns(31*31)
Danbooru.config.stubs(:max_image_resolution).returns(31 * 31)
end
should "should fail validation" do
@@ -1068,7 +1068,6 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal("error: ActiveRecord::RecordInvalid - Validation failed: Md5 duplicate: #{@post.id}", @predecessor.status)
end
end
end
context "with no predecessor" do
@@ -1178,7 +1177,7 @@ class UploadServiceTest < ActiveSupport::TestCase
should "record the canonical source" do
post = subject.new({}).create_post_from_upload(@upload)
assert_equal(@ref, post.source)
end
end
end
context "for a pixiv ugoira" do
@@ -1213,7 +1212,7 @@ class UploadServiceTest < ActiveSupport::TestCase
should "create a commentary record" do
assert_difference(-> { ArtistCommentary.count }) do
subject.new({include_artist_commentary: true, artist_commentary_title: "blah", artist_commentary_desc: "blah"}).create_post_from_upload(@upload)
subject.new(include_artist_commentary: true, artist_commentary_title: "blah", artist_commentary_desc: "blah").create_post_from_upload(@upload)
end
end
@@ -1223,7 +1222,6 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_not_nil(post.id)
end
end
end
context "Upload#prune!" do
@@ -1239,31 +1237,31 @@ class UploadServiceTest < ActiveSupport::TestCase
should "delete unused files after deleting the upload" do
@upload = as(@user) { UploadService::Preprocessor.new(file: upload_file("test/files/test.jpg")).start! }
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
@upload.destroy!
refute(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
refute(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
end
should "not delete files that are still in use by a post" do
@upload = as(@user) { UploadService.new(file: upload_file("test/files/test.jpg")).start! }
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
@upload.destroy!
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
end
should "not delete files if they're still in use by another upload" do
@upload1 = as(@user) { UploadService::Preprocessor.new(file: upload_file("test/files/test.jpg")).start! }
@upload2 = as(@user) { UploadService::Preprocessor.new(file: upload_file("test/files/test.jpg")).start! }
assert_equal(@upload1.md5, @upload2.md5)
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload1.md5, "jpg", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload1.md5, "jpg", :original)))
@upload1.destroy!
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload1.md5, "jpg", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload1.md5, "jpg", :original)))
@upload2.destroy!
refute(File.exists?(Danbooru.config.storage_manager.file_path(@upload2.md5, "jpg", :original)))
refute(File.exist?(Danbooru.config.storage_manager.file_path(@upload2.md5, "jpg", :original)))
end
should "not delete files that were replaced after upload and are still pending deletion" do
@@ -1276,11 +1274,11 @@ class UploadServiceTest < ActiveSupport::TestCase
# after replacement the uploaded file is no longer in use, but it shouldn't be
# deleted yet. it should only be deleted by the replacer after the grace period.
@upload.destroy!
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
travel (PostReplacement::DELETION_GRACE_PERIOD + 1).days
perform_enqueued_jobs
refute(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
refute(File.exist?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
end
should "work on uploads without a file" do

View File

@@ -8,14 +8,14 @@ if ENV["SIMPLECOV"]
end
end
require File.expand_path('../../config/environment', __FILE__)
require File.expand_path('../config/environment', __dir__)
require 'rails/test_help'
require 'cache'
require 'webmock/minitest'
require 'mocha/minitest'
Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].each {|file| require file}
Dir[File.expand_path(File.dirname(__FILE__) + "/test_helpers/*.rb")].each {|file| require file}
Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].sort.each {|file| require file}
Dir[File.expand_path(File.dirname(__FILE__) + "/test_helpers/*.rb")].sort.each {|file| require file}
Shoulda::Matchers.configure do |config|
config.integrate do |with|

View File

@@ -1,5 +1,5 @@
module DownloadTestHelper
def assert_downloaded(expected_filesize, source, referer=nil)
def assert_downloaded(expected_filesize, source, referer = nil)
download = Downloads::File.new(source, referer)
tempfile, strategy = download.download!
assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}")
@@ -7,13 +7,13 @@ module DownloadTestHelper
skip "Remote connection to #{source} failed"
end
def assert_rewritten(expected_source, test_source, test_referer=nil)
def assert_rewritten(expected_source, test_source, test_referer = nil)
strategy = Sources::Strategies.find(test_source, test_referer)
rewritten_source = strategy.image_url
assert_match(expected_source, rewritten_source, "Tested source URL: #{test_source}")
end
def assert_not_rewritten(source, referer=nil)
def assert_not_rewritten(source, referer = nil)
assert_rewritten(source, source, referer)
end

View File

@@ -59,6 +59,5 @@ class APNGInspectorTest < ActiveSupport::TestCase
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
end
end

View File

@@ -93,7 +93,7 @@ class ArtistCommentaryTest < ActiveSupport::TestCase
original_title: " foo\u00A0\t\n",
original_description: " foo\u00A0\t\n",
translated_title: " foo\u00A0\t\n",
translated_description: " foo\u00A0\n",
translated_description: " foo\u00A0\n"
)
assert_equal("foo", @artcomm.original_title)

View File

@@ -39,7 +39,7 @@ class ArtistTest < ActiveSupport::TestCase
@artist = Artist.create(name: "blah", url_string: "-http://monet.com\nhttp://monet.com")
assert_equal(1, @artist.urls.count)
assert_equal(["-http://monet.com"], @artist.urls.map(&:to_s))
refute(@artist.urls[0].is_active?)
refute(@artist.urls[0].is_active?)
end
should "allow deactivating a url" do
@@ -237,7 +237,7 @@ class ArtistTest < ActiveSupport::TestCase
context "when finding pixiv artists" do
setup do
FactoryBot.create(:artist, :name => "masao",:url_string => "http://www.pixiv.net/member.php?id=32777")
FactoryBot.create(:artist, :name => "masao", :url_string => "http://www.pixiv.net/member.php?id=32777")
FactoryBot.create(:artist, :name => "bkub", :url_string => "http://www.pixiv.net/member.php?id=9948")
FactoryBot.create(:artist, :name => "ryuura", :url_string => "http://www.pixiv.net/member.php?id=8678371")
end
@@ -297,7 +297,7 @@ class ArtistTest < ActiveSupport::TestCase
setup do
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
FactoryBot.create(:artist, :name => "hammer_(sunset_beach)", :url_string => "http://twitter.com/hamaororon")
FactoryBot.create(:artist, :name => "haruyama_kazunori", :url_string => "https://twitter.com/kazuharoom")
FactoryBot.create(:artist, :name => "haruyama_kazunori", :url_string => "https://twitter.com/kazuharoom")
end
should "find the correct artist for twitter.com sources" do

View File

@@ -121,7 +121,7 @@ class ArtistUrlTest < ActiveSupport::TestCase
should "normalize deviant art artist urls" do
url = FactoryBot.create(:artist_url, :url => "https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484")
assert_equal("http://www.deviantart.com/aeror404/", url.normalized_url)
assert_equal("http://www.deviantart.com/aeror404/", url.normalized_url)
end
should "normalize nico seiga artist urls" do

View File

@@ -64,11 +64,11 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
context "on approval" do
setup do
@post = create(:post, tag_string: "foo aaa")
@script = %q(
@script = '
create alias foo -> bar
create implication bar -> baz
mass update aaa -> bbb
)
'
@bur = FactoryBot.create(:bulk_update_request, :script => @script)
@bur.approve!(@admin)

View File

@@ -19,7 +19,7 @@ class CloudflareServiceTest < ActiveSupport::TestCase
should "make calls to cloudflare's api" do
subject.delete("md5", "png")
assert_requested(:delete, "https://api.cloudflare.com/client/v4/zones/123/purge_cache", times: 1) do |req|
assert_requested(:delete, "https://api.cloudflare.com/client/v4/zones/123/purge_cache", times: 1) do |req|
req.body =~ /danbooru\.donmai\.us/ && req.body =~ /safebooru\.donmai\.us/ && req.body =~ /sample/ && req.body =~ /preview/
end
end

View File

@@ -23,7 +23,7 @@ class DmailTest < ActiveSupport::TestCase
end
should "not validate" do
assert_difference("Dmail.count", 2)do
assert_difference("Dmail.count", 2) do
Dmail.create_split(from: @spammer, to: @recipient, title: "spam", body: "wonderful spam")
assert(@recipient.dmails.last.is_spam?)
end
@@ -70,7 +70,7 @@ class DmailTest < ActiveSupport::TestCase
@dmail = FactoryBot.create(:dmail, :owner => @recipient, :body => "banned word here", :to => @recipient)
end
assert_equal(false, !!@recipient.dmail_filter.filtered?(@dmail))
assert_equal(false, @recipient.dmail_filter.filtered?(@dmail))
assert_equal(false, @dmail.is_read?)
assert_equal(true, @recipient.has_mail?)
end

View File

@@ -10,7 +10,7 @@ module Downloads
end
teardown do
ENV["SKIP_CLOUDFLARE_CHECK"] = nil
ENV["SKIP_CLOUDFLARE_CHECK"] = nil
end
context "for a banned IP" do
@@ -59,7 +59,7 @@ module Downloads
HTTParty.expects(:get).twice.multiple_yields(chunk, bomb).then.multiple_yields(chunk, chunk).returns(resp)
@download.stubs(:is_cloudflare?).returns(false)
tempfile, _ = @download.download!
tempfile, _strategy = @download.download!
assert_equal("aa", tempfile.read)
end
@@ -78,7 +78,7 @@ module Downloads
should "correctly save the file when following 302 redirects" do
download = Downloads::File.new("https://yande.re/post/show/578014")
file, strategy = download.download!(url: download.preview_url)
file, strategy = download.download!(url: download.preview_url)
assert_equal(19134, file.size)
end
end

View File

@@ -109,7 +109,6 @@ module Downloads
assert_not_rewritten(@file_url)
assert_downloaded(@file_size, @file_url)
end
end
context "downloading a background image" do
@@ -157,9 +156,9 @@ module Downloads
should "capture the data" do
assert_equal(2, @download.data[:ugoira_frame_data].size)
if @download.data[:ugoira_frame_data][0]["file"]
assert_equal([{"file"=>"000000.jpg", "delay"=>125}, {"file"=>"000001.jpg", "delay"=>125}], @download.data[:ugoira_frame_data])
assert_equal([{"file" => "000000.jpg", "delay" => 125}, {"file" => "000001.jpg", "delay" => 125}], @download.data[:ugoira_frame_data])
else
assert_equal([{"delay_msec"=>125}, {"delay_msec"=>125}], @download.data[:ugoira_frame_data])
assert_equal([{"delay_msec" => 125}, {"delay_msec" => 125}], @download.data[:ugoira_frame_data])
end
end
end

View File

@@ -4,7 +4,7 @@ module Downloads
class TumblrTest < ActiveSupport::TestCase
# Currently there's no way to obtain the raw version of these images,
# so we have to change the tests to validate against the 1280 version
context "a download for a tumblr 500 sample" do
should "instead download the 1280 version" do
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key

View File

@@ -35,7 +35,7 @@ class FavoriteTest < ActiveSupport::TestCase
should "return the fav group" do
assert_equal(@fav_group.id, FavoriteGroup.for_post(1).first.try(:id))
end
end
end
context "when the id is in the middle" do
@@ -57,7 +57,7 @@ class FavoriteTest < ActiveSupport::TestCase
should "return the fav group" do
assert_equal(@fav_group.id, FavoriteGroup.for_post(1).first.try(:id))
end
end
end
end
@@ -68,7 +68,7 @@ class FavoriteTest < ActiveSupport::TestCase
end
should "remove it from all favorite groups" do
assert_equal("#{@post.id}", @fav_group.post_ids)
assert_equal(@post.id.to_s, @fav_group.post_ids)
@post.expunge!
@fav_group.reload
assert_equal("", @fav_group.post_ids)

View File

@@ -89,7 +89,7 @@ class ForumPostTest < ActiveSupport::TestCase
setup do
CurrentUser.user = FactoryBot.create(:moderator_user)
end
should "update the topic's updated_at timestamp" do
@topic.reload
assert_equal(@posts[-1].updated_at.to_i, @topic.updated_at.to_i)
@@ -147,7 +147,7 @@ class ForumPostTest < ActiveSupport::TestCase
3.times do
posts << FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
end
# updating the original post
travel(1.second) do
posts.first.update(body: "xxx")

View File

@@ -49,7 +49,7 @@ class ForumTopicTest < ActiveSupport::TestCase
context "that postdates the topic" do
setup do
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 2.days.from_now)
end
end
should "return true" do
assert_equal(true, @topic.read_by?(@user))
@@ -78,7 +78,7 @@ class ForumTopicTest < ActiveSupport::TestCase
context "that postdates the topic" do
setup do
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 1.days.from_now)
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 1.day.from_now)
end
should "return true" do
@@ -128,7 +128,7 @@ class ForumTopicTest < ActiveSupport::TestCase
should "create a matching forum post" do
assert_difference(["ForumTopic.count", "ForumPost.count"], 1) do
@topic = FactoryBot.create(:forum_topic, :title => "abc", :original_post_attributes => {:body => "abc"})
end
end
end
end

View File

@@ -1,5 +1,3 @@
# encoding: utf-8
require 'test_helper'
class PoolTest < ActiveSupport::TestCase

View File

@@ -62,7 +62,7 @@ class PostArchiveTest < ActiveSupport::TestCase
should "also create a version" do
assert_equal(1, @post.versions.size)
@version = @post.versions.sort_by(&:id).last
@version = @post.versions.max_by(&:id)
assert_equal("aaa bbb ccc", @version.tags)
assert_equal(@post.rating, @version.rating)
assert_equal(@post.parent_id, @version.parent_id)
@@ -109,7 +109,7 @@ class PostArchiveTest < ActiveSupport::TestCase
should "also create a version" do
assert_equal(2, @post.versions.size)
@version = @post.versions.sort_by(&:id).last
@version = @post.versions.max_by(&:id)
assert_equal("bbb ccc xxx", @version.tags)
assert_equal("q", @version.rating)
assert_equal("", @version.source)
@@ -127,14 +127,14 @@ class PostArchiveTest < ActiveSupport::TestCase
should "should create a version if the rating changes" do
assert_difference("@post.versions.size", 1) do
@post.update(rating: "s")
assert_equal("s", @post.versions.sort_by(&:id).last.rating)
assert_equal("s", @post.versions.max_by(&:id).rating)
end
end
should "should create a version if the source changes" do
assert_difference("@post.versions.size", 1) do
@post.update(source: "blah")
assert_equal("blah", @post.versions.sort_by(&:id).last.source)
assert_equal("blah", @post.versions.max_by(&:id).source)
end
end
@@ -142,14 +142,14 @@ class PostArchiveTest < ActiveSupport::TestCase
assert_difference("@post.versions.size", 1) do
@parent = FactoryBot.create(:post)
@post.update(parent_id: @parent.id)
assert_equal(@parent.id, @post.versions.sort_by(&:id).last.parent_id)
assert_equal(@parent.id, @post.versions.max_by(&:id).parent_id)
end
end
should "should create a version if the tags change" do
assert_difference("@post.versions.size", 1) do
@post.update(tag_string: "blah")
assert_equal("blah", @post.versions.sort_by(&:id).last.tags)
assert_equal("blah", @post.versions.max_by(&:id).tags)
end
end
end

View File

@@ -38,7 +38,7 @@ class PostFlagTest < ActiveSupport::TestCase
should "not be able to flag a post more than twice" do
assert_difference(-> { PostFlag.count }, 1) do
as(@bob) do
@post_flag = PostFlag.create(post: @post, reason: "aaa", is_resolved: false)
@post_flag = PostFlag.create(post: @post, reason: "aaa", is_resolved: false)
end
end

View File

@@ -25,7 +25,7 @@ class PostPrunerTest < ActiveSupport::TestCase
def teardown
super
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end

View File

@@ -301,7 +301,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "Deleting a post with" do
context "a parent" do
should "not reassign favorites to the parent by default" do
@@ -716,7 +716,6 @@ class PostTest < ActiveSupport::TestCase
end
context "tagged with a metatag" do
context "for typing a tag" do
setup do
@post = FactoryBot.create(:post, tag_string: "char:hoge")
@@ -828,14 +827,14 @@ class PostTest < ActiveSupport::TestCase
should "add the post to the favgroup" do
assert_equal(1, @favgroup.reload.post_count)
assert_equal(true, !!@favgroup.contains?(@post.id))
assert_equal(true, @favgroup.contains?(@post.id))
end
should "remove the post from the favgroup" do
@post.update(:tag_string => "-favgroup:#{@favgroup.id}")
assert_equal(0, @favgroup.reload.post_count)
assert_equal(false, !!@favgroup.contains?(@post.id))
assert_equal(false, @favgroup.contains?(@post.id))
end
end
@@ -1814,7 +1813,7 @@ class PostTest < ActiveSupport::TestCase
setup do
mock_pool_archive_service!
end
should "return posts for the age:<1minute tag" do
post = FactoryBot.create(:post)
assert_tag_match([post], "age:<1minute")
@@ -2261,7 +2260,7 @@ class PostTest < ActiveSupport::TestCase
context "labeled" do
should "work" do
SavedSearch.expects(:post_ids_for).with(CurrentUser.id, label: "zzz").returns([@post1.id])
assert_tag_match([@post1], "search:zzz")
assert_tag_match([@post1], "search:zzz")
end
end
@@ -2275,7 +2274,7 @@ class PostTest < ActiveSupport::TestCase
context "all" do
should "work" do
SavedSearch.expects(:post_ids_for).with(CurrentUser.id).returns([@post1.id, @post2.id])
assert_tag_match([@post2, @post1], "search:all")
assert_tag_match([@post2, @post1], "search:all")
end
end
end
@@ -2348,9 +2347,9 @@ class PostTest < ActiveSupport::TestCase
fav_count: n,
file_size: 1.megabyte * n,
# posts[0] is portrait, posts[1] is landscape. posts[1].mpixels > posts[0].mpixels.
image_height: 100*n*n,
image_width: 100*(3-n)*n,
tag_string: tags[n-1],
image_height: 100 * n * n,
image_width: 100 * (3 - n) * n,
tag_string: tags[n - 1]
)
FactoryBot.create(:artist_commentary, post: p)
@@ -2480,7 +2479,7 @@ class PostTest < ActiveSupport::TestCase
FactoryBot.create(:super_voter, user: @user)
@post = FactoryBot.create(:post)
end
should "account for magnitude" do
CurrentUser.scoped(@user, "127.0.0.1") do
assert_nothing_raised {@post.vote!("up")}

View File

@@ -24,7 +24,7 @@ class PostViewCountServiceTest < ActiveSupport::TestCase
setup do
subject.stubs(:fetch_rank).returns([[@post.id, 1]])
end
should "return the posts" do
posts = subject.popular_posts
assert_equal(@post.id, posts[0].id)

View File

@@ -122,4 +122,3 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
end
end
end

View File

@@ -35,11 +35,11 @@ module Sources
end
should "get the tags" do
assert(@site_1.tags.size > 0)
assert_not(@site_1.tags.empty?)
first_tag = @site_1.tags.first
assert_equal(["アニメ", "https://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
assert(@site_2.tags.size > 0)
assert_not(@site_2.tags.empty?)
first_tag = @site_2.tags.first
assert_equal(["アニメ", "https://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
end

View File

@@ -2,7 +2,7 @@ require 'test_helper'
module Sources
class PawooTest < ActiveSupport::TestCase
context "The source site for a https://pawoo.net/web/status/$id url" do
context "The source site for a https://pawoo.net/web/status/$id url" do
setup do
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
@site = Sources::Strategies.find("https://pawoo.net/web/statuses/1202176")
@@ -31,7 +31,7 @@ module Sources
end
end
context "The source site for a https://pawoo.net/$user/$id url" do
context "The source site for a https://pawoo.net/$user/$id url" do
setup do
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
@site = Sources::Strategies.find("https://pawoo.net/@evazion/19451018")
@@ -82,7 +82,7 @@ module Sources
end
end
context "The source site for a https://img.pawoo.net/ url" do
context "The source site for a https://img.pawoo.net/ url" do
setup do
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
@url = "https://img.pawoo.net/media_attachments/files/001/298/028/original/55a6fd252778454b.mp4"

View File

@@ -59,9 +59,9 @@ module Sources
should "capture the frame data" do
assert_equal(2, @site.ugoira_frame_data.size)
if @site.ugoira_frame_data[0]["file"]
assert_equal([{"file"=>"000000.jpg", "delay"=>125}, {"file"=>"000001.jpg", "delay"=>125}], @site.ugoira_frame_data)
assert_equal([{"file" => "000000.jpg", "delay" => 125}, {"file" => "000001.jpg", "delay" => 125}], @site.ugoira_frame_data)
else
assert_equal([{"delay_msec"=>125}, {"delay_msec"=>125}], @site.ugoira_frame_data)
assert_equal([{"delay_msec" => 125}, {"delay_msec" => 125}], @site.ugoira_frame_data)
end
end
end
@@ -171,7 +171,7 @@ module Sources
should "get the full size image url" do
assert_equal("https://i.pximg.net/img-original/img/2017/08/18/00/09/21/64476642_p0.jpg", @site.image_url)
end
end
should "get the full size image url for the canonical url" do
assert_equal("https://i.pximg.net/img-original/img/2017/08/18/00/09/21/64476642_p0.jpg", @site.canonical_url)
@@ -223,7 +223,7 @@ module Sources
"mutsu_(kantai_collection)" => "陸奥",
"fate/grand_order" => "Fate/GrandOrder",
"fate" => "",
"foo" => "",
"foo" => ""
}
tags.each do |tag, other_names|

View File

@@ -213,7 +213,7 @@ module Sources
should "get the tags" do
tags = [
%w[foo https://twitter.com/hashtag/foo],
%w[ホワイトデー https://twitter.com/hashtag/ホワイトデー],
%w[ホワイトデー https://twitter.com/hashtag/ホワイトデー]
]
assert_equal(tags, @site.tags)

View File

@@ -24,7 +24,7 @@ class TokenBucketTest < ActiveSupport::TestCase
should "work" do
@user.token_bucket.consume!
assert_operator(@user.token_bucket.token_count, :<, 1)
@user.reload
@user.reload
assert_operator(@user.token_bucket.token_count, :<, 1)
end
end

View File

@@ -28,7 +28,7 @@ class UserFeedbackTest < ActiveSupport::TestCase
assert_equal(dmail, user.dmails.last.body)
end
end
should "not validate if the creator is the user" do
gold_user = FactoryBot.create(:gold_user)
CurrentUser.user = gold_user

View File

@@ -88,7 +88,7 @@ class UserTest < ActiveSupport::TestCase
@user.update_column(:created_at, 1.year.ago)
assert(@user.can_comment?)
assert(!@user.is_comment_limited?)
(Danbooru.config.member_comment_limit).times do
Danbooru.config.member_comment_limit.times do
FactoryBot.create(:comment)
end
assert(@user.is_comment_limited?)