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

@@ -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?)