Raise error on unpermitted params.
Fail loudly if we forget to whitelist a param instead of silently ignoring it. misc models: convert to strong params. artist commentaries: convert to strong params. * Disallow changing or setting post_id to a nonexistent post. artists: convert to strong params. * Disallow setting `is_banned` in create/update actions. Changing it this way instead of with the ban/unban actions would leave the artist in a partially banned state. bans: convert to strong params. * Disallow changing the user_id after the ban has been created. comments: convert to strong params. favorite groups: convert to strong params. news updates: convert to strong params. post appeals: convert to strong params. post flags: convert to strong params. * Disallow users from setting the `is_deleted` / `is_resolved` flags. ip bans: convert to strong params. user feedbacks: convert to strong params. * Disallow users from setting `disable_dmail_notification` when creating feedbacks. * Disallow changing the user_id after the feedback has been created. notes: convert to strong params. wiki pages: convert to strong params. * Also fix non-Builders being able to delete wiki pages. saved searches: convert to strong params. pools: convert to strong params. * Disallow setting `post_count` or `is_deleted` in create/update actions. janitor trials: convert to strong params. post disapprovals: convert to strong params. * Factor out quick-mod bar to shared partial. * Fix quick-mod bar to use `Post#is_approvable?` to determine visibility of Approve button. dmail filters: convert to strong params. password resets: convert to strong params. user name change requests: convert to strong params. posts: convert to strong params. users: convert to strong params. * Disallow setting password_hash, last_logged_in_at, last_forum_read_at, has_mail, and dmail_filter_attributes[user_id]. * Remove initialize_default_image_size (dead code). uploads: convert to strong params. * Remove `initialize_status` because status already defaults to pending in the database. tag aliases/implications: convert to strong params. tags: convert to strong params. forum posts: convert to strong params. * Disallow changing the topic_id after creating the post. * Disallow setting is_deleted (destroy/undelete actions should be used instead). * Remove is_sticky / is_locked (nonexistent attributes). forum topics: convert to strong params. * merges https://github.com/evazion/danbooru/tree/wip-rails-5.1 * lock pg gem to 0.21 (1.0.0 is incompatible with rails 5.1.4) * switch to factorybot and change all references Co-authored-by: r888888888 <r888888888@gmail.com> Co-authored-by: evazion <noizave@gmail.com> add diffs
This commit is contained in:
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
context "The alias and implication importer" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:admin_user)
|
||||
CurrentUser.user = FactoryBot.create(:admin_user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
@@ -66,9 +66,9 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "rename an aliased tag's artist entry and wiki page" do
|
||||
tag1 = FactoryGirl.create(:tag, :name => "aaa", :category => 1)
|
||||
tag2 = FactoryGirl.create(:tag, :name => "bbb")
|
||||
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
|
||||
tag1 = FactoryBot.create(:tag, :name => "aaa", :category => 1)
|
||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||
artist = FactoryBot.create(:artist, :name => "aaa", :notes => "testing")
|
||||
@importer = AliasAndImplicationImporter.new("create alias aaa -> bbb", "", "1")
|
||||
@importer.process!
|
||||
artist.reload
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class ApiKeyTest < ActiveSupport::TestCase
|
||||
context "in all cases a user" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:gold_user, :name => "abcdef")
|
||||
@user = FactoryBot.create(:gold_user, :name => "abcdef")
|
||||
@api_key = ApiKey.generate!(@user)
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class ApplicationRecordTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@tags = FactoryGirl.create_list(:tag, 3, post_count: 1)
|
||||
@tags = FactoryBot.create_list(:tag, 3, post_count: 1)
|
||||
end
|
||||
|
||||
context "ApplicationRecord#search" do
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class ArtistCommentaryTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -13,21 +13,21 @@ class ArtistCommentaryTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "A post should not have more than one commentary" do
|
||||
post = FactoryGirl.create(:post)
|
||||
post = FactoryBot.create(:post)
|
||||
|
||||
assert_raise(ActiveRecord::RecordInvalid) do
|
||||
FactoryGirl.create(:artist_commentary, post_id: post.id)
|
||||
FactoryGirl.create(:artist_commentary, post_id: post.id)
|
||||
FactoryBot.create(:artist_commentary, post_id: post.id)
|
||||
FactoryBot.create(:artist_commentary, post_id: post.id)
|
||||
end
|
||||
end
|
||||
|
||||
context "An artist commentary" do
|
||||
context "when searched" do
|
||||
setup do
|
||||
@post1 = FactoryGirl.create(:post, tag_string: "artcomm1")
|
||||
@post2 = FactoryGirl.create(:post, tag_string: "artcomm2")
|
||||
@artcomm1 = FactoryGirl.create(:artist_commentary, post_id: @post1.id, original_title: "foo", translated_title: "bar")
|
||||
@artcomm2 = FactoryGirl.create(:artist_commentary, post_id: @post2.id, original_title: "", original_description: "", translated_title: "", translated_description: "")
|
||||
@post1 = FactoryBot.create(:post, tag_string: "artcomm1")
|
||||
@post2 = FactoryBot.create(:post, tag_string: "artcomm2")
|
||||
@artcomm1 = FactoryBot.create(:artist_commentary, post_id: @post1.id, original_title: "foo", translated_title: "bar")
|
||||
@artcomm2 = FactoryBot.create(:artist_commentary, post_id: @post2.id, original_title: "", original_description: "", translated_title: "", translated_description: "")
|
||||
end
|
||||
|
||||
should "find the correct match" do
|
||||
@@ -46,7 +46,7 @@ class ArtistCommentaryTest < ActiveSupport::TestCase
|
||||
|
||||
context "when created" do
|
||||
should "create a new version" do
|
||||
@artcomm = FactoryGirl.create(:artist_commentary, original_title: "foo")
|
||||
@artcomm = FactoryBot.create(:artist_commentary, original_title: "foo")
|
||||
|
||||
assert_equal(1, @artcomm.versions.size)
|
||||
assert_equal("foo", @artcomm.versions.last.original_title)
|
||||
@@ -55,8 +55,8 @@ class ArtistCommentaryTest < ActiveSupport::TestCase
|
||||
|
||||
context "when updated" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@artcomm = FactoryGirl.create(:artist_commentary, post_id: @post.id)
|
||||
@post = FactoryBot.create(:post)
|
||||
@artcomm = FactoryBot.create(:artist_commentary, post_id: @post.id)
|
||||
@artcomm.reload
|
||||
end
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "An artist" do
|
||||
setup do
|
||||
user = Timecop.travel(1.month.ago) {FactoryGirl.create(:user)}
|
||||
user = Timecop.travel(1.month.ago) {FactoryBot.create(:user)}
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -33,8 +33,8 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "with a matching tag alias" do
|
||||
setup do
|
||||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
@artist = FactoryGirl.create(:artist, :name => "aaa")
|
||||
@tag_alias = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
@artist = FactoryBot.create(:artist, :name => "aaa")
|
||||
end
|
||||
|
||||
should "know it has an alias" do
|
||||
@@ -48,9 +48,9 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been banned" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
@artist = FactoryGirl.create(:artist, :name => "aaa")
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa")
|
||||
@artist = FactoryBot.create(:artist, :name => "aaa")
|
||||
@admin = FactoryBot.create(:admin_user)
|
||||
CurrentUser.scoped(@admin) { @artist.ban! }
|
||||
@post.reload
|
||||
end
|
||||
@@ -88,7 +88,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
should "create a new wiki page to store any note information" do
|
||||
artist = nil
|
||||
assert_difference("WikiPage.count") do
|
||||
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
|
||||
artist = FactoryBot.create(:artist, :name => "aaa", :notes => "testing")
|
||||
end
|
||||
assert_equal("testing", artist.notes)
|
||||
assert_equal("testing", artist.wiki_page.body)
|
||||
@@ -97,8 +97,8 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when a wiki page with the same name already exists" do
|
||||
setup do
|
||||
@wiki_page = FactoryGirl.create(:wiki_page, :title => "aaa")
|
||||
@artist = FactoryGirl.build(:artist, :name => "aaa")
|
||||
@wiki_page = FactoryBot.create(:wiki_page, :title => "aaa")
|
||||
@artist = FactoryBot.build(:artist, :name => "aaa")
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
@@ -108,7 +108,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update the wiki page when notes are assigned" do
|
||||
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
|
||||
artist = FactoryBot.create(:artist, :name => "aaa", :notes => "testing")
|
||||
artist.update_attribute(:notes, "kokoko")
|
||||
artist.reload
|
||||
assert_equal("kokoko", artist.notes)
|
||||
@@ -116,33 +116,32 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "normalize its name" do
|
||||
artist = FactoryGirl.create(:artist, :name => " AAA BBB ")
|
||||
artist = FactoryBot.create(:artist, :name => " AAA BBB ")
|
||||
assert_equal("aaa_bbb", artist.name)
|
||||
end
|
||||
|
||||
should "resolve ambiguous urls" do
|
||||
bobross = FactoryGirl.create(:artist, :name => "bob_ross", :url_string => "http://artists.com/bobross/image.jpg")
|
||||
bob = FactoryGirl.create(:artist, :name => "bob", :url_string => "http://artists.com/bob/image.jpg")
|
||||
bobross = FactoryBot.create(:artist, :name => "bob_ross", :url_string => "http://artists.com/bobross/image.jpg")
|
||||
bob = FactoryBot.create(:artist, :name => "bob", :url_string => "http://artists.com/bob/image.jpg")
|
||||
matches = Artist.find_all_by_url("http://artists.com/bob/test.jpg")
|
||||
assert_equal(1, matches.size)
|
||||
assert_equal("bob", matches.first.name)
|
||||
end
|
||||
|
||||
should "parse urls" do
|
||||
artist = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg http://aaa.com")
|
||||
artist = FactoryBot.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg http://aaa.com")
|
||||
artist.reload
|
||||
assert_equal(["http://aaa.com", "http://rembrandt.com/test.jpg"], artist.urls.map(&:to_s).sort)
|
||||
end
|
||||
|
||||
should "not allow invalid urls" do
|
||||
artist = FactoryGirl.build(:artist, :url_string => "blah")
|
||||
|
||||
artist = FactoryBot.create(:artist, :url_string => "blah")
|
||||
assert_equal(false, artist.valid?)
|
||||
assert_equal(["'blah' must begin with http:// or https://"], artist.errors[:url])
|
||||
assert_equal(["Url must begin with http:// or https://"], artist.errors[:url])
|
||||
end
|
||||
|
||||
should "make sure old urls are deleted" do
|
||||
artist = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
||||
artist = FactoryBot.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
||||
artist.url_string = "http://not.rembrandt.com/test.jpg"
|
||||
artist.save
|
||||
artist.reload
|
||||
@@ -150,7 +149,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not delete urls that have not changed" do
|
||||
artist = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
||||
artist = FactoryBot.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
||||
old_url_ids = ArtistUrl.order("id").pluck(&:id)
|
||||
artist.url_string = "http://rembrandt.com/test.jpg"
|
||||
artist.save
|
||||
@@ -158,15 +157,15 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "ignore pixiv.net/ and pixiv.net/img/ url matches" do
|
||||
a1 = FactoryGirl.create(:artist, :name => "yomosaka", :url_string => "http://i2.pixiv.net/img100/img/yomosaka/27618292.jpg")
|
||||
a2 = FactoryGirl.create(:artist, :name => "niwatazumi_bf", :url_string => "http://i2.pixiv.net/img16/img/niwatazumi_bf/35488864_big_p6.jpg")
|
||||
a1 = FactoryBot.create(:artist, :name => "yomosaka", :url_string => "http://i2.pixiv.net/img100/img/yomosaka/27618292.jpg")
|
||||
a2 = FactoryBot.create(:artist, :name => "niwatazumi_bf", :url_string => "http://i2.pixiv.net/img16/img/niwatazumi_bf/35488864_big_p6.jpg")
|
||||
assert_equal([], Artist.find_all_by_url("http://i2.pixiv.net/img28/img/kyang692/35563903.jpg"))
|
||||
end
|
||||
|
||||
should "find matches by url" do
|
||||
a1 = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/x/test.jpg")
|
||||
a2 = FactoryGirl.create(:artist, :name => "subway", :url_string => "http://subway.com/x/test.jpg")
|
||||
a3 = FactoryGirl.create(:artist, :name => "minko", :url_string => "https://minko.com/x/test.jpg")
|
||||
a1 = FactoryBot.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/x/test.jpg")
|
||||
a2 = FactoryBot.create(:artist, :name => "subway", :url_string => "http://subway.com/x/test.jpg")
|
||||
a3 = FactoryBot.create(:artist, :name => "minko", :url_string => "https://minko.com/x/test.jpg")
|
||||
|
||||
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/x/test.jpg").map(&:name))
|
||||
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/x/another.jpg").map(&:name))
|
||||
@@ -176,24 +175,24 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not find duplicates" do
|
||||
FactoryGirl.create(:artist, :name => "warhol", :url_string => "http://warhol.com/x/a/image.jpg\nhttp://warhol.com/x/b/image.jpg")
|
||||
FactoryBot.create(:artist, :name => "warhol", :url_string => "http://warhol.com/x/a/image.jpg\nhttp://warhol.com/x/b/image.jpg")
|
||||
assert_equal(["warhol"], Artist.find_all_by_url("http://warhol.com/x/test.jpg").map(&:name))
|
||||
end
|
||||
|
||||
should "not include duplicate urls" do
|
||||
artist = FactoryGirl.create(:artist, :url_string => "http://foo.com http://foo.com")
|
||||
artist = FactoryBot.create(:artist, :url_string => "http://foo.com http://foo.com")
|
||||
assert_equal(["http://foo.com"], artist.url_array)
|
||||
end
|
||||
|
||||
should "hide deleted artists" do
|
||||
FactoryGirl.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg", :is_active => false)
|
||||
FactoryBot.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg", :is_active => false)
|
||||
assert_equal([], Artist.find_all_by_url("http://warhol.com/a/image.jpg").map(&:name))
|
||||
end
|
||||
|
||||
context "when finding deviantart artists" do
|
||||
setup do
|
||||
FactoryGirl.create(:artist, :name => "artgerm", :url_string => "http://artgerm.deviantart.com/")
|
||||
FactoryGirl.create(:artist, :name => "trixia", :url_string => "http://trixdraws.deviantart.com/")
|
||||
FactoryBot.create(:artist, :name => "artgerm", :url_string => "http://artgerm.deviantart.com/")
|
||||
FactoryBot.create(:artist, :name => "trixia", :url_string => "http://trixdraws.deviantart.com/")
|
||||
end
|
||||
|
||||
should "find the correct artist for page URLs" do
|
||||
@@ -221,9 +220,9 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when finding pixiv artists" do
|
||||
setup do
|
||||
FactoryGirl.create(:artist, :name => "masao",:url_string => "http://www.pixiv.net/member.php?id=32777")
|
||||
FactoryGirl.create(:artist, :name => "bkub", :url_string => "http://www.pixiv.net/member.php?id=9948")
|
||||
FactoryGirl.create(:artist, :name => "ryuura", :url_string => "http://www.pixiv.net/member.php?id=8678371")
|
||||
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
|
||||
|
||||
should "find the correct artist by looking up the profile url" do
|
||||
@@ -267,8 +266,8 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when finding nico seiga artists" do
|
||||
setup do
|
||||
FactoryGirl.create(:artist, :name => "osamari", :url_string => "http://seiga.nicovideo.jp/user/illust/7017777")
|
||||
FactoryGirl.create(:artist, :name => "hakuro109", :url_string => "http://seiga.nicovideo.jp/user/illust/16265470")
|
||||
FactoryBot.create(:artist, :name => "osamari", :url_string => "http://seiga.nicovideo.jp/user/illust/7017777")
|
||||
FactoryBot.create(:artist, :name => "hakuro109", :url_string => "http://seiga.nicovideo.jp/user/illust/16265470")
|
||||
end
|
||||
|
||||
should "find the artist by the profile" do
|
||||
@@ -284,8 +283,9 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when finding twitter artists" do
|
||||
setup do
|
||||
FactoryGirl.create(:artist, :name => "hammer_(sunset_beach)", :url_string => "http://twitter.com/hamaororon")
|
||||
FactoryGirl.create(:artist, :name => "haruyama_kazunori", :url_string => "https://twitter.com/kazuharoom")
|
||||
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")
|
||||
end
|
||||
|
||||
should "find the correct artist for twitter.com sources" do
|
||||
@@ -317,8 +317,9 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when finding pawoo artists" do
|
||||
setup do
|
||||
FactoryGirl.create(:artist, :name => "evazion", :url_string => "https://pawoo.net/@evazion")
|
||||
FactoryGirl.create(:artist, :name => "yasumo01", :url_string => "https://pawoo.net/web/accounts/28816")
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
FactoryBot.create(:artist, :name => "evazion", :url_string => "https://pawoo.net/@evazion")
|
||||
FactoryBot.create(:artist, :name => "yasumo01", :url_string => "https://pawoo.net/web/accounts/28816")
|
||||
end
|
||||
|
||||
should "find the artist" do
|
||||
@@ -336,8 +337,8 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when finding nijie artists" do
|
||||
setup do
|
||||
FactoryGirl.create(:artist, :name => "evazion", :url_string => "http://nijie.info/members.php?id=236014")
|
||||
FactoryGirl.create(:artist, :name => "728995", :url_string => "http://nijie.info/members.php?id=728995")
|
||||
FactoryBot.create(:artist, :name => "evazion", :url_string => "http://nijie.info/members.php?id=236014")
|
||||
FactoryBot.create(:artist, :name => "728995", :url_string => "http://nijie.info/members.php?id=728995")
|
||||
end
|
||||
|
||||
should "find the artist" do
|
||||
@@ -352,8 +353,8 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when finding tumblr artists" do
|
||||
setup do
|
||||
FactoryGirl.create(:artist, :name => "ilya_kuvshinov", :url_string => "http://kuvshinov-ilya.tumblr.com")
|
||||
FactoryGirl.create(:artist, :name => "j.k.", :url_string => "https://jdotkdot5.tumblr.com")
|
||||
FactoryBot.create(:artist, :name => "ilya_kuvshinov", :url_string => "http://kuvshinov-ilya.tumblr.com")
|
||||
FactoryBot.create(:artist, :name => "j.k.", :url_string => "https://jdotkdot5.tumblr.com")
|
||||
end
|
||||
|
||||
should "find the artist" do
|
||||
@@ -367,19 +368,19 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "normalize its other names" do
|
||||
artist = FactoryGirl.create(:artist, :name => "a1", :other_names_comma => "aaa, bbb, ccc ddd")
|
||||
artist = FactoryBot.create(:artist, :name => "a1", :other_names_comma => "aaa, bbb, ccc ddd")
|
||||
assert_equal("aaa, bbb, ccc_ddd", artist.other_names_comma)
|
||||
end
|
||||
|
||||
should "search on its name should return results" do
|
||||
artist = FactoryGirl.create(:artist, :name => "artist")
|
||||
artist = FactoryBot.create(:artist, :name => "artist")
|
||||
assert_not_nil(Artist.search(:name => "artist").first)
|
||||
assert_not_nil(Artist.search(:name_matches => "artist").first)
|
||||
assert_not_nil(Artist.search(:any_name_matches => "artist").first)
|
||||
end
|
||||
|
||||
should "search on other names should return matches" do
|
||||
artist = FactoryGirl.create(:artist, :name => "artist", :other_names_comma => "aaa, ccc ddd")
|
||||
artist = FactoryBot.create(:artist, :name => "artist", :other_names_comma => "aaa, ccc ddd")
|
||||
assert_nil(Artist.other_names_match("artist").first)
|
||||
assert_not_nil(Artist.other_names_match("aaa").first)
|
||||
assert_not_nil(Artist.other_names_match("ccc_ddd").first)
|
||||
@@ -391,8 +392,8 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "search on group name and return matches" do
|
||||
cat_or_fish = FactoryGirl.create(:artist, :name => "cat_or_fish")
|
||||
yuu = FactoryGirl.create(:artist, :name => "yuu", :group_name => "cat_or_fish")
|
||||
cat_or_fish = FactoryBot.create(:artist, :name => "cat_or_fish")
|
||||
yuu = FactoryBot.create(:artist, :name => "yuu", :group_name => "cat_or_fish")
|
||||
cat_or_fish.reload
|
||||
assert_equal("yuu", cat_or_fish.member_names)
|
||||
assert_not_nil(Artist.search(:name => "group:cat_or_fish").first)
|
||||
@@ -402,20 +403,20 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "search on has_tag and return matches" do
|
||||
post = FactoryGirl.create(:post, tag_string: "bkub")
|
||||
bkub = FactoryGirl.create(:artist, name: "bkub")
|
||||
none = FactoryGirl.create(:artist, name: "none")
|
||||
post = FactoryBot.create(:post, tag_string: "bkub")
|
||||
bkub = FactoryBot.create(:artist, name: "bkub")
|
||||
none = FactoryBot.create(:artist, name: "none")
|
||||
|
||||
assert_equal(bkub.id, Artist.search(has_tag: "true").first.id)
|
||||
assert_equal(none.id, Artist.search(has_tag: "false").first.id)
|
||||
end
|
||||
|
||||
should "revert to prior versions" do
|
||||
user = FactoryGirl.create(:user)
|
||||
reverter = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
reverter = FactoryBot.create(:user)
|
||||
artist = nil
|
||||
assert_difference("ArtistVersion.count") do
|
||||
artist = FactoryGirl.create(:artist, :other_names => "yyy")
|
||||
artist = FactoryBot.create(:artist, :other_names => "yyy")
|
||||
end
|
||||
|
||||
assert_difference("ArtistVersion.count") do
|
||||
@@ -433,15 +434,15 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update the category of the tag when created" do
|
||||
tag = FactoryGirl.create(:tag, :name => "abc")
|
||||
artist = FactoryGirl.create(:artist, :name => "abc")
|
||||
tag = FactoryBot.create(:tag, :name => "abc")
|
||||
artist = FactoryBot.create(:artist, :name => "abc")
|
||||
tag.reload
|
||||
assert_equal(Tag.categories.artist, tag.category)
|
||||
end
|
||||
|
||||
should "update the category of the tag when renamed" do
|
||||
tag = FactoryGirl.create(:tag, :name => "def")
|
||||
artist = FactoryGirl.create(:artist, :name => "abc")
|
||||
tag = FactoryBot.create(:tag, :name => "def")
|
||||
artist = FactoryBot.create(:artist, :name => "abc")
|
||||
artist.name = "def"
|
||||
artist.save
|
||||
tag.reload
|
||||
@@ -450,12 +451,12 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when updated" do
|
||||
setup do
|
||||
@artist = FactoryGirl.create(:artist)
|
||||
@artist = FactoryBot.create(:artist)
|
||||
@artist.stubs(:merge_version?).returns(false)
|
||||
end
|
||||
|
||||
should "create a new version" do
|
||||
assert_difference("@artist.versions.count") do
|
||||
assert_difference("ArtistVersion.count") do
|
||||
@artist.update(:url_string => "http://foo.com")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class ArtistUrlTest < ActiveSupport::TestCase
|
||||
context "An artist url" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
@@ -13,24 +13,24 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "always add a trailing slash when normalized" do
|
||||
url = FactoryGirl.create(:artist_url, :url => "http://monet.com")
|
||||
url = FactoryBot.create(:artist_url, :url => "http://monet.com")
|
||||
assert_equal("http://monet.com", url.url)
|
||||
assert_equal("http://monet.com/", url.normalized_url)
|
||||
|
||||
url = FactoryGirl.create(:artist_url, :url => "http://monet.com/")
|
||||
url = FactoryBot.create(:artist_url, :url => "http://monet.com/")
|
||||
assert_equal("http://monet.com/", url.url)
|
||||
assert_equal("http://monet.com/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalise https" do
|
||||
url = FactoryGirl.create(:artist_url, :url => "https://google.com")
|
||||
url = FactoryBot.create(:artist_url, :url => "https://google.com")
|
||||
assert_equal("https://google.com", url.url)
|
||||
assert_equal("http://google.com/", url.normalized_url)
|
||||
end
|
||||
|
||||
context "normalize twitter profile urls" do
|
||||
setup do
|
||||
@url = FactoryGirl.create(:artist_url, :url => "https://twitter.com/BLAH")
|
||||
@url = FactoryBot.create(:artist_url, :url => "https://twitter.com/BLAH")
|
||||
end
|
||||
|
||||
should "downcase the url" do
|
||||
@@ -39,36 +39,36 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "normalize fc2 urls" do
|
||||
url = FactoryGirl.create(:artist_url, :url => "http://blog55.fc2.com/monet")
|
||||
url = FactoryBot.create(:artist_url, :url => "http://blog55.fc2.com/monet")
|
||||
assert_equal("http://blog55.fc2.com/monet", url.url)
|
||||
assert_equal("http://blog.fc2.com/monet/", url.normalized_url)
|
||||
|
||||
url = FactoryGirl.create(:artist_url, :url => "http://blog-imgs-55.fc2.com/monet")
|
||||
url = FactoryBot.create(:artist_url, :url => "http://blog-imgs-55.fc2.com/monet")
|
||||
assert_equal("http://blog-imgs-55.fc2.com/monet", url.url)
|
||||
assert_equal("http://blog.fc2.com/monet/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize nico seiga artist urls" do
|
||||
url = FactoryGirl.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/1826959")
|
||||
url = FactoryBot.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/1826959")
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/1826959/", url.normalized_url)
|
||||
|
||||
url = FactoryGirl.create(:artist_url, :url => "http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
url = FactoryBot.create(:artist_url, :url => "http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize hentai foundry artist urls" do
|
||||
url = FactoryGirl.create(:artist_url, :url => "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg")
|
||||
url = FactoryBot.create(:artist_url, :url => "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg")
|
||||
assert_equal("http://pictures.hentai-foundry.com/a/AnimeFlux/219123.jpg/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize pixiv urls" do
|
||||
url = FactoryGirl.create(:artist_url, :url => "https://i.pximg.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png")
|
||||
url = FactoryBot.create(:artist_url, :url => "https://i.pximg.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png")
|
||||
assert_equal("https://i.pximg.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png", url.url)
|
||||
assert_equal("http://www.pixiv.net/member.php?id=339253/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize twitter urls" do
|
||||
url = FactoryGirl.create(:artist_url, :url => "https://twitter.com/MONET/status/12345")
|
||||
url = FactoryBot.create(:artist_url, :url => "https://twitter.com/MONET/status/12345")
|
||||
assert_equal("https://twitter.com/MONET/status/12345", url.url)
|
||||
assert_equal("http://twitter.com/monet/status/12345/", url.normalized_url)
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class BanTest < ActiveSupport::TestCase
|
||||
context "A ban" do
|
||||
context "created by an admin" do
|
||||
setup do
|
||||
@banner = FactoryGirl.create(:admin_user)
|
||||
@banner = FactoryBot.create(:admin_user)
|
||||
CurrentUser.user = @banner
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -16,42 +16,42 @@ class BanTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "set the is_banned flag on the user" do
|
||||
user = FactoryGirl.create(:user)
|
||||
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:user)
|
||||
ban = FactoryBot.build(:ban, :user => user, :banner => @banner)
|
||||
ban.save
|
||||
user.reload
|
||||
assert(user.is_banned?)
|
||||
end
|
||||
|
||||
should "not be valid against another admin" do
|
||||
user = FactoryGirl.create(:admin_user)
|
||||
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:admin_user)
|
||||
ban = FactoryBot.build(:ban, :user => user, :banner => @banner)
|
||||
ban.save
|
||||
assert(ban.errors.any?)
|
||||
end
|
||||
|
||||
should "be valid against anyone who is not an admin" do
|
||||
user = FactoryGirl.create(:moderator_user)
|
||||
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:moderator_user)
|
||||
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
|
||||
assert(ban.errors.empty?)
|
||||
|
||||
user = FactoryGirl.create(:contributor_user)
|
||||
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:contributor_user)
|
||||
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
|
||||
assert(ban.errors.empty?)
|
||||
|
||||
user = FactoryGirl.create(:gold_user)
|
||||
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:gold_user)
|
||||
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
|
||||
assert(ban.errors.empty?)
|
||||
|
||||
user = FactoryGirl.create(:user)
|
||||
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:user)
|
||||
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
|
||||
assert(ban.errors.empty?)
|
||||
end
|
||||
end
|
||||
|
||||
context "created by a moderator" do
|
||||
setup do
|
||||
@banner = FactoryGirl.create(:moderator_user)
|
||||
@banner = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @banner
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -63,47 +63,47 @@ class BanTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not be valid against an admin or moderator" do
|
||||
user = FactoryGirl.create(:admin_user)
|
||||
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:admin_user)
|
||||
ban = FactoryBot.build(:ban, :user => user, :banner => @banner)
|
||||
ban.save
|
||||
assert(ban.errors.any?)
|
||||
|
||||
user = FactoryGirl.create(:moderator_user)
|
||||
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:moderator_user)
|
||||
ban = FactoryBot.build(:ban, :user => user, :banner => @banner)
|
||||
ban.save
|
||||
assert(ban.errors.any?)
|
||||
end
|
||||
|
||||
should "be valid against anyone who is not an admin or a moderator" do
|
||||
user = FactoryGirl.create(:contributor_user)
|
||||
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:contributor_user)
|
||||
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
|
||||
assert(ban.errors.empty?)
|
||||
|
||||
user = FactoryGirl.create(:gold_user)
|
||||
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:gold_user)
|
||||
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
|
||||
assert(ban.errors.empty?)
|
||||
|
||||
user = FactoryGirl.create(:user)
|
||||
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
|
||||
user = FactoryBot.create(:user)
|
||||
ban = FactoryBot.create(:ban, :user => user, :banner => @banner)
|
||||
assert(ban.errors.empty?)
|
||||
end
|
||||
end
|
||||
|
||||
should "initialize the expiration date" do
|
||||
user = FactoryGirl.create(:user)
|
||||
admin = FactoryGirl.create(:admin_user)
|
||||
user = FactoryBot.create(:user)
|
||||
admin = FactoryBot.create(:admin_user)
|
||||
CurrentUser.scoped(admin) do
|
||||
ban = FactoryGirl.create(:ban, :user => user, :banner => admin)
|
||||
ban = FactoryBot.create(:ban, :user => user, :banner => admin)
|
||||
assert_not_nil(ban.expires_at)
|
||||
end
|
||||
end
|
||||
|
||||
should "update the user's feedback" do
|
||||
user = FactoryGirl.create(:user)
|
||||
admin = FactoryGirl.create(:admin_user)
|
||||
user = FactoryBot.create(:user)
|
||||
admin = FactoryBot.create(:admin_user)
|
||||
assert(user.feedback.empty?)
|
||||
CurrentUser.scoped(admin) do
|
||||
FactoryGirl.create(:ban, :user => user, :banner => admin)
|
||||
FactoryBot.create(:ban, :user => user, :banner => admin)
|
||||
end
|
||||
assert(!user.feedback.empty?)
|
||||
assert_equal("negative", user.feedback.last.category)
|
||||
@@ -112,11 +112,11 @@ class BanTest < ActiveSupport::TestCase
|
||||
|
||||
context "Searching for a ban" do
|
||||
should "find a given ban" do
|
||||
CurrentUser.user = FactoryGirl.create(:admin_user)
|
||||
CurrentUser.user = FactoryBot.create(:admin_user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
user = FactoryGirl.create(:user)
|
||||
ban = FactoryGirl.create(:ban, user: user)
|
||||
user = FactoryBot.create(:user)
|
||||
ban = FactoryBot.create(:ban, user: user)
|
||||
params = {
|
||||
user_name: user.name,
|
||||
banner_name: ban.banner.name,
|
||||
@@ -133,10 +133,10 @@ class BanTest < ActiveSupport::TestCase
|
||||
|
||||
context "by user id" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@admin = FactoryBot.create(:admin_user)
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -146,7 +146,7 @@ class BanTest < ActiveSupport::TestCase
|
||||
|
||||
context "when only expired bans exist" do
|
||||
setup do
|
||||
@ban = FactoryGirl.create(:ban, :user => @user, :banner => @admin, :duration => -1)
|
||||
@ban = FactoryBot.create(:ban, :user => @user, :banner => @admin, :duration => -1)
|
||||
end
|
||||
|
||||
should "not return expired bans" do
|
||||
@@ -156,7 +156,7 @@ class BanTest < ActiveSupport::TestCase
|
||||
|
||||
context "when active bans still exist" do
|
||||
setup do
|
||||
@ban = FactoryGirl.create(:ban, :user => @user, :banner => @admin, :duration => 1)
|
||||
@ban = FactoryBot.create(:ban, :user => @user, :banner => @admin, :duration => 1)
|
||||
end
|
||||
|
||||
should "return active bans" do
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class BulkRevertTest < ActiveSupport::TestCase
|
||||
context "#find_post_versions" do
|
||||
subject do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
BulkRevert.new
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
context "a bulk update request" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@admin = FactoryBot.create(:admin_user)
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -20,7 +20,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
create implication bar -> baz
|
||||
)
|
||||
|
||||
@bur = FactoryGirl.create(:bulk_update_request, :script => @script)
|
||||
@bur = FactoryBot.create(:bulk_update_request, :script => @script)
|
||||
@bur.approve!(@admin)
|
||||
|
||||
@ta = TagAlias.where(:antecedent_name => "foo", :consequent_name => "bar").first
|
||||
@@ -54,8 +54,8 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has an invalid alias" do
|
||||
setup do
|
||||
@alias1 = FactoryGirl.create(:tag_alias)
|
||||
@req = FactoryGirl.build(:bulk_update_request, :script => "create alias bbb -> aaa")
|
||||
@alias1 = FactoryBot.create(:tag_alias)
|
||||
@req = FactoryBot.build(:bulk_update_request, :script => "create alias bbb -> aaa")
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
@@ -68,9 +68,9 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
|
||||
context "for an implication that is redundant with an existing implication" do
|
||||
should "not validate" do
|
||||
FactoryGirl.create(:tag_implication, :antecedent_name => "a", :consequent_name => "b")
|
||||
FactoryGirl.create(:tag_implication, :antecedent_name => "b", :consequent_name => "c")
|
||||
bur = FactoryGirl.build(:bulk_update_request, :script => "imply a -> c")
|
||||
FactoryBot.create(:tag_implication, :antecedent_name => "a", :consequent_name => "b")
|
||||
FactoryBot.create(:tag_implication, :antecedent_name => "b", :consequent_name => "c")
|
||||
bur = FactoryBot.build(:bulk_update_request, :script => "imply a -> c")
|
||||
bur.save
|
||||
|
||||
assert_equal(["Error: a already implies c through another implication (create implication a -> c)"], bur.errors.full_messages)
|
||||
@@ -79,8 +79,8 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
|
||||
context "for an implication that is redundant with another implication in the same BUR" do
|
||||
setup do
|
||||
FactoryGirl.create(:tag_implication, :antecedent_name => "b", :consequent_name => "c")
|
||||
@bur = FactoryGirl.build(:bulk_update_request, :script => "imply a -> b\nimply a -> c")
|
||||
FactoryBot.create(:tag_implication, :antecedent_name => "b", :consequent_name => "c")
|
||||
@bur = FactoryBot.build(:bulk_update_request, :script => "imply a -> b\nimply a -> c")
|
||||
@bur.save
|
||||
end
|
||||
|
||||
@@ -98,7 +98,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
context "for a `category <tag> -> type` change" do
|
||||
should "work" do
|
||||
tag = Tag.find_or_create_by_name("tagme")
|
||||
bur = FactoryGirl.create(:bulk_update_request, :script => "category tagme -> meta")
|
||||
bur = FactoryBot.create(:bulk_update_request, :script => "category tagme -> meta")
|
||||
bur.approve!(@admin)
|
||||
|
||||
assert_equal(Tag.categories.meta, tag.reload.category)
|
||||
@@ -107,9 +107,9 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
|
||||
context "with an associated forum topic" do
|
||||
setup do
|
||||
@topic = FactoryGirl.create(:forum_topic, :title => "[bulk] hoge")
|
||||
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
||||
@req = FactoryGirl.create(:bulk_update_request, :script => "create alias AAA -> BBB", :forum_topic_id => @topic.id, :forum_post_id => @post.id, :title => "[bulk] hoge")
|
||||
@topic = FactoryBot.create(:forum_topic, :title => "[bulk] hoge")
|
||||
@post = FactoryBot.create(:forum_post, :topic_id => @topic.id)
|
||||
@req = FactoryBot.create(:bulk_update_request, :script => "create alias AAA -> BBB", :forum_topic_id => @topic.id, :forum_post_id => @post.id, :title => "[bulk] hoge")
|
||||
end
|
||||
|
||||
should "gracefully handle validation errors during approval" do
|
||||
@@ -169,8 +169,8 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
|
||||
context "when searching" do
|
||||
setup do
|
||||
@bur1 = FactoryGirl.create(:bulk_update_request, title: "foo", script: "create alias aaa -> bbb", user_id: @admin.id)
|
||||
@bur2 = FactoryGirl.create(:bulk_update_request, title: "bar", script: "create implication bbb -> ccc", user_id: @admin.id)
|
||||
@bur1 = FactoryBot.create(:bulk_update_request, title: "foo", script: "create alias aaa -> bbb", user_id: @admin.id)
|
||||
@bur2 = FactoryBot.create(:bulk_update_request, title: "bar", script: "create implication bbb -> ccc", user_id: @admin.id)
|
||||
@bur1.approve!(@admin)
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class CommentTest < ActiveSupport::TestCase
|
||||
context "A comment" do
|
||||
setup do
|
||||
user = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -15,16 +15,16 @@ class CommentTest < ActiveSupport::TestCase
|
||||
|
||||
context "that mentions a user" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post = FactoryBot.create(:post)
|
||||
Danbooru.config.stubs(:member_comment_limit).returns(100)
|
||||
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
|
||||
end
|
||||
|
||||
context "added in an edit" do
|
||||
should "dmail the added user" do
|
||||
@user1 = FactoryGirl.create(:user)
|
||||
@user2 = FactoryGirl.create(:user)
|
||||
@comment = FactoryGirl.create(:comment, :post_id => @post.id, :body => "@#{@user1.name}")
|
||||
@user1 = FactoryBot.create(:user)
|
||||
@user2 = FactoryBot.create(:user)
|
||||
@comment = FactoryBot.create(:comment, :post_id => @post.id, :body => "@#{@user1.name}")
|
||||
|
||||
assert_no_difference("@user1.dmails.count") do
|
||||
assert_difference("@user2.dmails.count") do
|
||||
@@ -37,32 +37,32 @@ class CommentTest < ActiveSupport::TestCase
|
||||
|
||||
context "in a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryGirl.create(:user, :created_at => 2.weeks.ago)
|
||||
@user2 = FactoryBot.create(:user, :created_at => 2.weeks.ago)
|
||||
end
|
||||
|
||||
should "not create a dmail" do
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote]")
|
||||
FactoryBot.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote] blah [quote]@#{@user2.name}[/quote]")
|
||||
FactoryBot.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote] blah [quote]@#{@user2.name}[/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:comment, :post_id => @post.id, :body => "[quote][quote]@#{@user2.name}[/quote][/quote]")
|
||||
FactoryBot.create(:comment, :post_id => @post.id, :body => "[quote][quote]@#{@user2.name}[/quote][/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 1) do
|
||||
FactoryGirl.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote] @#{@user2.name}")
|
||||
FactoryBot.create(:comment, :post_id => @post.id, :body => "[quote]@#{@user2.name}[/quote] @#{@user2.name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "outside a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryGirl.create(:user)
|
||||
@comment = FactoryGirl.build(:comment, :post_id => @post.id, :body => "Hey @#{@user2.name} check this out!")
|
||||
@user2 = FactoryBot.create(:user)
|
||||
@comment = FactoryBot.build(:comment, :post_id => @post.id, :body => "Hey @#{@user2.name} check this out!")
|
||||
end
|
||||
|
||||
should "create a dmail" do
|
||||
@@ -89,7 +89,7 @@ class CommentTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "fail creation" do
|
||||
comment = FactoryGirl.build(:comment)
|
||||
comment = FactoryBot.build(:comment)
|
||||
comment.save
|
||||
assert_equal(["You can not post comments within 1 week of sign up"], comment.errors.full_messages)
|
||||
end
|
||||
@@ -103,9 +103,9 @@ class CommentTest < ActiveSupport::TestCase
|
||||
|
||||
context "that is then deleted" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@comment = FactoryGirl.create(:comment, :post_id => @post.id)
|
||||
@comment.update({is_deleted: true}, as: :member)
|
||||
@post = FactoryBot.create(:post)
|
||||
@comment = FactoryBot.create(:comment, :post_id => @post.id)
|
||||
@comment.update(is_deleted: true)
|
||||
@post.reload
|
||||
end
|
||||
|
||||
@@ -115,59 +115,59 @@ class CommentTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "be created" do
|
||||
comment = FactoryGirl.build(:comment)
|
||||
comment = FactoryBot.build(:comment)
|
||||
comment.save
|
||||
assert(comment.errors.empty?, comment.errors.full_messages.join(", "))
|
||||
end
|
||||
|
||||
should "not validate if the post does not exist" do
|
||||
comment = FactoryGirl.build(:comment, :post_id => -1)
|
||||
comment = FactoryBot.build(:comment, :post_id => -1)
|
||||
|
||||
assert_not(comment.valid?)
|
||||
assert_equal(["must exist"], comment.errors[:post])
|
||||
end
|
||||
|
||||
should "not bump the parent post" do
|
||||
post = FactoryGirl.create(:post)
|
||||
comment = FactoryGirl.create(:comment, :do_not_bump_post => true, :post => post)
|
||||
post = FactoryBot.create(:post)
|
||||
comment = FactoryBot.create(:comment, :do_not_bump_post => true, :post => post)
|
||||
post.reload
|
||||
assert_nil(post.last_comment_bumped_at)
|
||||
|
||||
comment = FactoryGirl.create(:comment, :post => post)
|
||||
comment = FactoryBot.create(:comment, :post => post)
|
||||
post.reload
|
||||
assert_not_nil(post.last_comment_bumped_at)
|
||||
end
|
||||
|
||||
should "not bump the post after exceeding the threshold" do
|
||||
Danbooru.config.stubs(:comment_threshold).returns(1)
|
||||
p = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:comment, :post => p)
|
||||
p = FactoryBot.create(:post)
|
||||
c1 = FactoryBot.create(:comment, :post => p)
|
||||
Timecop.travel(2.seconds.from_now) do
|
||||
c2 = FactoryGirl.create(:comment, :post => p)
|
||||
c2 = FactoryBot.create(:comment, :post => p)
|
||||
end
|
||||
p.reload
|
||||
assert_equal(c1.created_at.to_s, p.last_comment_bumped_at.to_s)
|
||||
end
|
||||
|
||||
should "always record the last_commented_at properly" do
|
||||
post = FactoryGirl.create(:post)
|
||||
post = FactoryBot.create(:post)
|
||||
Danbooru.config.stubs(:comment_threshold).returns(1)
|
||||
|
||||
c1 = FactoryGirl.create(:comment, :do_not_bump_post => true, :post => post)
|
||||
c1 = FactoryBot.create(:comment, :do_not_bump_post => true, :post => post)
|
||||
post.reload
|
||||
assert_equal(c1.created_at.to_s, post.last_commented_at.to_s)
|
||||
|
||||
Timecop.travel(2.seconds.from_now) do
|
||||
c2 = FactoryGirl.create(:comment, :post => post)
|
||||
c2 = FactoryBot.create(:comment, :post => post)
|
||||
post.reload
|
||||
assert_equal(c2.created_at.to_s, post.last_commented_at.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
should "not record the user id of the voter" do
|
||||
user = FactoryGirl.create(:user)
|
||||
post = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:comment, :post => post)
|
||||
user = FactoryBot.create(:user)
|
||||
post = FactoryBot.create(:post)
|
||||
c1 = FactoryBot.create(:comment, :post => post)
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
c1.vote!("up")
|
||||
c1.reload
|
||||
@@ -176,9 +176,9 @@ class CommentTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not allow duplicate votes" do
|
||||
user = FactoryGirl.create(:user)
|
||||
post = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:comment, :post => post)
|
||||
user = FactoryBot.create(:user)
|
||||
post = FactoryBot.create(:post)
|
||||
c1 = FactoryBot.create(:comment, :post => post)
|
||||
|
||||
assert_nothing_raised { c1.vote!("down") }
|
||||
exception = assert_raises(ActiveRecord::RecordInvalid) { c1.vote!("down") }
|
||||
@@ -186,24 +186,24 @@ class CommentTest < ActiveSupport::TestCase
|
||||
assert_equal(1, CommentVote.count)
|
||||
assert_equal(-1, CommentVote.last.score)
|
||||
|
||||
c2 = FactoryGirl.create(:comment, :post => post)
|
||||
c2 = FactoryBot.create(:comment, :post => post)
|
||||
assert_nothing_raised { c2.vote!("down") }
|
||||
assert_equal(2, CommentVote.count)
|
||||
end
|
||||
|
||||
should "not allow upvotes by the creator" do
|
||||
user = FactoryGirl.create(:user)
|
||||
post = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:comment, :post => post)
|
||||
user = FactoryBot.create(:user)
|
||||
post = FactoryBot.create(:post)
|
||||
c1 = FactoryBot.create(:comment, :post => post)
|
||||
|
||||
exception = assert_raises(ActiveRecord::RecordInvalid) { c1.vote!("up") }
|
||||
assert_equal("Validation failed: You cannot upvote your own comments", exception.message)
|
||||
end
|
||||
|
||||
should "allow undoing of votes" do
|
||||
user = FactoryGirl.create(:user)
|
||||
post = FactoryGirl.create(:post)
|
||||
comment = FactoryGirl.create(:comment, :post => post)
|
||||
user = FactoryBot.create(:user)
|
||||
post = FactoryBot.create(:post)
|
||||
comment = FactoryBot.create(:comment, :post => post)
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
comment.vote!("up")
|
||||
comment.unvote!
|
||||
@@ -214,9 +214,9 @@ class CommentTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "be searchable" do
|
||||
c1 = FactoryGirl.create(:comment, :body => "aaa bbb ccc")
|
||||
c2 = FactoryGirl.create(:comment, :body => "aaa ddd")
|
||||
c3 = FactoryGirl.create(:comment, :body => "eee")
|
||||
c1 = FactoryBot.create(:comment, :body => "aaa bbb ccc")
|
||||
c2 = FactoryBot.create(:comment, :body => "aaa ddd")
|
||||
c3 = FactoryBot.create(:comment, :body => "eee")
|
||||
|
||||
matches = Comment.body_matches("aaa")
|
||||
assert_equal(2, matches.count)
|
||||
@@ -225,7 +225,7 @@ class CommentTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "default to id_desc order when searched with no options specified" do
|
||||
comms = FactoryGirl.create_list(:comment, 3)
|
||||
comms = FactoryBot.create_list(:comment, 3)
|
||||
matches = Comment.search({})
|
||||
|
||||
assert_equal([comms[2].id, comms[1].id, comms[0].id], matches.map(&:id))
|
||||
@@ -233,38 +233,38 @@ class CommentTest < ActiveSupport::TestCase
|
||||
|
||||
context "that is edited by a moderator" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@comment = FactoryGirl.create(:comment, :post_id => @post.id)
|
||||
@mod = FactoryGirl.create(:moderator_user)
|
||||
@post = FactoryBot.create(:post)
|
||||
@comment = FactoryBot.create(:comment, :post_id => @post.id)
|
||||
@mod = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @mod
|
||||
end
|
||||
|
||||
should "create a mod action" do
|
||||
assert_difference("ModAction.count") do
|
||||
@comment.update_attributes({:body => "nope"}, :as => :moderator)
|
||||
@comment.update_attributes(:body => "nope")
|
||||
end
|
||||
end
|
||||
|
||||
should "credit the moderator as the updater" do
|
||||
@comment.update({ body: "test" }, as: :moderator)
|
||||
@comment.update(body: "test")
|
||||
assert_equal(@mod.id, @comment.updater_id)
|
||||
end
|
||||
end
|
||||
|
||||
context "that is below the score threshold" do
|
||||
should "be hidden if not stickied" do
|
||||
user = FactoryGirl.create(:user, :comment_threshold => 0)
|
||||
post = FactoryGirl.create(:post)
|
||||
comment = FactoryGirl.create(:comment, :post => post, :score => -5)
|
||||
user = FactoryBot.create(:user, :comment_threshold => 0)
|
||||
post = FactoryBot.create(:post)
|
||||
comment = FactoryBot.create(:comment, :post => post, :score => -5)
|
||||
|
||||
assert_equal([comment], post.comments.hidden(user))
|
||||
assert_equal([], post.comments.visible(user))
|
||||
end
|
||||
|
||||
should "be visible if stickied" do
|
||||
user = FactoryGirl.create(:user, :comment_threshold => 0)
|
||||
post = FactoryGirl.create(:post)
|
||||
comment = FactoryGirl.create(:comment, :post => post, :score => -5, :is_sticky => true)
|
||||
user = FactoryBot.create(:user, :comment_threshold => 0)
|
||||
post = FactoryBot.create(:post)
|
||||
comment = FactoryBot.create(:comment, :post => post, :score => -5, :is_sticky => true)
|
||||
|
||||
assert_equal([], post.comments.hidden(user))
|
||||
assert_equal([comment], post.comments.visible(user))
|
||||
@@ -273,7 +273,7 @@ class CommentTest < ActiveSupport::TestCase
|
||||
|
||||
context "that is quoted" do
|
||||
should "strip [quote] tags correctly" do
|
||||
comment = FactoryGirl.create(:comment, body: <<-EOS.strip_heredoc)
|
||||
comment = FactoryBot.create(:comment, body: <<-EOS.strip_heredoc)
|
||||
paragraph one
|
||||
|
||||
[quote]
|
||||
|
||||
@@ -23,7 +23,7 @@ class CurrentUserTest < ActiveSupport::TestCase
|
||||
req = mock()
|
||||
req.stubs(:host).returns("danbooru")
|
||||
req.stubs(:params).returns({})
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.set_safe_mode(req)
|
||||
assert_equal(false, CurrentUser.safe_mode?)
|
||||
end
|
||||
@@ -33,7 +33,7 @@ class CurrentUserTest < ActiveSupport::TestCase
|
||||
req.stubs(:host).returns("danbooru")
|
||||
req.stubs(:params).returns({})
|
||||
|
||||
CurrentUser.user = FactoryGirl.create(:user, enable_safe_mode: true)
|
||||
CurrentUser.user = FactoryBot.create(:user, enable_safe_mode: true)
|
||||
CurrentUser.set_safe_mode(req)
|
||||
|
||||
assert_equal(true, CurrentUser.safe_mode?)
|
||||
@@ -42,7 +42,7 @@ class CurrentUserTest < ActiveSupport::TestCase
|
||||
|
||||
context "The current user" do
|
||||
should "be set only within the scope of the block" do
|
||||
user = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
|
||||
assert_nil(CurrentUser.user)
|
||||
assert_nil(CurrentUser.ip_addr)
|
||||
@@ -58,8 +58,8 @@ class CurrentUserTest < ActiveSupport::TestCase
|
||||
|
||||
context "A scoped current user" do
|
||||
should "reset the current user after the block has exited" do
|
||||
user1 = FactoryGirl.create(:user)
|
||||
user2 = FactoryGirl.create(:user)
|
||||
user1 = FactoryBot.create(:user)
|
||||
user2 = FactoryBot.create(:user)
|
||||
CurrentUser.user = user1
|
||||
CurrentUser.scoped(user2, nil) do
|
||||
assert_equal(user2.id, CurrentUser.user.id)
|
||||
@@ -68,8 +68,8 @@ class CurrentUserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "reset the current user even if an exception is thrown" do
|
||||
user1 = FactoryGirl.create(:user)
|
||||
user2 = FactoryGirl.create(:user)
|
||||
user1 = FactoryBot.create(:user)
|
||||
user2 = FactoryBot.create(:user)
|
||||
CurrentUser.user = user1
|
||||
assert_raises(RuntimeError) do
|
||||
CurrentUser.scoped(user2, nil) do
|
||||
|
||||
43
test/unit/dmail_filter_test.rb
Normal file
43
test/unit/dmail_filter_test.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DmailFilterTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@receiver = FactoryBot.create(:user)
|
||||
@sender = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
def create_dmail(body, title)
|
||||
CurrentUser.scoped(@sender, "127.0.0.1") do
|
||||
Dmail.create_split(:to_id => @receiver.id, :body => body, :title => title)
|
||||
end
|
||||
end
|
||||
|
||||
context "a dmail filter for a word" do
|
||||
setup do
|
||||
@dmail_filter = @receiver.create_dmail_filter(:words => "banned")
|
||||
end
|
||||
|
||||
should "filter on that word in the body" do
|
||||
create_dmail("banned", "okay")
|
||||
assert_equal(true, @receiver.dmails.last.is_read?)
|
||||
end
|
||||
|
||||
should "filter on that word in the title" do
|
||||
create_dmail("okay", "banned")
|
||||
assert_equal(true, @receiver.dmails.last.is_read?)
|
||||
end
|
||||
end
|
||||
|
||||
context "a dmail filter for a user name" do
|
||||
setup do
|
||||
@dmail_filter = @receiver.create_dmail_filter(:words => @sender.name)
|
||||
end
|
||||
|
||||
should "filter on the sender" do
|
||||
create_dmail("okay", "okay")
|
||||
assert_equal(true, @receiver.dmails.last.is_read?)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,24 +3,22 @@ require 'test_helper'
|
||||
class DmailTest < ActiveSupport::TestCase
|
||||
context "A dmail" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "1.2.3.4"
|
||||
ActionMailer::Base.delivery_method = :test
|
||||
ActionMailer::Base.perform_deliveries = true
|
||||
ActionMailer::Base.deliveries = []
|
||||
TestAfterCommit.enabled = true
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
TestAfterCommit.enabled = false
|
||||
end
|
||||
|
||||
context "spam" do
|
||||
setup do
|
||||
Dmail.any_instance.stubs(:spam?).returns(true)
|
||||
@recipient = FactoryGirl.create(:user)
|
||||
@recipient = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
@@ -33,7 +31,7 @@ class DmailTest < ActiveSupport::TestCase
|
||||
should "autoban spammers after sending spam to N distinct users" do
|
||||
Dmail.any_instance.expects(:spam?).returns(true)
|
||||
|
||||
users = FactoryGirl.create_list(:user, Dmail::AUTOBAN_THRESHOLD)
|
||||
users = FactoryBot.create_list(:user, Dmail::AUTOBAN_THRESHOLD)
|
||||
users.each do |user|
|
||||
Dmail.create_split(from: @user, to: user, title: "spam", body: "wonderful spam")
|
||||
end
|
||||
@@ -47,9 +45,9 @@ class DmailTest < ActiveSupport::TestCase
|
||||
|
||||
context "filter" do
|
||||
setup do
|
||||
@recipient = FactoryGirl.create(:user)
|
||||
@recipient = FactoryBot.create(:user)
|
||||
@recipient.create_dmail_filter(:words => "banned")
|
||||
@dmail = FactoryGirl.build(:dmail, :title => "xxx", :owner => @recipient, :body => "banned word here", :to => @recipient, :from => @user)
|
||||
@dmail = FactoryBot.build(:dmail, :title => "xxx", :owner => @recipient, :body => "banned word here", :to => @recipient, :from => @user)
|
||||
end
|
||||
|
||||
should "detect banned words" do
|
||||
@@ -68,8 +66,8 @@ class DmailTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "be ignored when sender is a moderator" do
|
||||
CurrentUser.scoped(FactoryGirl.create(:moderator_user), "127.0.0.1") do
|
||||
@dmail = FactoryGirl.create(:dmail, :owner => @recipient, :body => "banned word here", :to => @recipient)
|
||||
CurrentUser.scoped(FactoryBot.create(:moderator_user), "127.0.0.1") do
|
||||
@dmail = FactoryBot.create(:dmail, :owner => @recipient, :body => "banned word here", :to => @recipient)
|
||||
end
|
||||
|
||||
assert_equal(false, !!@recipient.dmail_filter.filtered?(@dmail))
|
||||
@@ -94,7 +92,7 @@ class DmailTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
dmail = FactoryGirl.build(:dmail, :title => "xxx", :owner => @user)
|
||||
dmail = FactoryBot.build(:dmail, :title => "xxx", :owner => @user)
|
||||
dmail.save
|
||||
assert_equal(1, dmail.errors.size)
|
||||
assert_equal(["Sender is banned and cannot send messages"], dmail.errors.full_messages)
|
||||
@@ -103,7 +101,7 @@ class DmailTest < ActiveSupport::TestCase
|
||||
|
||||
context "search" do
|
||||
should "return results based on title contents" do
|
||||
dmail = FactoryGirl.create(:dmail, :title => "xxx", :owner => @user)
|
||||
dmail = FactoryBot.create(:dmail, :title => "xxx", :owner => @user)
|
||||
|
||||
matches = Dmail.search(title_matches: "x")
|
||||
assert_equal([dmail.id], matches.map(&:id))
|
||||
@@ -119,7 +117,7 @@ class DmailTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return results based on body contents" do
|
||||
dmail = FactoryGirl.create(:dmail, :body => "xxx", :owner => @user)
|
||||
dmail = FactoryBot.create(:dmail, :body => "xxx", :owner => @user)
|
||||
matches = Dmail.search_message("xxx")
|
||||
assert(matches.any?)
|
||||
matches = Dmail.search_message("aaa")
|
||||
@@ -128,14 +126,14 @@ class DmailTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "should parse user names" do
|
||||
dmail = FactoryGirl.build(:dmail, :owner => @user)
|
||||
dmail = FactoryBot.build(:dmail, :owner => @user)
|
||||
dmail.to_id = nil
|
||||
dmail.to_name = @user.name
|
||||
assert(dmail.to_id == @user.id)
|
||||
end
|
||||
|
||||
should "construct a response" do
|
||||
dmail = FactoryGirl.create(:dmail, :owner => @user)
|
||||
dmail = FactoryBot.create(:dmail, :owner => @user)
|
||||
response = dmail.build_response
|
||||
assert_equal("Re: #{dmail.title}", response.title)
|
||||
assert_equal(dmail.from_id, response.to_id)
|
||||
@@ -143,41 +141,41 @@ class DmailTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "create a copy for each user" do
|
||||
@new_user = FactoryGirl.create(:user)
|
||||
@new_user = FactoryBot.create(:user)
|
||||
assert_difference("Dmail.count", 2) do
|
||||
Dmail.create_split(:to_id => @new_user.id, :title => "foo", :body => "foo")
|
||||
end
|
||||
end
|
||||
|
||||
should "record the creator's ip addr" do
|
||||
dmail = FactoryGirl.create(:dmail, owner: @user)
|
||||
dmail = FactoryBot.create(:dmail, owner: @user)
|
||||
assert_equal(CurrentUser.ip_addr, dmail.creator_ip_addr.to_s)
|
||||
end
|
||||
|
||||
should "send an email if the user wants it" do
|
||||
user = FactoryGirl.create(:user, :receive_email_notifications => true)
|
||||
user = FactoryBot.create(:user, :receive_email_notifications => true)
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
||||
FactoryGirl.create(:dmail, :to => user, :owner => user)
|
||||
FactoryBot.create(:dmail, :to => user, :owner => user)
|
||||
end
|
||||
end
|
||||
|
||||
should "create only one message for a split response" do
|
||||
user = FactoryGirl.create(:user, :receive_email_notifications => true)
|
||||
user = FactoryBot.create(:user, :receive_email_notifications => true)
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
||||
Dmail.create_split(:to_id => user.id, :title => "foo", :body => "foo")
|
||||
end
|
||||
end
|
||||
|
||||
should "be marked as read after the user reads it" do
|
||||
dmail = FactoryGirl.create(:dmail, :owner => @user)
|
||||
dmail = FactoryBot.create(:dmail, :owner => @user)
|
||||
assert(!dmail.is_read?)
|
||||
dmail.mark_as_read!
|
||||
assert(dmail.is_read?)
|
||||
end
|
||||
|
||||
should "notify the recipient he has mail" do
|
||||
@recipient = FactoryGirl.create(:user)
|
||||
dmail = FactoryGirl.create(:dmail, :owner => @recipient)
|
||||
@recipient = FactoryBot.create(:user)
|
||||
dmail = FactoryBot.create(:dmail, :owner => @recipient)
|
||||
recipient = dmail.to
|
||||
recipient.reload
|
||||
assert(recipient.has_mail?)
|
||||
@@ -192,7 +190,7 @@ class DmailTest < ActiveSupport::TestCase
|
||||
|
||||
context "that is automated" do
|
||||
setup do
|
||||
@bot = FactoryGirl.create(:user)
|
||||
@bot = FactoryBot.create(:user)
|
||||
User.stubs(:system).returns(@bot)
|
||||
end
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ module Downloads
|
||||
class FileTest < ActiveSupport::TestCase
|
||||
context "A twitter video download" do
|
||||
setup do
|
||||
skip "Twitter is not configured" unless Danbooru.config.twitter_api_key
|
||||
@source = "https://twitter.com/CincinnatiZoo/status/859073537713328129"
|
||||
@download = Downloads::File.new(@source)
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ module Downloads
|
||||
class PawooTest < ActiveSupport::TestCase
|
||||
context "downloading a 'https://pawoo.net/web/statuses/:id' url" do
|
||||
should "download the original file" do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@source = "https://pawoo.net/web/statuses/1202176"
|
||||
@rewrite = "https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -13,6 +14,7 @@ module Downloads
|
||||
|
||||
context "downloading a 'https://pawoo.net/:user/:id' url" do
|
||||
should "download the original file" do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@source = "https://pawoo.net/@9ed00e924818/1202176"
|
||||
@rewrite = "https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -22,6 +24,7 @@ module Downloads
|
||||
|
||||
context "downloading a 'https://img.pawoo.net/media_attachments/:id/small/:file' url" do
|
||||
should "download the original file" do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@source = "https://img.pawoo.net/media_attachments/files/000/128/953/small/4c0a06087b03343f.png"
|
||||
@rewrite = "https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
|
||||
@@ -4,6 +4,7 @@ module Downloads
|
||||
class TumblrTest < ActiveSupport::TestCase
|
||||
context "a download for a tumblr 500 sample" do
|
||||
should "instead download the raw version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://24.media.tumblr.com/fc328250915434e66e8e6a92773f79d0/tumblr_mf4nshfibc1s0oswoo1_500.jpg"
|
||||
@rewrite = "http://data.tumblr.com/fc328250915434e66e8e6a92773f79d0/tumblr_mf4nshfibc1s0oswoo1_raw.jpg"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -13,6 +14,7 @@ module Downloads
|
||||
|
||||
context "a download for a *.media.tumblr.com/tumblr_$id_$size image without a larger size" do
|
||||
should "download the same version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://25.media.tumblr.com/tumblr_lxbzel2H5y1r9yjhso1_500.jpg"
|
||||
@rewrite = "http://data.tumblr.com/tumblr_lxbzel2H5y1r9yjhso1_500.jpg"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -22,6 +24,7 @@ module Downloads
|
||||
|
||||
context "a download for a *.media.tumblr.com/tumblr_$id_$size image with a larger size" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://25.media.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_500.png"
|
||||
@rewrite = "http://data.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_1280.png"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -31,6 +34,7 @@ module Downloads
|
||||
|
||||
context "a download for a *.media.tumblr.com/$hash/tumblr_$id_rN_$size image" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://33.media.tumblr.com/4b7fecf9a5a8284fbaefb051a2369b55/tumblr_npozqfwc9h1rt6u7do1_r1_500.gif"
|
||||
@rewrite = "http://data.tumblr.com/4b7fecf9a5a8284fbaefb051a2369b55/tumblr_npozqfwc9h1rt6u7do1_r1_raw.gif"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -40,6 +44,7 @@ module Downloads
|
||||
|
||||
context "a download for a *.media.tumblr.com/$hash/tumblr_inline_$id_$size image" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://68.media.tumblr.com/ee02048f5578595badc95905e17154b4/tumblr_inline_ofbr4452601sk4jd9_250.gif"
|
||||
@rewrite = "http://data.tumblr.com/ee02048f5578595badc95905e17154b4/tumblr_inline_ofbr4452601sk4jd9_500.gif"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -49,6 +54,7 @@ module Downloads
|
||||
|
||||
context "a download for a data.tumblr.com/$id_$size image with a larger size" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "http://data.tumblr.com/0DNBGJovY5j3smfeQs8nB53z_400.jpg"
|
||||
@rewrite = "http://data.tumblr.com/0DNBGJovY5j3smfeQs8nB53z_500.jpg"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -58,6 +64,7 @@ module Downloads
|
||||
|
||||
context "a download for a data.tumblr.com/tumblr_$id_$size.jpg image" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "http://data.tumblr.com/tumblr_m24kbxqKAX1rszquso1_250.jpg"
|
||||
@rewrite = "http://data.tumblr.com/tumblr_m24kbxqKAX1rszquso1_1280.jpg"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -67,6 +74,7 @@ module Downloads
|
||||
|
||||
context "a download for a gs1.wac.edgecastcdn.net image" do
|
||||
should "rewrite to the full tumblr version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://gs1.wac.edgecastcdn.net/8019B6/data.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_500.png"
|
||||
@rewrite = "http://data.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_1280.png"
|
||||
|
||||
@@ -77,6 +85,7 @@ module Downloads
|
||||
|
||||
context "a download for a *.tumblr.com/post/* html page" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://noizave.tumblr.com/post/162206271767"
|
||||
@rewrite = "http://data.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_raw.png"
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ module Downloads
|
||||
class TwitterTest < ActiveSupport::TestCase
|
||||
context "downloading a 'https://twitter.com/:user/status/:id' url containing a video" do
|
||||
should "download the largest video" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@source = "https://twitter.com/CincinnatiZoo/status/859073537713328129"
|
||||
@rewrite = "https://video.twimg.com/ext_tw_video/859073467769126913/pu/vid/1280x720/cPGgVROXHy3yrK6u.mp4"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -13,6 +14,7 @@ module Downloads
|
||||
|
||||
context "downloading a 'https://twitter.com/:user/status/:id/photo/:n' card url" do
|
||||
should "download the orig file" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@source = "https://twitter.com/masayasuf/status/870734961778630656/photo/1"
|
||||
@rewrite = "https://pbs.twimg.com/media/DBV40M2UIAAHYlt.jpg:orig"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -22,6 +24,7 @@ module Downloads
|
||||
|
||||
context "downloading a 'https://mobile.twitter.com/:user/status/:id/photo/:n' mobile url" do
|
||||
should "download the orig file" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@source = "https://mobile.twitter.com/Strangestone/status/556440271961858051"
|
||||
@rewrite = "https://pbs.twimg.com/media/B7jfc1JCcAEyeJh.png:orig"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@@ -31,6 +34,7 @@ module Downloads
|
||||
|
||||
context "downloading a 'https://pbs.twimg.com/media/*:large' url" do
|
||||
should "download the orig file" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large"
|
||||
@rewrite = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
|
||||
@@ -3,10 +3,10 @@ require 'test_helper'
|
||||
class FavoriteTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@fav_group = FactoryGirl.create(:favorite_group, creator: @user, name: "blah")
|
||||
@fav_group = FactoryBot.create(:favorite_group, creator: @user, name: "blah")
|
||||
end
|
||||
|
||||
def teardown
|
||||
@@ -63,7 +63,7 @@ class FavoriteTest < ActiveSupport::TestCase
|
||||
|
||||
context "expunging a post" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post = FactoryBot.create(:post)
|
||||
@fav_group.add!(@post)
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class FavoriteTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
Favorite # need to force loading the favorite model
|
||||
@@ -15,21 +15,21 @@ class FavoriteTest < ActiveSupport::TestCase
|
||||
|
||||
context "A favorite" do
|
||||
should "delete from all tables" do
|
||||
user1 = FactoryGirl.create(:user)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
user1 = FactoryBot.create(:user)
|
||||
p1 = FactoryBot.create(:post)
|
||||
|
||||
user1.add_favorite!(p1)
|
||||
assert_equal(1, Favorite.count)
|
||||
|
||||
Favorite.destroy_all(:user_id => user1.id, :post_id => p1.id)
|
||||
Favorite.where(:user_id => user1.id, :post_id => p1.id).delete_all
|
||||
assert_equal(0, Favorite.count)
|
||||
end
|
||||
|
||||
should "know which table it belongs to" do
|
||||
user1 = FactoryGirl.create(:user)
|
||||
user2 = FactoryGirl.create(:user)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
p2 = FactoryGirl.create(:post)
|
||||
user1 = FactoryBot.create(:user)
|
||||
user2 = FactoryBot.create(:user)
|
||||
p1 = FactoryBot.create(:post)
|
||||
p2 = FactoryBot.create(:post)
|
||||
|
||||
user1.add_favorite!(p1)
|
||||
user1.add_favorite!(p2)
|
||||
@@ -46,9 +46,9 @@ class FavoriteTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not allow duplicates" do
|
||||
user1 = FactoryGirl.create(:user)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
p2 = FactoryGirl.create(:post)
|
||||
user1 = FactoryBot.create(:user)
|
||||
p1 = FactoryBot.create(:post)
|
||||
p2 = FactoryBot.create(:post)
|
||||
user1.add_favorite!(p1)
|
||||
user1.add_favorite!(p1)
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ require 'test_helper'
|
||||
class ForumPostTest < ActiveSupport::TestCase
|
||||
context "A forum post" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@topic = FactoryGirl.create(:forum_topic)
|
||||
@topic = FactoryBot.create(:forum_topic)
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -17,32 +17,32 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
context "that mentions a user" do
|
||||
context "in a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryGirl.create(:user)
|
||||
@user2 = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
should "not create a dmail" do
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote]")
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote] blah [quote]@#{@user2.name}[/quote]")
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote] blah [quote]@#{@user2.name}[/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "[quote][quote]@#{@user2.name}[/quote][/quote]")
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "[quote][quote]@#{@user2.name}[/quote][/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 1) do
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote] @#{@user2.name}")
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote] @#{@user2.name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "outside a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryGirl.create(:user)
|
||||
@post = FactoryGirl.build(:forum_post, :topic_id => @topic.id, :body => "Hey @#{@user2.name} check this out!")
|
||||
@user2 = FactoryBot.create(:user)
|
||||
@post = FactoryBot.build(:forum_post, :topic_id => @topic.id, :body => "Hey @#{@user2.name} check this out!")
|
||||
end
|
||||
|
||||
should "create a dmail" do
|
||||
@@ -67,16 +67,16 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
Danbooru.config.stubs(:posts_per_page).returns(3)
|
||||
@posts = []
|
||||
9.times do
|
||||
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||
@posts << FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||
end
|
||||
Timecop.travel(2.seconds.from_now) do
|
||||
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||
@posts << FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||
end
|
||||
end
|
||||
|
||||
context "that is deleted" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:moderator_user)
|
||||
CurrentUser.user = FactoryBot.create(:moderator_user)
|
||||
end
|
||||
|
||||
should "update the topic's updated_at timestamp" do
|
||||
@@ -104,7 +104,7 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
|
||||
context "belonging to a locked topic" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "zzz")
|
||||
@post = FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "zzz")
|
||||
@topic.update_attribute(:is_locked, true)
|
||||
@post.reload
|
||||
end
|
||||
@@ -116,15 +116,16 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not be deletable" do
|
||||
@post.destroy
|
||||
assert_equal(1, ForumPost.count)
|
||||
assert_difference("ForumPost.count", 0) do
|
||||
@post.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "update the topic when created" do
|
||||
@original_topic_updated_at = @topic.updated_at
|
||||
Timecop.travel(1.second.from_now) do
|
||||
post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
||||
post = FactoryBot.create(:forum_post, :topic_id => @topic.id)
|
||||
end
|
||||
@topic.reload
|
||||
assert_not_equal(@original_topic_updated_at.to_s, @topic.updated_at.to_s)
|
||||
@@ -133,7 +134,7 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
should "update the topic when updated only for the original post" do
|
||||
posts = []
|
||||
3.times do
|
||||
posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||
posts << FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||
end
|
||||
|
||||
# updating the original post
|
||||
@@ -151,20 +152,20 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "be searchable by body content" do
|
||||
post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
|
||||
post = FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
|
||||
assert_equal(1, ForumPost.body_matches("xxx").count)
|
||||
assert_equal(0, ForumPost.body_matches("aaa").count)
|
||||
end
|
||||
|
||||
should "initialize its creator" do
|
||||
post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
||||
post = FactoryBot.create(:forum_post, :topic_id => @topic.id)
|
||||
assert_equal(@user.id, post.creator_id)
|
||||
end
|
||||
|
||||
context "updated by a second user" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
||||
@second_user = FactoryGirl.create(:user)
|
||||
@post = FactoryBot.create(:forum_post, :topic_id => @topic.id)
|
||||
@second_user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @second_user
|
||||
end
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ require 'test_helper'
|
||||
class ForumTopicTest < ActiveSupport::TestCase
|
||||
context "A forum topic" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@topic = FactoryGirl.create(:forum_topic, :title => "xxx")
|
||||
@topic = FactoryBot.create(:forum_topic, :title => "xxx")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -37,7 +37,7 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
|
||||
context "that predates the topic" do
|
||||
setup do
|
||||
FactoryGirl.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 16.hours.from_now)
|
||||
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 16.hours.from_now)
|
||||
end
|
||||
|
||||
should "return false" do
|
||||
@@ -47,7 +47,7 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
|
||||
context "that postdates the topic" do
|
||||
setup do
|
||||
FactoryGirl.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 2.days.from_now)
|
||||
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 2.days.from_now)
|
||||
end
|
||||
|
||||
should "return true" do
|
||||
@@ -67,7 +67,7 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
context "and a visit" do
|
||||
context "that predates the topic" do
|
||||
setup do
|
||||
FactoryGirl.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 1.day.ago)
|
||||
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 1.day.ago)
|
||||
end
|
||||
|
||||
should "return false" do
|
||||
@@ -77,7 +77,7 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
|
||||
context "that postdates the topic" do
|
||||
setup do
|
||||
FactoryGirl.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.days.from_now)
|
||||
end
|
||||
|
||||
should "return true" do
|
||||
@@ -99,7 +99,7 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
|
||||
context "with a previous visit" do
|
||||
setup do
|
||||
FactoryGirl.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 1.day.ago)
|
||||
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 1.day.ago)
|
||||
end
|
||||
|
||||
should "update the visit" do
|
||||
@@ -112,9 +112,9 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
|
||||
context "#merge" do
|
||||
setup do
|
||||
@topic2 = FactoryGirl.create(:forum_topic, :title => "yyy")
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic2.id, :body => "xxx")
|
||||
@topic2 = FactoryBot.create(:forum_topic, :title => "yyy")
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic2.id, :body => "xxx")
|
||||
end
|
||||
|
||||
should "merge all the posts in one topic into the other" do
|
||||
@@ -126,7 +126,7 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
context "constructed with nested attributes for its original post" do
|
||||
should "create a matching forum post" do
|
||||
assert_difference(["ForumTopic.count", "ForumPost.count"], 1) do
|
||||
@topic = FactoryGirl.create(:forum_topic, :title => "abc", :original_post_attributes => {:body => "abc"})
|
||||
@topic = FactoryBot.create(:forum_topic, :title => "abc", :original_post_attributes => {:body => "abc"})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -147,7 +147,7 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
|
||||
context "updated by a second user" do
|
||||
setup do
|
||||
@second_user = FactoryGirl.create(:user)
|
||||
@second_user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @second_user
|
||||
end
|
||||
|
||||
@@ -160,7 +160,7 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
context "with multiple posts that has been deleted" do
|
||||
setup do
|
||||
5.times do
|
||||
FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class IpBanTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
|
||||
@@ -14,16 +14,16 @@ class IpBanTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "be able to count the number of comments an IP address is associated with" do
|
||||
comment = FactoryGirl.create(:comment)
|
||||
comment = FactoryBot.create(:comment)
|
||||
counts = IpBan.count_by_ip_addr("comments", [comment.creator_id], "creator_id", "ip_addr")
|
||||
assert_equal([{"ip_addr" => "127.0.0.1", "count" => "1"}], counts)
|
||||
assert_equal([{"ip_addr" => "127.0.0.1", "count" => 1}], counts)
|
||||
end
|
||||
|
||||
should "be able to count any updates from a user, groupiny by IP address" do
|
||||
CurrentUser.scoped(@user, "1.2.3.4") do
|
||||
comment = FactoryGirl.create(:comment, :body => "aaa")
|
||||
comment = FactoryBot.create(:comment, :body => "aaa")
|
||||
counts = IpBan.query([comment.creator_id])
|
||||
assert_equal([{"ip_addr" => "1.2.3.4", "count" => "1"}], counts["comments"])
|
||||
assert_equal([{"ip_addr" => "1.2.3.4", "count" => 1}], counts["comments"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,8 @@ require 'test_helper'
|
||||
class JanitorTrialTest < ActiveSupport::TestCase
|
||||
context "A janitor trial" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@admin = FactoryBot.create(:admin_user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -30,7 +30,7 @@ class JanitorTrialTest < ActiveSupport::TestCase
|
||||
|
||||
context "upon demotion" do
|
||||
setup do
|
||||
@janitor_trial = FactoryGirl.create(:janitor_trial, :user_id => @user.id)
|
||||
@janitor_trial = FactoryBot.create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
|
||||
should "create a negative feedback record" do
|
||||
@@ -48,7 +48,7 @@ class JanitorTrialTest < ActiveSupport::TestCase
|
||||
|
||||
context "upon promotion" do
|
||||
setup do
|
||||
@janitor_trial = FactoryGirl.create(:janitor_trial, :user_id => @user.id)
|
||||
@janitor_trial = FactoryBot.create(:janitor_trial, :user_id => @user.id)
|
||||
end
|
||||
|
||||
should "destroy the trial object" do
|
||||
|
||||
@@ -5,7 +5,7 @@ module Maintenance
|
||||
class LoginReminderMailerTest < ActionMailer::TestCase
|
||||
context "The login reminder mailer" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
should "send the notice" do
|
||||
|
||||
@@ -4,11 +4,11 @@ module MetaSearches
|
||||
class TagTest < ActionMailer::TestCase
|
||||
context "The tag metasearch" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
FactoryGirl.create(:post, :tag_string => "xxx")
|
||||
FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
|
||||
FactoryBot.create(:post, :tag_string => "xxx")
|
||||
FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
FactoryBot.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
|
||||
end
|
||||
|
||||
should "find the tag" do
|
||||
|
||||
@@ -4,11 +4,11 @@ module Moderator
|
||||
class IpAddrSearchTest < ActiveSupport::TestCase
|
||||
context "an ip addr search" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
|
||||
@comment = FactoryGirl.create(:comment)
|
||||
@comment = FactoryBot.create(:comment)
|
||||
PoolArchive.stubs(:enabled?).returns(false)
|
||||
PostArchive.stubs(:enabled?).returns(false)
|
||||
end
|
||||
@@ -20,7 +20,7 @@ module Moderator
|
||||
|
||||
should "find by ip addr" do
|
||||
@search = IpAddrSearch.new(:ip_addr => "127.0.0.1")
|
||||
assert_equal({@user => 1}, @search.execute)
|
||||
assert_equal({@user => 1, @comment.post.uploader => 1}, @search.execute)
|
||||
end
|
||||
|
||||
should "find by user id" do
|
||||
|
||||
@@ -9,10 +9,10 @@ module Moderator
|
||||
|
||||
context "a tag batch change" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:moderator_user)
|
||||
@user = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -28,7 +28,7 @@ module Moderator
|
||||
end
|
||||
|
||||
should "move saved searches" do
|
||||
ss = FactoryGirl.create(:saved_search, :user => @user, :query => "123 ... 456")
|
||||
ss = FactoryBot.create(:saved_search, :user => @user, :query => "123 ... 456")
|
||||
tag_batch_change = TagBatchChange.new("...", "bbb", @user.id, "127.0.0.1")
|
||||
tag_batch_change.perform
|
||||
|
||||
@@ -36,7 +36,7 @@ module Moderator
|
||||
end
|
||||
|
||||
should "move only saved searches that match the mass update exactly" do
|
||||
ss = FactoryGirl.create(:saved_search, :user => @user, :query => "123 ... 456")
|
||||
ss = FactoryBot.create(:saved_search, :user => @user, :query => "123 ... 456")
|
||||
tag_batch_change = TagBatchChange.new("1", "bbb", @user.id, "127.0.0.1")
|
||||
tag_batch_change.perform
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class NoteTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -15,8 +15,8 @@ class NoteTest < ActiveSupport::TestCase
|
||||
|
||||
context "#merge_version" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@note = FactoryGirl.create(:note, :post => @post)
|
||||
@post = FactoryBot.create(:post)
|
||||
@note = FactoryBot.create(:note, :post => @post)
|
||||
end
|
||||
|
||||
should "not increment version" do
|
||||
@@ -28,8 +28,8 @@ class NoteTest < ActiveSupport::TestCase
|
||||
|
||||
context "for a post that already has a note" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@note = FactoryGirl.create(:note, :post => @post)
|
||||
@post = FactoryBot.create(:post)
|
||||
@note = FactoryBot.create(:note, :post => @post)
|
||||
end
|
||||
|
||||
context "when the note is deleted the post" do
|
||||
@@ -46,29 +46,29 @@ class NoteTest < ActiveSupport::TestCase
|
||||
|
||||
context "creating a note" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post, :image_width => 1000, :image_height => 1000)
|
||||
@post = FactoryBot.create(:post, :image_width => 1000, :image_height => 1000)
|
||||
end
|
||||
|
||||
should "not validate if the note is outside the image" do
|
||||
@note = FactoryGirl.build(:note, :x => 1001, :y => 500, :post => @post)
|
||||
@note = FactoryBot.build(:note, :x => 1001, :y => 500, :post => @post)
|
||||
@note.save
|
||||
assert_equal(["Note must be inside the image"], @note.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not validate if the note is larger than the image" do
|
||||
@note = FactoryGirl.build(:note, :x => 500, :y => 500, :height => 501, :width => 500, :post => @post)
|
||||
@note = FactoryBot.build(:note, :x => 500, :y => 500, :height => 501, :width => 500, :post => @post)
|
||||
@note.save
|
||||
assert_equal(["Note must be inside the image"], @note.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not validate if the post does not exist" do
|
||||
@note = FactoryGirl.build(:note, :x => 500, :y => 500, :post_id => -1)
|
||||
@note = FactoryBot.build(:note, :x => 500, :y => 500, :post_id => -1)
|
||||
@note.save
|
||||
assert_equal(["Post must exist"], @note.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not validate if the body is blank" do
|
||||
@note = FactoryGirl.build(:note, body: " ")
|
||||
@note = FactoryBot.build(:note, body: " ")
|
||||
|
||||
assert_equal(false, @note.valid?)
|
||||
assert_equal(["Body can't be blank"], @note.errors.full_messages)
|
||||
@@ -77,7 +77,7 @@ class NoteTest < ActiveSupport::TestCase
|
||||
should "create a version" do
|
||||
assert_difference("NoteVersion.count", 1) do
|
||||
Timecop.travel(1.day.from_now) do
|
||||
@note = FactoryGirl.create(:note, :post => @post)
|
||||
@note = FactoryBot.create(:note, :post => @post)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -89,7 +89,7 @@ class NoteTest < ActiveSupport::TestCase
|
||||
|
||||
should "update the post's last_noted_at field" do
|
||||
assert_nil(@post.last_noted_at)
|
||||
@note = FactoryGirl.create(:note, :post => @post)
|
||||
@note = FactoryBot.create(:note, :post => @post)
|
||||
@post.reload
|
||||
assert_not_nil(@post.last_noted_at)
|
||||
end
|
||||
@@ -101,7 +101,7 @@ class NoteTest < ActiveSupport::TestCase
|
||||
|
||||
should "fail" do
|
||||
assert_difference("Note.count", 0) do
|
||||
@note = FactoryGirl.build(:note, :post => @post)
|
||||
@note = FactoryBot.build(:note, :post => @post)
|
||||
@note.save
|
||||
end
|
||||
assert_equal(["Post is note locked"], @note.errors.full_messages)
|
||||
@@ -111,8 +111,8 @@ class NoteTest < ActiveSupport::TestCase
|
||||
|
||||
context "updating a note" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post, :image_width => 1000, :image_height => 1000)
|
||||
@note = FactoryGirl.create(:note, :post => @post)
|
||||
@post = FactoryBot.create(:post, :image_width => 1000, :image_height => 1000)
|
||||
@note = FactoryBot.create(:note, :post => @post)
|
||||
@note.stubs(:merge_version?).returns(false)
|
||||
end
|
||||
|
||||
@@ -165,8 +165,8 @@ class NoteTest < ActiveSupport::TestCase
|
||||
|
||||
context "when notes have been vandalized by one user" do
|
||||
setup do
|
||||
@vandal = FactoryGirl.create(:user)
|
||||
@note = FactoryGirl.create(:note, :x => 5, :y => 5)
|
||||
@vandal = FactoryBot.create(:user)
|
||||
@note = FactoryBot.create(:note, :x => 5, :y => 5)
|
||||
CurrentUser.scoped(@vandal, "127.0.0.1") do
|
||||
@note.update_attributes(:x => 10, :y => 10)
|
||||
end
|
||||
@@ -191,7 +191,7 @@ class NoteTest < ActiveSupport::TestCase
|
||||
|
||||
context "searching for a note" do
|
||||
setup do
|
||||
@note = FactoryGirl.create(:note, :body => "aaa")
|
||||
@note = FactoryBot.create(:note, :body => "aaa")
|
||||
end
|
||||
|
||||
context "where the body contains the string 'aaa'" do
|
||||
|
||||
@@ -14,6 +14,7 @@ class PixivUgoiraConverterTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "output to webm" do
|
||||
skip "ffmpeg is not installed" unless check_ffmpeg
|
||||
sample_file = PixivUgoiraConverter.generate_webm(@zipfile, @frame_data)
|
||||
preview_file = PixivUgoiraConverter.generate_preview(@zipfile)
|
||||
assert_operator(sample_file.size, :>, 1_000)
|
||||
|
||||
@@ -5,7 +5,7 @@ require 'test_helper'
|
||||
class PoolTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
Timecop.travel(1.month.ago) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
|
||||
context "A name" do
|
||||
setup do
|
||||
@pool = FactoryGirl.create(:pool, :name => "xxx")
|
||||
@pool = FactoryBot.create(:pool, :name => "xxx")
|
||||
end
|
||||
|
||||
should "be mapped to a pool id" do
|
||||
@@ -34,7 +34,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
|
||||
context "A multibyte character name" do
|
||||
setup do
|
||||
@mb_pool = FactoryGirl.create(:pool, :name => "àáâãäå")
|
||||
@mb_pool = FactoryBot.create(:pool, :name => "àáâãäå")
|
||||
end
|
||||
|
||||
should "be mapped to a pool id" do
|
||||
@@ -44,7 +44,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
|
||||
context "An id number" do
|
||||
setup do
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@pool = FactoryBot.create(:pool)
|
||||
end
|
||||
|
||||
should "be mapped to a pool id" do
|
||||
@@ -56,10 +56,10 @@ class PoolTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
PoolArchive.stubs(:enabled?).returns(true)
|
||||
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@p1 = FactoryGirl.create(:post)
|
||||
@p2 = FactoryGirl.create(:post)
|
||||
@p3 = FactoryGirl.create(:post)
|
||||
@pool = FactoryBot.create(:pool)
|
||||
@p1 = FactoryBot.create(:post)
|
||||
@p2 = FactoryBot.create(:post)
|
||||
@p3 = FactoryBot.create(:post)
|
||||
CurrentUser.scoped(@user, "1.2.3.4") do
|
||||
@pool.add!(@p1)
|
||||
end
|
||||
@@ -104,9 +104,9 @@ class PoolTest < ActiveSupport::TestCase
|
||||
|
||||
context "Updating a pool" do
|
||||
setup do
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@p1 = FactoryGirl.create(:post)
|
||||
@p2 = FactoryGirl.create(:post)
|
||||
@pool = FactoryBot.create(:pool)
|
||||
@p1 = FactoryBot.create(:post)
|
||||
@p2 = FactoryBot.create(:post)
|
||||
end
|
||||
|
||||
context "by adding a new post" do
|
||||
@@ -147,7 +147,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
context "to a deleted pool" do
|
||||
setup do
|
||||
# must be a builder to update deleted pools.
|
||||
CurrentUser.user = FactoryGirl.create(:builder_user)
|
||||
CurrentUser.user = FactoryBot.create(:builder_user)
|
||||
|
||||
@pool.update_attribute(:is_deleted, true)
|
||||
@pool.post_ids = "#{@pool.post_ids} #{@p2.id}"
|
||||
@@ -215,7 +215,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
|
||||
should "create new versions for each distinct user" do
|
||||
assert_equal(1, @pool.versions.size)
|
||||
user2 = Timecop.travel(1.month.ago) {FactoryGirl.create(:user)}
|
||||
user2 = Timecop.travel(1.month.ago) {FactoryBot.create(:user)}
|
||||
|
||||
CurrentUser.scoped(user2, "127.0.0.2") do
|
||||
@pool.post_ids = "#{@p1.id}"
|
||||
@@ -262,24 +262,21 @@ class PoolTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
context "when validating names" do
|
||||
should_not allow_value("foo,bar").for(:name)
|
||||
should_not allow_value("foo*bar").for(:name)
|
||||
should_not allow_value("123").for(:name)
|
||||
should_not allow_value("___").for(:name)
|
||||
should_not allow_value(" ").for(:name)
|
||||
|
||||
%w[any none series collection].each do |type|
|
||||
should_not allow_value(type).for(:name)
|
||||
should "not be valid for bad names" do
|
||||
["foo,bar", "foo*bar", "123", "___", " ", "any", "none", "series", "collection"].each do |bad_name|
|
||||
pool = Pool.create(name: bad_name)
|
||||
assert pool.invalid?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "An existing pool" do
|
||||
setup do
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@p1 = FactoryGirl.create(:post)
|
||||
@p2 = FactoryGirl.create(:post)
|
||||
@p3 = FactoryGirl.create(:post)
|
||||
@pool = FactoryBot.create(:pool)
|
||||
@p1 = FactoryBot.create(:post)
|
||||
@p2 = FactoryBot.create(:post)
|
||||
@p3 = FactoryBot.create(:post)
|
||||
@pool.add!(@p1)
|
||||
@pool.add!(@p2)
|
||||
@pool.add!(@p3)
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class PostAppealTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@alice = FactoryGirl.create(:user)
|
||||
@alice = FactoryBot.create(:user)
|
||||
CurrentUser.user = @alice
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
Danbooru.config.stubs(:max_appeals_per_day).returns(5)
|
||||
@@ -16,7 +16,7 @@ class PostAppealTest < ActiveSupport::TestCase
|
||||
|
||||
context "a user" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa", :is_deleted => true)
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa", :is_deleted => true)
|
||||
end
|
||||
|
||||
should "not be able to appeal a post more than twice" do
|
||||
|
||||
@@ -3,13 +3,13 @@ require 'test_helper'
|
||||
class PostApprovalTest < ActiveSupport::TestCase
|
||||
context "a pending post" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@post = FactoryGirl.create(:post, uploader_id: @user.id, is_pending: true)
|
||||
@post = FactoryBot.create(:post, uploader_id: @user.id, is_pending: true)
|
||||
|
||||
@approver = FactoryGirl.create(:user)
|
||||
@approver = FactoryBot.create(:user)
|
||||
@approver.can_approve_posts = true
|
||||
@approver.save
|
||||
CurrentUser.user = @approver
|
||||
@@ -35,9 +35,9 @@ class PostApprovalTest < ActiveSupport::TestCase
|
||||
|
||||
context "that is then flagged" do
|
||||
setup do
|
||||
@user2 = FactoryGirl.create(:user)
|
||||
@user3 = FactoryGirl.create(:user)
|
||||
@approver2 = FactoryGirl.create(:user)
|
||||
@user2 = FactoryBot.create(:user)
|
||||
@user3 = FactoryBot.create(:user)
|
||||
@approver2 = FactoryBot.create(:user)
|
||||
@approver2.can_approve_posts = true
|
||||
@approver2.save
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
context "A post" do
|
||||
setup do
|
||||
Timecop.travel(1.month.ago) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@@ -20,7 +20,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
context "#undo" do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "1")
|
||||
@post = FactoryBot.create(:post, :tag_string => "1")
|
||||
@post.update_attributes(:tag_string => "1 2")
|
||||
@post.update_attributes(:tag_string => "2 3")
|
||||
end
|
||||
@@ -37,7 +37,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
context "that has multiple versions: " do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "1")
|
||||
@post = FactoryBot.create(:post, :tag_string => "1")
|
||||
@post.update_attributes(:tag_string => "1 2")
|
||||
@post.update_attributes(:tag_string => "2 3")
|
||||
end
|
||||
@@ -56,8 +56,8 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been created" do
|
||||
setup do
|
||||
@parent = FactoryGirl.create(:post)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "e", :parent => @parent, :source => "xyz")
|
||||
@parent = FactoryBot.create(:post)
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "e", :parent => @parent, :source => "xyz")
|
||||
end
|
||||
|
||||
should "also create a version" do
|
||||
@@ -73,8 +73,8 @@ 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}")
|
||||
@pool = FactoryBot.create(:pool)
|
||||
@post = FactoryBot.create(:post, tag_string: "tagme pool:#{@pool.id}")
|
||||
end
|
||||
|
||||
should "create a version" do
|
||||
@@ -88,8 +88,8 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
|
||||
context "that should be merged" do
|
||||
setup do
|
||||
@parent = FactoryGirl.create(:post)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
@parent = FactoryBot.create(:post)
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
end
|
||||
|
||||
should "delete the previous version" do
|
||||
@@ -103,7 +103,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
context "that has been updated" do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
|
||||
end
|
||||
|
||||
@@ -140,7 +140,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
|
||||
should "should create a version if the parent changes" do
|
||||
assert_difference("@post.versions.size", 1) do
|
||||
@parent = FactoryGirl.create(:post)
|
||||
@parent = FactoryBot.create(:post)
|
||||
@post.update(parent_id: @parent.id)
|
||||
assert_equal(@parent.id, @post.versions.sort_by(&:id).last.parent_id)
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@alice = FactoryGirl.create(:moderator_user)
|
||||
@alice = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @alice
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -15,8 +15,8 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
|
||||
context "A post disapproval" do
|
||||
setup do
|
||||
@post_1 = FactoryGirl.create(:post, :is_pending => true)
|
||||
@post_2 = FactoryGirl.create(:post, :is_pending => true)
|
||||
@post_1 = FactoryBot.create(:post, :is_pending => true)
|
||||
@post_2 = FactoryBot.create(:post, :is_pending => true)
|
||||
end
|
||||
|
||||
context "made by alice" do
|
||||
@@ -37,7 +37,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
|
||||
context "when the current user is brittony" do
|
||||
setup do
|
||||
@brittony = FactoryGirl.create(:moderator_user)
|
||||
@brittony = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @brittony
|
||||
end
|
||||
|
||||
@@ -50,8 +50,8 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
|
||||
context "for a post that has been approved" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@post = FactoryBot.create(:post)
|
||||
@user = FactoryBot.create(:user)
|
||||
Timecop.travel(2.months.ago) do
|
||||
@disapproval = PostDisapproval.create(:user => @user, :post => @post)
|
||||
end
|
||||
@@ -66,20 +66,20 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
|
||||
context "when sending dmails" do
|
||||
setup do
|
||||
@uploaders = FactoryGirl.create_list(:user, 2)
|
||||
@disapprovers = FactoryGirl.create_list(:mod_user, 2)
|
||||
@uploaders = FactoryBot.create_list(:user, 2)
|
||||
@disapprovers = FactoryBot.create_list(:mod_user, 2)
|
||||
|
||||
# 2 uploaders, with 2 uploads each, and 2 disapprovals on each upload.
|
||||
@uploaders.each do |uploader|
|
||||
FactoryGirl.create_list(:post, 2, uploader: uploader).each do |post|
|
||||
FactoryGirl.create(:post_disapproval, post: post, user: @disapprovers[0])
|
||||
FactoryGirl.create(:post_disapproval, post: post, user: @disapprovers[1])
|
||||
FactoryBot.create_list(:post, 2, uploader: uploader).each do |post|
|
||||
FactoryBot.create(:post_disapproval, post: post, user: @disapprovers[0])
|
||||
FactoryBot.create(:post_disapproval, post: post, user: @disapprovers[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "dmail the uploaders" do
|
||||
bot = FactoryGirl.create(:user)
|
||||
bot = FactoryBot.create(:user)
|
||||
User.stubs(:system).returns(bot)
|
||||
|
||||
assert_difference(["@uploaders[0].dmails.count", "@uploaders[1].dmails.count"], 1) do
|
||||
|
||||
@@ -5,11 +5,11 @@ class PostEventTest < ActiveSupport::TestCase
|
||||
super
|
||||
|
||||
Timecop.travel(2.weeks.ago) do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post = FactoryBot.create(:post)
|
||||
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
||||
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
|
||||
end
|
||||
|
||||
@@ -4,11 +4,11 @@ class PostFlagTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
Timecop.travel(2.weeks.ago) do
|
||||
@alice = FactoryGirl.create(:gold_user)
|
||||
@alice = FactoryBot.create(:gold_user)
|
||||
end
|
||||
CurrentUser.user = @alice
|
||||
CurrentUser.ip_addr = "127.0.0.2"
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -19,7 +19,7 @@ class PostFlagTest < ActiveSupport::TestCase
|
||||
context "a basic user" do
|
||||
setup do
|
||||
Timecop.travel(2.weeks.ago) do
|
||||
@bob = FactoryGirl.create(:user)
|
||||
@bob = FactoryBot.create(:user)
|
||||
end
|
||||
CurrentUser.user = @bob
|
||||
end
|
||||
@@ -72,18 +72,18 @@ class PostFlagTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not be able to flag a post in the cooldown period" do
|
||||
users = FactoryGirl.create_list(:user, 2, created_at: 2.weeks.ago)
|
||||
flag1 = FactoryGirl.create(:post_flag, post: @post, creator: users.first)
|
||||
users = FactoryBot.create_list(:user, 2, created_at: 2.weeks.ago)
|
||||
flag1 = FactoryBot.create(:post_flag, post: @post, creator: users.first)
|
||||
@post.approve!
|
||||
|
||||
travel_to(PostFlag::COOLDOWN_PERIOD.from_now - 1.minute) do
|
||||
flag2 = FactoryGirl.build(:post_flag, post: @post, creator: users.second)
|
||||
flag2 = FactoryBot.build(:post_flag, post: @post, creator: users.second)
|
||||
assert(flag2.invalid?)
|
||||
assert_match(/cannot be flagged more than once/, flag2.errors[:post].join)
|
||||
end
|
||||
|
||||
travel_to(PostFlag::COOLDOWN_PERIOD.from_now + 1.minute) do
|
||||
flag3 = FactoryGirl.build(:post_flag, post: @post, creator: users.second)
|
||||
flag3 = FactoryBot.build(:post_flag, post: @post, creator: users.second)
|
||||
assert(flag3.valid?)
|
||||
end
|
||||
end
|
||||
@@ -98,13 +98,13 @@ class PostFlagTest < ActiveSupport::TestCase
|
||||
context "a moderator user" do
|
||||
setup do
|
||||
Timecop.travel(2.weeks.ago) do
|
||||
@dave = FactoryGirl.create(:moderator_user)
|
||||
@dave = FactoryBot.create(:moderator_user)
|
||||
end
|
||||
CurrentUser.user = @dave
|
||||
end
|
||||
|
||||
should "not be able to view flags on their own uploads" do
|
||||
@modpost = FactoryGirl.create(:post, :tag_string => "mmm",:uploader_id => @dave.id)
|
||||
@modpost = FactoryBot.create(:post, :tag_string => "mmm",:uploader_id => @dave.id)
|
||||
CurrentUser.scoped(@alice) do
|
||||
@flag1 = PostFlag.create(:post => @modpost, :reason => "aaa", :is_resolved => false)
|
||||
end
|
||||
|
||||
@@ -4,20 +4,20 @@ class PostPrunerTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@user = FactoryGirl.create(:admin_user)
|
||||
@user = FactoryBot.create(:admin_user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
Timecop.travel(2.weeks.ago) do
|
||||
@flagger = FactoryGirl.create(:gold_user)
|
||||
@flagger = FactoryBot.create(:gold_user)
|
||||
end
|
||||
@old_post = FactoryGirl.create(:post, :created_at => 5.days.ago, :is_pending => true)
|
||||
@unresolved_flagged_post = FactoryGirl.create(:post, :is_flagged => true)
|
||||
@resolved_flagged_post = FactoryGirl.create(:post, :is_flagged => true)
|
||||
@old_post = FactoryBot.create(:post, :created_at => 5.days.ago, :is_pending => true)
|
||||
@unresolved_flagged_post = FactoryBot.create(:post, :is_flagged => true)
|
||||
@resolved_flagged_post = FactoryBot.create(:post, :is_flagged => true)
|
||||
|
||||
CurrentUser.scoped(@flagger, "127.0.0.2") do
|
||||
@unresolved_post_flag = FactoryGirl.create(:post_flag, :created_at => 5.days.ago, :is_resolved => false, :post_id => @unresolved_flagged_post.id)
|
||||
@resolved_post_flag = FactoryGirl.create(:post_flag, :created_at => 5.days.ago, :is_resolved => true, :post_id => @resolved_flagged_post.id)
|
||||
@unresolved_post_flag = FactoryBot.create(:post_flag, :created_at => 5.days.ago, :is_resolved => false, :post_id => @unresolved_flagged_post.id)
|
||||
@resolved_post_flag = FactoryBot.create(:post_flag, :created_at => 5.days.ago, :is_resolved => true, :post_id => @resolved_flagged_post.id)
|
||||
end
|
||||
|
||||
PostPruner.new.prune!
|
||||
|
||||
@@ -7,11 +7,11 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
mock_iqdb_service!
|
||||
Delayed::Worker.delay_jobs = true # don't delete the old images right away
|
||||
|
||||
@system = FactoryGirl.create(:user, created_at: 2.weeks.ago)
|
||||
@system = FactoryBot.create(:user, created_at: 2.weeks.ago)
|
||||
User.stubs(:system).returns(@system)
|
||||
|
||||
@uploader = FactoryGirl.create(:user, created_at: 2.weeks.ago, can_upload_free: true)
|
||||
@replacer = FactoryGirl.create(:user, created_at: 2.weeks.ago, can_approve_posts: true)
|
||||
@uploader = FactoryBot.create(:user, created_at: 2.weeks.ago, can_upload_free: true)
|
||||
@replacer = FactoryBot.create(:user, created_at: 2.weeks.ago, can_approve_posts: true)
|
||||
CurrentUser.user = @replacer
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -27,7 +27,7 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
context "Replacing" do
|
||||
setup do
|
||||
CurrentUser.scoped(@uploader, "127.0.0.2") do
|
||||
upload = FactoryGirl.create(:jpg_upload, as_pending: "0", tag_string: "lowres tag1")
|
||||
upload = FactoryBot.create(:jpg_upload, as_pending: "0", tag_string: "lowres tag1")
|
||||
upload.process!
|
||||
@post = upload.post
|
||||
end
|
||||
@@ -118,7 +118,7 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
|
||||
context "a post with notes" do
|
||||
setup do
|
||||
@post.update({image_width: 160, image_height: 164}, without_protection: true)
|
||||
@post.update(image_width: 160, image_height: 164)
|
||||
CurrentUser.scoped(@uploader, "127.0.0.1") do
|
||||
@note = @post.notes.create(x: 80, y: 82, width: 80, height: 82, body: "test")
|
||||
end
|
||||
@@ -169,6 +169,7 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
|
||||
context "a post that is replaced by a ugoira" do
|
||||
should "save the frame data" do
|
||||
skip "ffmpeg not installed" unless check_ffmpeg
|
||||
@post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
@post.reload
|
||||
|
||||
@@ -186,6 +187,8 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
|
||||
context "a post that is replaced to another file then replaced back to the original file" do
|
||||
should "not delete the original files" do
|
||||
skip "ffmpeg is not installed" unless check_ffmpeg
|
||||
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
@@ -204,8 +207,10 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
|
||||
context "two posts that have had their files swapped" do
|
||||
should "not delete the still active files" do
|
||||
@post1 = FactoryGirl.create(:post)
|
||||
@post2 = FactoryGirl.create(:post)
|
||||
skip "ffmpeg is not installed" unless check_ffmpeg
|
||||
|
||||
@post1 = FactoryBot.create(:post)
|
||||
@post2 = FactoryBot.create(:post)
|
||||
|
||||
# swap the images between @post1 and @post2.
|
||||
@post1.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
@@ -245,6 +250,7 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
|
||||
context "a post when replaced with a HTML source" do
|
||||
should "record the image URL as the replacement URL, not the HTML source" do
|
||||
skip "Twitter key not set" unless Danbooru.config.twitter_api_key
|
||||
replacement_url = "https://twitter.com/nounproject/status/540944400767922176"
|
||||
image_url = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||
@post.replace!(replacement_url: replacement_url)
|
||||
|
||||
@@ -4,13 +4,13 @@ module PostSets
|
||||
class FavoriteTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@post_1 = FactoryGirl.create(:post)
|
||||
@post_2 = FactoryGirl.create(:post)
|
||||
@post_3 = FactoryGirl.create(:post)
|
||||
@post_1 = FactoryBot.create(:post)
|
||||
@post_2 = FactoryBot.create(:post)
|
||||
@post_3 = FactoryBot.create(:post)
|
||||
@post_2.add_favorite!(@user)
|
||||
@post_1.add_favorite!(@user)
|
||||
@post_3.add_favorite!(@user)
|
||||
@@ -24,13 +24,11 @@ module PostSets
|
||||
context "a favorite set for before the most recent post" do
|
||||
setup do
|
||||
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_3.id).first.id
|
||||
::Favorite.stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id, "b#{id}")
|
||||
@set = PostSets::Favorite.new(@user.id, "b#{id}", limit: 1)
|
||||
end
|
||||
|
||||
context "a sequential paginator" do
|
||||
should "return the second most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
@@ -50,7 +48,6 @@ module PostSets
|
||||
|
||||
context "a sequential paginator" do
|
||||
should "return the second most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
@@ -70,7 +67,6 @@ module PostSets
|
||||
|
||||
context "a sequential paginator" do
|
||||
should "return the third most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_2.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
@@ -90,7 +86,6 @@ module PostSets
|
||||
|
||||
context "a sequential paginator" do
|
||||
should "return the most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
@@ -109,7 +104,6 @@ module PostSets
|
||||
|
||||
context "a numbered paginator" do
|
||||
should "return the second most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
@@ -127,7 +121,6 @@ module PostSets
|
||||
end
|
||||
|
||||
should "return the most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ module PostSets
|
||||
class IntroTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@post_1 = FactoryGirl.create(:post, :tag_string => "a")
|
||||
@post_2 = FactoryGirl.create(:post, :tag_string => "b")
|
||||
@post_3 = FactoryGirl.create(:post, :tag_string => "c")
|
||||
@post_1 = FactoryBot.create(:post, :tag_string => "a")
|
||||
@post_2 = FactoryBot.create(:post, :tag_string => "b")
|
||||
@post_3 = FactoryBot.create(:post, :tag_string => "c")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -21,8 +21,8 @@ module PostSets
|
||||
|
||||
context "a set for the 'a' tag query" do
|
||||
setup do
|
||||
@post_4 = FactoryGirl.create(:post, :tag_string => "a", :fav_count => 5)
|
||||
@post_5 = FactoryGirl.create(:post, :tag_string => "a", :fav_count => 5)
|
||||
@post_4 = FactoryBot.create(:post, :tag_string => "a", :fav_count => 5)
|
||||
@post_5 = FactoryBot.create(:post, :tag_string => "a", :fav_count => 5)
|
||||
end
|
||||
|
||||
context "with no page" do
|
||||
|
||||
@@ -4,17 +4,17 @@ module PostSets
|
||||
class PoolTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
mock_pool_archive_service!
|
||||
start_pool_archive_transaction
|
||||
|
||||
@post_1 = FactoryGirl.create(:post)
|
||||
@post_2 = FactoryGirl.create(:post)
|
||||
@post_3 = FactoryGirl.create(:post)
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@post_1 = FactoryBot.create(:post)
|
||||
@post_2 = FactoryBot.create(:post)
|
||||
@post_3 = FactoryBot.create(:post)
|
||||
@pool = FactoryBot.create(:pool)
|
||||
@pool.add!(@post_2)
|
||||
@pool.add!(@post_1)
|
||||
@pool.add!(@post_3)
|
||||
|
||||
@@ -5,13 +5,13 @@ module PostSets
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@post_1 = FactoryGirl.create(:post, :tag_string => "a")
|
||||
@post_2 = FactoryGirl.create(:post, :tag_string => "b")
|
||||
@post_3 = FactoryGirl.create(:post, :tag_string => "c")
|
||||
@post_1 = FactoryBot.create(:post, :tag_string => "a")
|
||||
@post_2 = FactoryBot.create(:post, :tag_string => "b")
|
||||
@post_3 = FactoryBot.create(:post, :tag_string => "c")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -32,8 +32,8 @@ module PostSets
|
||||
|
||||
context "a set for the 'a' tag query" do
|
||||
setup do
|
||||
@post_4 = FactoryGirl.create(:post, :tag_string => "a")
|
||||
@post_5 = FactoryGirl.create(:post, :tag_string => "a")
|
||||
@post_4 = FactoryBot.create(:post, :tag_string => "a")
|
||||
@post_5 = FactoryBot.create(:post, :tag_string => "a")
|
||||
end
|
||||
|
||||
context "with no page" do
|
||||
@@ -107,7 +107,7 @@ module PostSets
|
||||
|
||||
context "for a gold user" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:gold_user)
|
||||
CurrentUser.user = FactoryBot.create(:gold_user)
|
||||
end
|
||||
|
||||
should "pass" do
|
||||
@@ -141,7 +141,7 @@ module PostSets
|
||||
|
||||
context "that has a matching wiki page" do
|
||||
setup do
|
||||
@wiki_page = FactoryGirl.create(:wiki_page, :title => "a")
|
||||
@wiki_page = FactoryBot.create(:wiki_page, :title => "a")
|
||||
end
|
||||
|
||||
should "find the wiki page" do
|
||||
@@ -152,7 +152,7 @@ module PostSets
|
||||
|
||||
context "that has a matching artist" do
|
||||
setup do
|
||||
@artist = FactoryGirl.create(:artist, :name => "a")
|
||||
@artist = FactoryBot.create(:artist, :name => "a")
|
||||
end
|
||||
|
||||
should "find the artist" do
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@ class PostVersionTest < ActiveSupport::TestCase
|
||||
context "A post" do
|
||||
setup do
|
||||
Timecop.travel(1.month.ago) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@@ -18,7 +18,7 @@ class PostVersionTest < ActiveSupport::TestCase
|
||||
context "that has multiple versions: " do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "1")
|
||||
@post = FactoryBot.create(:post, :tag_string => "1")
|
||||
@post.update_attributes(:tag_string => "1 2")
|
||||
@post.update_attributes(:tag_string => "2 3")
|
||||
end
|
||||
@@ -37,8 +37,8 @@ class PostVersionTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been created" do
|
||||
setup do
|
||||
@parent = FactoryGirl.create(:post)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "e", :parent => @parent, :source => "xyz")
|
||||
@parent = FactoryBot.create(:post)
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "e", :parent => @parent, :source => "xyz")
|
||||
end
|
||||
|
||||
should "also create a version" do
|
||||
@@ -53,8 +53,8 @@ class PostVersionTest < ActiveSupport::TestCase
|
||||
|
||||
context "that should be merged" do
|
||||
setup do
|
||||
@parent = FactoryGirl.create(:post)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
@parent = FactoryBot.create(:post)
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
end
|
||||
|
||||
should "delete the previous version" do
|
||||
@@ -69,7 +69,7 @@ class PostVersionTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
Timecop.travel(1.minute.ago) do
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
end
|
||||
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
|
||||
end
|
||||
|
||||
@@ -4,12 +4,12 @@ class PostViewCountServiceTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
PostViewCountService.stubs(:enabled?).returns(true)
|
||||
Danbooru.config.stubs(:reportbooru_server).returns("http://localhost:1234")
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post = FactoryBot.create(:post)
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
||||
@@ -4,12 +4,12 @@ class PostVoteTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@supervoter = FactoryGirl.create(:user, is_super_voter: true)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@supervoter = FactoryBot.create(:user, is_super_voter: true)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post = FactoryBot.create(:post)
|
||||
end
|
||||
|
||||
context "Voting for a post" do
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class RelatedTagCalculatorTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -15,9 +15,9 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
|
||||
context "A related tag calculator" do
|
||||
context "for a post set" do
|
||||
setup do
|
||||
FactoryGirl.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
FactoryBot.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||
FactoryBot.create(:post, :tag_string => "aaa bbb")
|
||||
@posts = Post.tag_match("aaa")
|
||||
end
|
||||
|
||||
@@ -28,27 +28,27 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
|
||||
|
||||
should "calculate related tags for a tag" do
|
||||
posts = []
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb")
|
||||
|
||||
assert_equal({"aaa" => 3, "bbb" => 3, "ccc" => 2, "ddd" => 1}, RelatedTagCalculator.calculate_from_sample("aaa", 10))
|
||||
end
|
||||
|
||||
should "calculate related tags for multiple tag" do
|
||||
posts = []
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa eee fff")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa eee fff")
|
||||
|
||||
assert_equal({"aaa"=>2, "bbb"=>2, "ddd"=>1, "ccc"=>2}, RelatedTagCalculator.calculate_from_sample("aaa bbb", 10))
|
||||
end
|
||||
|
||||
should "calculate typed related tags for a tag" do
|
||||
posts = []
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb art:ccc copy:ddd")
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb art:ccc")
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb art:ccc copy:ddd")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb art:ccc")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb")
|
||||
|
||||
assert_equal({"ccc" => 2}, RelatedTagCalculator.calculate_from_sample("aaa", 10, Tag.categories.artist))
|
||||
assert_equal({"ddd" => 1}, RelatedTagCalculator.calculate_from_sample("aaa", 10, Tag.categories.copyright))
|
||||
@@ -56,9 +56,9 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
|
||||
|
||||
should "convert a hash into string format" do
|
||||
posts = []
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||
posts << FactoryBot.create(:post, :tag_string => "aaa bbb")
|
||||
|
||||
tag = Tag.find_by_name("aaa")
|
||||
counts = RelatedTagCalculator.calculate_from_sample("aaa", 10)
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -11,9 +11,9 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
subject { RelatedTagQuery.new("copyright") }
|
||||
|
||||
setup do
|
||||
@copyright = FactoryGirl.create(:copyright_tag, name: "copyright")
|
||||
@wiki = FactoryGirl.create(:wiki_page, title: "copyright", body: "[[list_of_hoges]]")
|
||||
@list_of_hoges = FactoryGirl.create(:wiki_page, title: "list_of_hoges", body: "[[alpha]] and [[beta]]")
|
||||
@copyright = FactoryBot.create(:copyright_tag, name: "copyright")
|
||||
@wiki = FactoryBot.create(:wiki_page, title: "copyright", body: "[[list_of_hoges]]")
|
||||
@list_of_hoges = FactoryBot.create(:wiki_page, title: "list_of_hoges", body: "[[alpha]] and [[beta]]")
|
||||
end
|
||||
|
||||
should "return tags from the associated list wiki" do
|
||||
@@ -26,8 +26,8 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
|
||||
context "a related tag query without a category constraint" do
|
||||
setup do
|
||||
@post_1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
@post_2 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
@post_1 = FactoryBot.create(:post, :tag_string => "aaa bbb")
|
||||
@post_2 = FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||
end
|
||||
|
||||
context "for a tag that already exists" do
|
||||
@@ -57,8 +57,8 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
|
||||
context "for an aliased tag" do
|
||||
setup do
|
||||
@ta = FactoryGirl.create(:tag_alias, antecedent_name: "xyz", consequent_name: "aaa")
|
||||
@wp = FactoryGirl.create(:wiki_page, title: "aaa", body: "blah [[foo|blah]] [[FOO]] [[bar]] blah")
|
||||
@ta = FactoryBot.create(:tag_alias, antecedent_name: "xyz", consequent_name: "aaa")
|
||||
@wp = FactoryBot.create(:wiki_page, title: "aaa", body: "blah [[foo|blah]] [[FOO]] [[bar]] blah")
|
||||
@query = RelatedTagQuery.new("xyz", "")
|
||||
|
||||
Tag.named("aaa").first.update_related
|
||||
@@ -85,7 +85,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
|
||||
context "for a tag with a wiki page" do
|
||||
setup do
|
||||
@wiki_page = FactoryGirl.create(:wiki_page, :title => "aaa", :body => "[[bbb]] [[ccc]]")
|
||||
@wiki_page = FactoryBot.create(:wiki_page, :title => "aaa", :body => "[[bbb]] [[ccc]]")
|
||||
@query = RelatedTagQuery.new("aaa", "")
|
||||
end
|
||||
|
||||
@@ -97,9 +97,9 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
|
||||
context "a related tag query with a category constraint" do
|
||||
setup do
|
||||
@post_1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
@post_2 = FactoryGirl.create(:post, :tag_string => "aaa art:ccc")
|
||||
@post_3 = FactoryGirl.create(:post, :tag_string => "aaa copy:ddd")
|
||||
@post_1 = FactoryBot.create(:post, :tag_string => "aaa bbb")
|
||||
@post_2 = FactoryBot.create(:post, :tag_string => "aaa art:ccc")
|
||||
@post_3 = FactoryBot.create(:post, :tag_string => "aaa copy:ddd")
|
||||
@query = RelatedTagQuery.new("aaa", "artist")
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class SavedSearchTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
mock_saved_search_service!
|
||||
@@ -17,8 +17,8 @@ class SavedSearchTest < ActiveSupport::TestCase
|
||||
|
||||
context ".labels_for" do
|
||||
setup do
|
||||
FactoryGirl.create(:saved_search, user: @user, label_string: "blah", query: "blah")
|
||||
FactoryGirl.create(:saved_search, user: @user, label_string: "zah", query: "blah")
|
||||
FactoryBot.create(:saved_search, user: @user, label_string: "blah", query: "blah")
|
||||
FactoryBot.create(:saved_search, user: @user, label_string: "zah", query: "blah")
|
||||
end
|
||||
|
||||
should "fetch the labels used by a user" do
|
||||
@@ -27,16 +27,16 @@ class SavedSearchTest < ActiveSupport::TestCase
|
||||
|
||||
should "expire when a search is updated" do
|
||||
Cache.expects(:delete).once
|
||||
FactoryGirl.create(:saved_search, user: @user, query: "blah")
|
||||
FactoryBot.create(:saved_search, user: @user, query: "blah")
|
||||
end
|
||||
end
|
||||
|
||||
context ".queries_for" do
|
||||
setup do
|
||||
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")
|
||||
FactoryGirl.create(:saved_search, user: @user, label_string: "qux", query: " aaa bbb ccc ")
|
||||
FactoryBot.create(:tag_alias, antecedent_name: "bbb", consequent_name: "ccc", creator: @user)
|
||||
FactoryBot.create(:saved_search, user: @user, label_string: "blah", query: "aaa")
|
||||
FactoryBot.create(:saved_search, user: @user, label_string: "zah", query: "CCC BBB AAA")
|
||||
FactoryBot.create(:saved_search, user: @user, label_string: "qux", query: " aaa bbb ccc ")
|
||||
end
|
||||
|
||||
should "fetch the queries used by a user for a label" do
|
||||
@@ -87,7 +87,7 @@ class SavedSearchTest < ActiveSupport::TestCase
|
||||
|
||||
context "Creating a saved search" do
|
||||
setup do
|
||||
FactoryGirl.create(:tag_alias, antecedent_name: "zzz", consequent_name: "yyy", creator: @user)
|
||||
FactoryBot.create(:tag_alias, antecedent_name: "zzz", consequent_name: "yyy", creator: @user)
|
||||
@saved_search = @user.saved_searches.create(:query => " ZZZ xxx ")
|
||||
end
|
||||
|
||||
@@ -111,7 +111,7 @@ class SavedSearchTest < ActiveSupport::TestCase
|
||||
|
||||
context "Destroying a saved search" do
|
||||
setup do
|
||||
@saved_search = @user.saved_searches.create(:tag_query => "xxx")
|
||||
@saved_search = @user.saved_searches.create(query: "xxx")
|
||||
@saved_search.destroy
|
||||
end
|
||||
|
||||
@@ -123,7 +123,7 @@ class SavedSearchTest < ActiveSupport::TestCase
|
||||
|
||||
context "A user with max saved searches" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:gold_user)
|
||||
@user = FactoryBot.create(:gold_user)
|
||||
CurrentUser.user = @user
|
||||
User.any_instance.stubs(:max_saved_searches).returns(0)
|
||||
@saved_search = @user.saved_searches.create(:query => "xxx")
|
||||
|
||||
@@ -4,7 +4,7 @@ module Sources
|
||||
class NijieTest < ActiveSupport::TestCase
|
||||
context "The source site for a nijie page" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@site = Sources::Site.new("http://nijie.info/view.php?id=213043")
|
||||
@@ -29,8 +29,8 @@ module Sources
|
||||
end
|
||||
|
||||
should "normalize ()characters in tags" do
|
||||
FactoryGirl.create(:tag, :name => "kaga")
|
||||
FactoryGirl.create(:wiki_page, :title => "kaga", :other_names => "加賀(艦これ)")
|
||||
FactoryBot.create(:tag, :name => "kaga")
|
||||
FactoryBot.create(:wiki_page, :title => "kaga", :other_names => "加賀(艦これ)")
|
||||
|
||||
@site = Sources::Site.new("http://nijie.info/view.php?id=208316")
|
||||
@site.get
|
||||
|
||||
@@ -4,6 +4,7 @@ module Sources
|
||||
class PawooTest < ActiveSupport::TestCase
|
||||
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::Site.new("https://pawoo.net/web/statuses/1202176")
|
||||
@site.get
|
||||
end
|
||||
@@ -33,6 +34,7 @@ module Sources
|
||||
|
||||
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::Site.new("https://pawoo.net/@evazion/19451018")
|
||||
@site.get
|
||||
end
|
||||
@@ -84,6 +86,7 @@ module Sources
|
||||
|
||||
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"
|
||||
@ref = "https://pawoo.net/@evazion/19451018"
|
||||
@site = Sources::Site.new(@url, referer_url: @ref)
|
||||
|
||||
@@ -160,7 +160,7 @@ module Sources
|
||||
|
||||
context "translating the tags" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
tags = {
|
||||
@@ -174,8 +174,8 @@ module Sources
|
||||
}
|
||||
|
||||
tags.each do |tag, other_names|
|
||||
FactoryGirl.create(:tag, name: tag, post_count: 1)
|
||||
FactoryGirl.create(:wiki_page, title: tag, other_names: other_names)
|
||||
FactoryBot.create(:tag, name: tag, post_count: 1)
|
||||
FactoryBot.create(:wiki_page, title: tag, other_names: other_names)
|
||||
end
|
||||
|
||||
@site = get_source("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981746")
|
||||
@@ -219,12 +219,12 @@ module Sources
|
||||
end
|
||||
|
||||
should "apply aliases to translated tags" do
|
||||
tohsaka_rin = FactoryGirl.create(:tag, name: "tohsaka_rin")
|
||||
toosaka_rin = FactoryGirl.create(:tag, name: "toosaka_rin")
|
||||
tohsaka_rin = FactoryBot.create(:tag, name: "tohsaka_rin")
|
||||
toosaka_rin = FactoryBot.create(:tag, name: "toosaka_rin")
|
||||
|
||||
FactoryGirl.create(:wiki_page, title: "tohsaka_rin", other_names: "遠坂凛")
|
||||
FactoryGirl.create(:wiki_page, title: "toosaka_rin", other_names: "遠坂凛")
|
||||
FactoryGirl.create(:tag_alias, antecedent_name: "tohsaka_rin", consequent_name: "toosaka_rin")
|
||||
FactoryBot.create(:wiki_page, title: "tohsaka_rin", other_names: "遠坂凛")
|
||||
FactoryBot.create(:wiki_page, title: "toosaka_rin", other_names: "遠坂凛")
|
||||
FactoryBot.create(:tag_alias, antecedent_name: "tohsaka_rin", consequent_name: "toosaka_rin")
|
||||
|
||||
assert_equal([toosaka_rin], @site.translate_tag("遠坂凛"))
|
||||
end
|
||||
|
||||
@@ -2,6 +2,11 @@ require 'test_helper'
|
||||
|
||||
module Sources
|
||||
class TumblrTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
skip "Tumblr key is not configured" unless Danbooru.config.tumblr_consumer_key
|
||||
end
|
||||
|
||||
context "The source for a 'http://*.tumblr.com/post/*' photo post with a single image" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://noizave.tumblr.com/post/162206271767")
|
||||
@@ -67,10 +72,10 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the artist" do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@artist = FactoryGirl.create(:artist, name: "noizave", url_string: "https://noizave.tumblr.com/")
|
||||
@artist = FactoryBot.create(:artist, name: "noizave", url_string: "https://noizave.tumblr.com/")
|
||||
assert_equal([@artist], @site.artists)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ module Sources
|
||||
class TwitterTest < ActiveSupport::TestCase
|
||||
context "A video" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/CincinnatiZoo/status/859073537713328129")
|
||||
@site.get
|
||||
end
|
||||
@@ -15,6 +16,7 @@ module Sources
|
||||
|
||||
context "An animated gif" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/DaniStrawberry1/status/859435334765088769")
|
||||
@site.get
|
||||
end
|
||||
@@ -26,6 +28,7 @@ module Sources
|
||||
|
||||
context "A twitter summary card" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/NatGeo/status/932700115936178177")
|
||||
@site.get
|
||||
end
|
||||
@@ -37,6 +40,7 @@ module Sources
|
||||
|
||||
context "A twitter summary card from twitter" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/masayasuf/status/870734961778630656/photo/1")
|
||||
@site.get
|
||||
end
|
||||
@@ -48,6 +52,7 @@ module Sources
|
||||
|
||||
context "A twitter summary card from twitter with a :large image" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/aranobu/status/817736083567820800")
|
||||
@site.get
|
||||
end
|
||||
@@ -59,6 +64,7 @@ module Sources
|
||||
|
||||
context "An extended tweet" do
|
||||
should "extract the correct image url" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/onsen_musume_jp/status/865534101918330881")
|
||||
@site.get
|
||||
|
||||
@@ -66,6 +72,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "extract all the image urls" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/aoimanabu/status/892370963630743552")
|
||||
@site.get
|
||||
|
||||
@@ -81,6 +88,7 @@ module Sources
|
||||
|
||||
context "The source site for a restricted twitter" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://mobile.twitter.com/Strangestone/status/556440271961858051")
|
||||
@site.get
|
||||
end
|
||||
@@ -92,6 +100,7 @@ module Sources
|
||||
|
||||
context "The source site for twitter" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://mobile.twitter.com/nounproject/status/540944400767922176")
|
||||
@site.get
|
||||
end
|
||||
@@ -125,6 +134,7 @@ module Sources
|
||||
|
||||
context "The source site for a direct image and a referer" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large", referer_url: "https://twitter.com/nounproject/status/540944400767922176")
|
||||
@site.get
|
||||
end
|
||||
@@ -140,6 +150,7 @@ module Sources
|
||||
|
||||
context "The source site for a https://twitter.com/i/web/status/:id url" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/i/web/status/943446161586733056")
|
||||
@site.get
|
||||
end
|
||||
@@ -151,6 +162,7 @@ module Sources
|
||||
|
||||
context "A tweet" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/noizave/status/875768175136317440")
|
||||
@site.get
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ class StorageManagerTest < ActiveSupport::TestCase
|
||||
|
||||
context "#store_file and #delete_file methods" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post, file_ext: "png")
|
||||
@post = FactoryBot.create(:post, file_ext: "png")
|
||||
|
||||
@storage_manager.store_file(StringIO.new("data"), @post, :preview)
|
||||
@storage_manager.store_file(StringIO.new("data"), @post, :large)
|
||||
@@ -76,7 +76,7 @@ class StorageManagerTest < ActiveSupport::TestCase
|
||||
|
||||
context "#file_url method" do
|
||||
should "return the correct urls" do
|
||||
@post = FactoryGirl.create(:post, file_ext: "png")
|
||||
@post = FactoryBot.create(:post, file_ext: "png")
|
||||
@storage_manager.stubs(:tagged_filenames).returns(false)
|
||||
|
||||
assert_equal("/data/#{@post.md5}.png", @storage_manager.file_url(@post, :original))
|
||||
@@ -88,8 +88,8 @@ class StorageManagerTest < ActiveSupport::TestCase
|
||||
|
||||
context "StorageManager::Hybrid" do
|
||||
setup do
|
||||
@post1 = FactoryGirl.build(:post, id: 1, file_ext: "png")
|
||||
@post2 = FactoryGirl.build(:post, id: 2, file_ext: "png")
|
||||
@post1 = FactoryBot.build(:post, id: 1, file_ext: "png")
|
||||
@post2 = FactoryBot.build(:post, id: 2, file_ext: "png")
|
||||
|
||||
@storage_manager = StorageManager::Hybrid.new do |id, md5, file_ext, type|
|
||||
if id.odd?
|
||||
|
||||
@@ -3,11 +3,11 @@ require 'test_helper'
|
||||
class TagAliasCorrectionTest < ActiveSupport::TestCase
|
||||
context "A tag alias correction" do
|
||||
setup do
|
||||
@mod = FactoryGirl.create(:moderator_user)
|
||||
@mod = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @mod
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa")
|
||||
@tag_alias = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class TagAliasRequestTest < ActiveSupport::TestCase
|
||||
context "A tag alias request" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
context "A tag alias" do
|
||||
setup do
|
||||
Timecop.travel(1.month.ago) do
|
||||
user = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
CurrentUser.user = user
|
||||
end
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@@ -18,9 +18,9 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
|
||||
context "on validation" do
|
||||
subject do
|
||||
FactoryGirl.create(:tag, :name => "aaa")
|
||||
FactoryGirl.create(:tag, :name => "bbb")
|
||||
FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
FactoryBot.create(:tag, :name => "aaa")
|
||||
FactoryBot.create(:tag, :name => "bbb")
|
||||
FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
should allow_value('active').for(:status)
|
||||
@@ -42,27 +42,25 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
|
||||
should_not allow_value(nil).for(:creator_id)
|
||||
should_not allow_value(-1).for(:creator_id).with_message("must exist", against: :creator)
|
||||
|
||||
should_not allow_mass_assignment_of(:status).as(:member)
|
||||
end
|
||||
|
||||
should "populate the creator information" do
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal(CurrentUser.user.id, ta.creator_id)
|
||||
end
|
||||
|
||||
should "convert a tag to its normalized version" do
|
||||
tag1 = FactoryGirl.create(:tag, :name => "aaa")
|
||||
tag2 = FactoryGirl.create(:tag, :name => "bbb")
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
tag1 = FactoryBot.create(:tag, :name => "aaa")
|
||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
normalized_tags = TagAlias.to_aliased(["aaa", "ccc"])
|
||||
assert_equal(["bbb", "ccc"], normalized_tags.sort)
|
||||
end
|
||||
|
||||
should "update the cache" do
|
||||
tag1 = FactoryGirl.create(:tag, :name => "aaa")
|
||||
tag2 = FactoryGirl.create(:tag, :name => "bbb")
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
tag1 = FactoryBot.create(:tag, :name => "aaa")
|
||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_nil(Cache.get("ta:#{Cache.hash("aaa")}"))
|
||||
TagAlias.to_aliased(["aaa"])
|
||||
assert_equal("bbb", Cache.get("ta:#{Cache.hash("aaa")}"))
|
||||
@@ -71,21 +69,21 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "move saved searches" do
|
||||
tag1 = FactoryGirl.create(:tag, :name => "...")
|
||||
tag2 = FactoryGirl.create(:tag, :name => "bbb")
|
||||
ss = FactoryGirl.create(:saved_search, :query => "123 ... 456", :user => CurrentUser.user)
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "...", :consequent_name => "bbb")
|
||||
tag1 = FactoryBot.create(:tag, :name => "...")
|
||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||
ss = FactoryBot.create(:saved_search, :query => "123 ... 456", :user => CurrentUser.user)
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "...", :consequent_name => "bbb")
|
||||
ss.reload
|
||||
assert_equal(%w(123 456 bbb), ss.query.scan(/\S+/).sort)
|
||||
end
|
||||
|
||||
should "update any affected posts when saved" do
|
||||
assert_equal(0, TagAlias.count)
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "ccc ddd")
|
||||
post1 = FactoryBot.create(:post, :tag_string => "aaa bbb")
|
||||
post2 = FactoryBot.create(:post, :tag_string => "ccc ddd")
|
||||
assert_equal("aaa bbb", post1.tag_string)
|
||||
assert_equal("ccc ddd", post2.tag_string)
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "ccc")
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "ccc")
|
||||
post1.reload
|
||||
post2.reload
|
||||
assert_equal("bbb ccc", post1.tag_string)
|
||||
@@ -93,9 +91,9 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not validate for transitive relations" do
|
||||
ta1 = FactoryGirl.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ta1 = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
assert_difference("TagAlias.count", 0) do
|
||||
ta2 = FactoryGirl.build(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ta2 = FactoryBot.build(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ta2.save
|
||||
assert(ta2.errors.any?, "Tag alias should be invalid")
|
||||
assert_equal("A tag alias for bbb already exists", ta2.errors.full_messages.join)
|
||||
@@ -103,50 +101,50 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "move existing aliases" do
|
||||
ta1 = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ta2 = FactoryGirl.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ta1 = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ta2 = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ta1.reload
|
||||
assert_equal("ccc", ta1.consequent_name)
|
||||
end
|
||||
|
||||
should "move existing implications" do
|
||||
ti = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti.reload
|
||||
assert_equal("ccc", ti.consequent_name)
|
||||
end
|
||||
|
||||
should "not push the antecedent's category to the consequent if the antecedent is general" do
|
||||
tag1 = FactoryGirl.create(:tag, :name => "aaa")
|
||||
tag2 = FactoryGirl.create(:tag, :name => "bbb", :category => 1)
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
tag1 = FactoryBot.create(:tag, :name => "aaa")
|
||||
tag2 = FactoryBot.create(:tag, :name => "bbb", :category => 1)
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
tag2.reload
|
||||
assert_equal(1, tag2.category)
|
||||
end
|
||||
|
||||
should "push the antecedent's category to the consequent" do
|
||||
tag1 = FactoryGirl.create(:tag, :name => "aaa", :category => 1)
|
||||
tag2 = FactoryGirl.create(:tag, :name => "bbb")
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
tag1 = FactoryBot.create(:tag, :name => "aaa", :category => 1)
|
||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
tag2.reload
|
||||
assert_equal(1, tag2.category)
|
||||
end
|
||||
|
||||
context "with an associated forum topic" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@admin = FactoryBot.create(:admin_user)
|
||||
CurrentUser.scoped(@admin) do
|
||||
@topic = FactoryGirl.create(:forum_topic, :title => TagAliasRequest.topic_title("aaa", "bbb"))
|
||||
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => TagAliasRequest.command_string("aaa", "bbb"))
|
||||
@alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
|
||||
@topic = FactoryBot.create(:forum_topic, :title => TagAliasRequest.topic_title("aaa", "bbb"))
|
||||
@post = FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => TagAliasRequest.command_string("aaa", "bbb"))
|
||||
@alias = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
|
||||
end
|
||||
end
|
||||
|
||||
context "and conflicting wiki pages" do
|
||||
setup do
|
||||
CurrentUser.scoped(@admin) do
|
||||
@wiki1 = FactoryGirl.create(:wiki_page, :title => "aaa")
|
||||
@wiki2 = FactoryGirl.create(:wiki_page, :title => "bbb")
|
||||
@wiki1 = FactoryBot.create(:wiki_page, :title => "aaa")
|
||||
@wiki2 = FactoryBot.create(:wiki_page, :title => "bbb")
|
||||
@alias.approve!(approver: @admin)
|
||||
end
|
||||
@admin.reload # reload to get the forum post the approval created.
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class TagImplicationRequestTest < ActiveSupport::TestCase
|
||||
context "A tag implication request" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
@@ -3,10 +3,10 @@ require 'test_helper'
|
||||
class TagImplicationTest < ActiveSupport::TestCase
|
||||
context "A tag implication" do
|
||||
setup do
|
||||
user = FactoryGirl.create(:admin_user)
|
||||
user = FactoryBot.create(:admin_user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -16,9 +16,9 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
|
||||
context "on validation" do
|
||||
subject do
|
||||
FactoryGirl.create(:tag, :name => "aaa")
|
||||
FactoryGirl.create(:tag, :name => "bbb")
|
||||
FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
FactoryBot.create(:tag, :name => "aaa")
|
||||
FactoryBot.create(:tag, :name => "bbb")
|
||||
FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
should allow_value('active').for(:status)
|
||||
@@ -40,62 +40,58 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
|
||||
should_not allow_value(nil).for(:creator_id)
|
||||
should_not allow_value(-1).for(:creator_id).with_message("must exist", against: :creator)
|
||||
|
||||
should_not allow_mass_assignment_of(:status).as(:member)
|
||||
should_not allow_mass_assignment_of(:forum_topic).as(:member)
|
||||
should_not allow_mass_assignment_of(:descendant_names).as(:member)
|
||||
end
|
||||
|
||||
should "ignore pending implications when building descendant names" do
|
||||
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "b", :consequent_name => "c", :status => "pending")
|
||||
ti2 = FactoryBot.build(:tag_implication, :antecedent_name => "b", :consequent_name => "c", :status => "pending")
|
||||
ti2.save
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "a", :consequent_name => "b")
|
||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "a", :consequent_name => "b")
|
||||
assert_equal("b", ti1.descendant_names)
|
||||
end
|
||||
|
||||
should "populate the creator information" do
|
||||
ti = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal(CurrentUser.user.id, ti.creator_id)
|
||||
end
|
||||
|
||||
should "not validate when a circular relation is created" do
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "bbb", :consequent_name => "aaa")
|
||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryBot.build(:tag_implication, :antecedent_name => "bbb", :consequent_name => "aaa")
|
||||
ti2.save
|
||||
assert(ti2.errors.any?, "Tag implication should not have validated.")
|
||||
assert_equal("Tag implication can not create a circular relation with another tag implication", ti2.errors.full_messages.join(""))
|
||||
end
|
||||
|
||||
should "not validate when a transitive relation is created" do
|
||||
ti_ab = FactoryGirl.create(:tag_implication, :antecedent_name => "a", :consequent_name => "b")
|
||||
ti_bc = FactoryGirl.create(:tag_implication, :antecedent_name => "b", :consequent_name => "c")
|
||||
ti_ac = FactoryGirl.build(:tag_implication, :antecedent_name => "a", :consequent_name => "c")
|
||||
ti_ab = FactoryBot.create(:tag_implication, :antecedent_name => "a", :consequent_name => "b")
|
||||
ti_bc = FactoryBot.create(:tag_implication, :antecedent_name => "b", :consequent_name => "c")
|
||||
ti_ac = FactoryBot.build(:tag_implication, :antecedent_name => "a", :consequent_name => "c")
|
||||
ti_ac.save
|
||||
|
||||
assert_equal("a already implies c through another implication", ti_ac.errors.full_messages.join(""))
|
||||
end
|
||||
|
||||
should "not allow for duplicates" do
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryBot.build(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2.save
|
||||
assert(ti2.errors.any?, "Tag implication should not have validated.")
|
||||
assert_includes(ti2.errors.full_messages, "Antecedent name has already been taken")
|
||||
end
|
||||
|
||||
should "not validate if its consequent is aliased to another tag" do
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti = FactoryGirl.build(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti = FactoryBot.build(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti.save
|
||||
assert(ti.errors.any?, "Tag implication should not have validated.")
|
||||
assert_equal("Consequent tag must not be aliased to another tag", ti.errors.full_messages.join(""))
|
||||
end
|
||||
|
||||
should "calculate all its descendants" do
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
assert_equal("ccc", ti1.descendant_names)
|
||||
assert_equal(["ccc"], ti1.descendant_names_array)
|
||||
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal("bbb ccc", ti2.descendant_names)
|
||||
assert_equal(["bbb", "ccc"], ti2.descendant_names_array)
|
||||
ti1.reload
|
||||
@@ -104,8 +100,8 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update its descendants on save" do
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
|
||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
|
||||
ti1.reload
|
||||
ti2.reload
|
||||
ti2.update_attributes(
|
||||
@@ -118,10 +114,10 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update the descendants for all of its parents on destroy" do
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "xxx", :consequent_name => "bbb")
|
||||
ti3 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti4 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
|
||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "xxx", :consequent_name => "bbb")
|
||||
ti3 = FactoryBot.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti4 = FactoryBot.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
|
||||
ti1.reload
|
||||
ti2.reload
|
||||
ti3.reload
|
||||
@@ -140,12 +136,12 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update the descendants for all of its parents on create" do
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti1.reload
|
||||
assert_equal("active", ti1.status)
|
||||
assert_equal("bbb", ti1.descendant_names)
|
||||
|
||||
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
ti1.reload
|
||||
ti2.reload
|
||||
assert_equal("active", ti1.status)
|
||||
@@ -153,14 +149,14 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
assert_equal("bbb ccc", ti1.descendant_names)
|
||||
assert_equal("ccc", ti2.descendant_names)
|
||||
|
||||
ti3 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
|
||||
ti3 = FactoryBot.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
|
||||
ti1.reload
|
||||
ti2.reload
|
||||
ti3.reload
|
||||
assert_equal("bbb ccc ddd", ti1.descendant_names)
|
||||
assert_equal("ccc ddd", ti2.descendant_names)
|
||||
|
||||
ti4 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "eee")
|
||||
ti4 = FactoryBot.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "eee")
|
||||
ti1.reload
|
||||
ti2.reload
|
||||
ti3.reload
|
||||
@@ -170,7 +166,7 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
assert_equal("ddd", ti3.descendant_names)
|
||||
assert_equal("eee", ti4.descendant_names)
|
||||
|
||||
ti5 = FactoryGirl.create(:tag_implication, :antecedent_name => "xxx", :consequent_name => "bbb")
|
||||
ti5 = FactoryBot.create(:tag_implication, :antecedent_name => "xxx", :consequent_name => "bbb")
|
||||
ti1.reload
|
||||
ti2.reload
|
||||
ti3.reload
|
||||
@@ -184,19 +180,19 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update any affected post upon save" do
|
||||
p1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "yyy")
|
||||
p1 = FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "yyy")
|
||||
p1.reload
|
||||
assert_equal("aaa bbb ccc xxx yyy", p1.tag_string)
|
||||
end
|
||||
|
||||
context "with an associated forum topic" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@topic = FactoryGirl.create(:forum_topic, :title => TagImplicationRequest.topic_title("aaa", "bbb"))
|
||||
@post = FactoryGirl.create(:forum_post, topic_id: @topic.id, :body => TagImplicationRequest.command_string("aaa", "bbb"))
|
||||
@implication = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
|
||||
@admin = FactoryBot.create(:admin_user)
|
||||
@topic = FactoryBot.create(:forum_topic, :title => TagImplicationRequest.topic_title("aaa", "bbb"))
|
||||
@post = FactoryBot.create(:forum_post, topic_id: @topic.id, :body => TagImplicationRequest.command_string("aaa", "bbb"))
|
||||
@implication = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :status => "pending")
|
||||
end
|
||||
|
||||
should "update the topic when processed" do
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class TagTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@builder = FactoryGirl.create(:builder_user)
|
||||
@builder = FactoryBot.create(:builder_user)
|
||||
CurrentUser.user = @builder
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -17,12 +17,12 @@ class TagTest < ActiveSupport::TestCase
|
||||
Tag.stubs(:trending_count_limit).returns(0)
|
||||
|
||||
Timecop.travel(1.week.ago) do
|
||||
FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
FactoryGirl.create(:post, :tag_string => "bbb")
|
||||
FactoryBot.create(:post, :tag_string => "aaa")
|
||||
FactoryBot.create(:post, :tag_string => "bbb")
|
||||
end
|
||||
|
||||
FactoryGirl.create(:post, :tag_string => "bbb")
|
||||
FactoryGirl.create(:post, :tag_string => "ccc")
|
||||
FactoryBot.create(:post, :tag_string => "bbb")
|
||||
FactoryBot.create(:post, :tag_string => "ccc")
|
||||
end
|
||||
|
||||
should "order the results by the total post count" do
|
||||
@@ -32,18 +32,18 @@ class TagTest < ActiveSupport::TestCase
|
||||
|
||||
context "A tag category fetcher" do
|
||||
should "fetch for a single tag" do
|
||||
FactoryGirl.create(:artist_tag, :name => "test")
|
||||
FactoryBot.create(:artist_tag, :name => "test")
|
||||
assert_equal(Tag.categories.artist, Tag.category_for("test"))
|
||||
end
|
||||
|
||||
should "fetch for a single tag with strange markup" do
|
||||
FactoryGirl.create(:artist_tag, :name => "!@$%")
|
||||
FactoryBot.create(:artist_tag, :name => "!@$%")
|
||||
assert_equal(Tag.categories.artist, Tag.category_for("!@$%"))
|
||||
end
|
||||
|
||||
should "fetch for multiple tags" do
|
||||
FactoryGirl.create(:artist_tag, :name => "aaa")
|
||||
FactoryGirl.create(:copyright_tag, :name => "bbb")
|
||||
FactoryBot.create(:artist_tag, :name => "aaa")
|
||||
FactoryBot.create(:copyright_tag, :name => "bbb")
|
||||
categories = Tag.categories_for(%w(aaa bbb ccc))
|
||||
assert_equal(Tag.categories.artist, categories["aaa"])
|
||||
assert_equal(Tag.categories.copyright, categories["bbb"])
|
||||
@@ -91,27 +91,13 @@ class TagTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
context "A tag" do
|
||||
should "be lockable by a moderator" do
|
||||
@tag = FactoryGirl.create(:tag)
|
||||
@tag.update_attributes({:is_locked => true}, :as => :moderator)
|
||||
@tag.reload
|
||||
assert_equal(true, @tag.is_locked?)
|
||||
end
|
||||
|
||||
should "not be lockable by a user" do
|
||||
@tag = FactoryGirl.create(:tag)
|
||||
@tag.update_attributes({:is_locked => true}, :as => :member)
|
||||
@tag.reload
|
||||
assert_equal(false, @tag.is_locked?)
|
||||
end
|
||||
|
||||
should "know its category name" do
|
||||
@tag = FactoryGirl.create(:artist_tag)
|
||||
@tag = FactoryBot.create(:artist_tag)
|
||||
assert_equal("Artist", @tag.category_name)
|
||||
end
|
||||
|
||||
should "reset its category after updating" do
|
||||
tag = FactoryGirl.create(:artist_tag)
|
||||
tag = FactoryBot.create(:artist_tag)
|
||||
assert_equal(Tag.categories.artist, Cache.get("tc:#{Cache.hash(tag.name)}"))
|
||||
|
||||
tag.update_attribute(:category, Tag.categories.copyright)
|
||||
@@ -143,8 +129,8 @@ class TagTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "parse a query" do
|
||||
tag1 = FactoryGirl.create(:tag, :name => "abc")
|
||||
tag2 = FactoryGirl.create(:tag, :name => "acb")
|
||||
tag1 = FactoryBot.create(:tag, :name => "abc")
|
||||
tag2 = FactoryBot.create(:tag, :name => "acb")
|
||||
|
||||
assert_equal(["abc"], Tag.parse_query("md5:abc")[:md5])
|
||||
assert_equal([:between, 1, 2], Tag.parse_query("id:1..2")[:post_id])
|
||||
@@ -182,14 +168,14 @@ class TagTest < ActiveSupport::TestCase
|
||||
|
||||
context "A tag" do
|
||||
should "be found when one exists" do
|
||||
tag = FactoryGirl.create(:tag)
|
||||
tag = FactoryBot.create(:tag)
|
||||
assert_difference("Tag.count", 0) do
|
||||
Tag.find_or_create_by_name(tag.name)
|
||||
end
|
||||
end
|
||||
|
||||
should "change the type for an existing tag" do
|
||||
tag = FactoryGirl.create(:tag)
|
||||
tag = FactoryBot.create(:tag)
|
||||
assert_difference("Tag.count", 0) do
|
||||
assert_equal(Tag.categories.general, tag.category)
|
||||
Tag.find_or_create_by_name("artist:#{tag.name}")
|
||||
@@ -199,7 +185,7 @@ class TagTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not change the category is the tag is locked" do
|
||||
tag = FactoryGirl.create(:tag, :is_locked => true)
|
||||
tag = FactoryBot.create(:tag, :is_locked => true)
|
||||
assert_equal(true, tag.is_locked?)
|
||||
Tag.find_or_create_by_name("artist:#{tag.name}")
|
||||
tag.reload
|
||||
@@ -207,15 +193,15 @@ class TagTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not change category when the tag is too large to be changed by a builder" do
|
||||
tag = FactoryGirl.create(:tag, post_count: 1001)
|
||||
tag = FactoryBot.create(:tag, post_count: 1001)
|
||||
Tag.find_or_create_by_name("artist:#{tag.name}", creator: @builder)
|
||||
|
||||
assert_equal(0, tag.reload.category)
|
||||
end
|
||||
|
||||
should "not change category when the tag is too large to be changed by a member" do
|
||||
tag = FactoryGirl.create(:tag, post_count: 51)
|
||||
Tag.find_or_create_by_name("artist:#{tag.name}", creator: FactoryGirl.create(:member_user))
|
||||
tag = FactoryBot.create(:tag, post_count: 51)
|
||||
Tag.find_or_create_by_name("artist:#{tag.name}", creator: FactoryBot.create(:member_user))
|
||||
|
||||
assert_equal(0, tag.reload.category)
|
||||
end
|
||||
@@ -265,8 +251,8 @@ class TagTest < ActiveSupport::TestCase
|
||||
|
||||
context "A tag with a negative post count" do
|
||||
should "be fixed" do
|
||||
tag = FactoryGirl.create(:tag, name: "touhou", post_count: -10)
|
||||
post = FactoryGirl.create(:post, tag_string: "touhou")
|
||||
tag = FactoryBot.create(:tag, name: "touhou", post_count: -10)
|
||||
post = FactoryBot.create(:post, tag_string: "touhou")
|
||||
|
||||
Tag.clean_up_negative_post_counts!
|
||||
assert_equal(1, tag.reload.post_count)
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class TokenBucketTest < ActiveSupport::TestCase
|
||||
context "#add!" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
TokenBucket.create(user_id: @user.id, last_touched_at: 1.minute.ago, token_count: 0)
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ class TokenBucketTest < ActiveSupport::TestCase
|
||||
|
||||
context "#consume!" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
TokenBucket.create(user_id: @user.id, last_touched_at: 1.minute.ago, token_count: 1)
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ class TokenBucketTest < ActiveSupport::TestCase
|
||||
|
||||
context "#throttled?" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
TokenBucket.create(user_id: @user.id, last_touched_at: 1.minute.ago, token_count: 0)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UploadTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
mock_iqdb_service!
|
||||
end
|
||||
|
||||
context "In all cases" do
|
||||
setup do
|
||||
user = FactoryGirl.create(:contributor_user)
|
||||
mock_iqdb_service!
|
||||
user = FactoryBot.create(:contributor_user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -22,12 +17,12 @@ class UploadTest < ActiveSupport::TestCase
|
||||
context "An upload" do
|
||||
context "from a user that is limited" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:user, :created_at => 1.year.ago)
|
||||
CurrentUser.user = FactoryBot.create(:user, :created_at => 1.year.ago)
|
||||
User.any_instance.stubs(:upload_limit).returns(0)
|
||||
end
|
||||
|
||||
should "fail creation" do
|
||||
@upload = FactoryGirl.build(:jpg_upload, :tag_string => "")
|
||||
@upload = FactoryBot.build(:jpg_upload, :tag_string => "")
|
||||
@upload.save
|
||||
assert_equal(["You have reached your upload limit for the day"], @upload.errors.full_messages)
|
||||
end
|
||||
@@ -35,51 +30,64 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "image size calculator" do
|
||||
should "discover the dimensions for a compressed SWF" do
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/compressed.swf"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/compressed.swf"))
|
||||
assert_equal([607, 756], @upload.calculate_dimensions)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a JPG with JFIF data" do
|
||||
@upload = FactoryGirl.create(:jpg_upload)
|
||||
@upload = FactoryBot.create(:jpg_upload)
|
||||
assert_equal([500, 335], @upload.calculate_dimensions)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a JPG with EXIF data" do
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/test-exif-small.jpg"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/test-exif-small.jpg"))
|
||||
assert_equal([529, 600], @upload.calculate_dimensions)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a JPG with no header data" do
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/test-blank.jpg"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/test-blank.jpg"))
|
||||
assert_equal([668, 996], @upload.calculate_dimensions)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a PNG" do
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/test.png"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/test.png"))
|
||||
assert_equal([768, 1024], @upload.calculate_dimensions)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a GIF" do
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/test.gif"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/test.gif"))
|
||||
assert_equal([400, 400], @upload.calculate_dimensions)
|
||||
@upload = FactoryBot.create(:upload, :file_path => "#{Rails.root}/test/files/compressed.swf")
|
||||
@upload.calculate_dimensions
|
||||
assert_equal(607, @upload.image_width)
|
||||
assert_equal(756, @upload.image_height)
|
||||
end
|
||||
end
|
||||
|
||||
context "content type calculator" do
|
||||
should "know how to parse jpeg, png, gif, and swf file headers" do
|
||||
@upload = FactoryGirl.build(:jpg_upload)
|
||||
assert_equal("jpg", @upload.file_header_to_file_ext(File.open("#{Rails.root}/test/files/test.jpg")))
|
||||
assert_equal("gif", @upload.file_header_to_file_ext(File.open("#{Rails.root}/test/files/test.gif")))
|
||||
assert_equal("png", @upload.file_header_to_file_ext(File.open("#{Rails.root}/test/files/test.png")))
|
||||
assert_equal("swf", @upload.file_header_to_file_ext(File.open("#{Rails.root}/test/files/compressed.swf")))
|
||||
assert_equal("bin", @upload.file_header_to_file_ext(File.open("#{Rails.root}/README.md")))
|
||||
@upload = FactoryBot.create(:jpg_upload)
|
||||
assert_equal("image/jpeg", @upload.file_header_to_content_type("#{Rails.root}/test/files/test.jpg"))
|
||||
assert_equal("image/gif", @upload.file_header_to_content_type("#{Rails.root}/test/files/test.gif"))
|
||||
assert_equal("image/png", @upload.file_header_to_content_type("#{Rails.root}/test/files/test.png"))
|
||||
assert_equal("application/x-shockwave-flash", @upload.file_header_to_content_type("#{Rails.root}/test/files/compressed.swf"))
|
||||
assert_equal("application/octet-stream", @upload.file_header_to_content_type("#{Rails.root}/README.md"))
|
||||
end
|
||||
|
||||
should "know how to parse jpeg, png, gif, and swf content types" do
|
||||
@upload = FactoryBot.create(:jpg_upload)
|
||||
assert_equal("jpg", @upload.content_type_to_file_ext("image/jpeg"))
|
||||
assert_equal("gif", @upload.content_type_to_file_ext("image/gif"))
|
||||
assert_equal("png", @upload.content_type_to_file_ext("image/png"))
|
||||
assert_equal("swf", @upload.content_type_to_file_ext("application/x-shockwave-flash"))
|
||||
assert_equal("bin", @upload.content_type_to_file_ext(""))
|
||||
end
|
||||
end
|
||||
|
||||
context "downloader" do
|
||||
context "for a zip that is not an ugoira" do
|
||||
should "not validate" do
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/invalid_ugoira.zip"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/invalid_ugoira.zip"))
|
||||
@upload.process!
|
||||
assert_equal("error: RuntimeError - missing frame data for ugoira", @upload.status)
|
||||
end
|
||||
@@ -88,7 +96,8 @@ class UploadTest < ActiveSupport::TestCase
|
||||
context "that is a pixiv ugoira" do
|
||||
setup do
|
||||
@url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654"
|
||||
@upload = FactoryGirl.create(:upload, :source => @url, :tag_string => "ugoira")
|
||||
@upload = FactoryBot.create(:source_upload, :source => @url, :tag_string => "ugoira")
|
||||
@output_file = Tempfile.new("download")
|
||||
end
|
||||
|
||||
should "process successfully" do
|
||||
@@ -97,34 +106,43 @@ class UploadTest < ActiveSupport::TestCase
|
||||
assert_equal("zip", @upload.file_header_to_file_ext(output_file))
|
||||
end
|
||||
end
|
||||
|
||||
should "initialize the final path after downloading a file" do
|
||||
@upload = FactoryBot.create(:source_upload)
|
||||
path = "#{Rails.root}/tmp/test.download.jpg"
|
||||
assert_nothing_raised {@upload.download_from_source(path)}
|
||||
assert(File.exists?(path))
|
||||
assert_equal(8558, File.size(path))
|
||||
assert_equal(path, @upload.file_path)
|
||||
end
|
||||
end
|
||||
|
||||
context "determining if a file is downloadable" do
|
||||
should "classify HTTP sources as downloadable" do
|
||||
@upload = FactoryGirl.create(:source_upload, :source => "http://www.example.com/1.jpg")
|
||||
@upload = FactoryBot.create(:source_upload, :source => "http://www.example.com/1.jpg")
|
||||
assert_not_nil(@upload.is_downloadable?)
|
||||
end
|
||||
|
||||
should "classify HTTPS sources as downloadable" do
|
||||
@upload = FactoryGirl.create(:source_upload, :source => "https://www.example.com/1.jpg")
|
||||
@upload = FactoryBot.create(:source_upload, :source => "https://www.example.com/1.jpg")
|
||||
assert_not_nil(@upload.is_downloadable?)
|
||||
end
|
||||
|
||||
should "classify non-HTTP/HTTPS sources as not downloadable" do
|
||||
@upload = FactoryGirl.create(:source_upload, :source => "ftp://www.example.com/1.jpg")
|
||||
@upload = FactoryBot.create(:source_upload, :source => "ftp://www.example.com/1.jpg")
|
||||
assert_nil(@upload.is_downloadable?)
|
||||
end
|
||||
end
|
||||
|
||||
context "file processor" do
|
||||
should "parse and process a cgi file representation" do
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/test.jpg"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/test.jpg"))
|
||||
assert_nothing_raised {@upload.process_upload}
|
||||
assert_equal(28086, @upload.file_size)
|
||||
end
|
||||
|
||||
should "process a transparent png" do
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/alpha.png"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/alpha.png"))
|
||||
assert_nothing_raised {@upload.process_upload}
|
||||
assert_equal(1136, @upload.file_size)
|
||||
end
|
||||
@@ -132,23 +150,27 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "hash calculator" do
|
||||
should "caculate the hash" do
|
||||
@upload = FactoryGirl.create(:jpg_upload)
|
||||
@upload.process_upload
|
||||
@upload = FactoryBot.create(:jpg_upload)
|
||||
@upload.calculate_hash(@upload.file_path)
|
||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @upload.md5)
|
||||
end
|
||||
end
|
||||
|
||||
context "resizer" do
|
||||
should "generate several resized versions of the image" do
|
||||
@upload = FactoryGirl.create(:upload, file_ext: "jpg", image_width: 1356, image_height: 911, file: upload_file("test/files/test-large.jpg"))
|
||||
preview_file, sample_file = @upload.generate_resizes
|
||||
assert_operator(preview_file.size, :>, 1_000)
|
||||
assert_operator(sample_file.size, :>, 1_000)
|
||||
@upload = FactoryBot.create(:large_jpg_upload)
|
||||
@upload.calculate_hash(@upload.file_path)
|
||||
@upload.calculate_dimensions(@upload.file_path)
|
||||
assert_nothing_raised {@upload.generate_resizes(@upload.file_path)}
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert(File.size(@upload.resized_file_path_for(Danbooru.config.small_image_width)) > 0)
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
assert(File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width)) > 0)
|
||||
end
|
||||
end
|
||||
|
||||
should "increment the uploaders post_upload_count" do
|
||||
@upload = FactoryGirl.create(:source_upload)
|
||||
@upload = FactoryBot.create(:source_upload)
|
||||
assert_difference("CurrentUser.user.post_upload_count", 1) do
|
||||
@upload.process!
|
||||
CurrentUser.user.reload
|
||||
@@ -157,11 +179,14 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "with an artist commentary" do
|
||||
setup do
|
||||
@upload = FactoryGirl.create(:source_upload,
|
||||
include_artist_commentary: "1",
|
||||
artist_commentary_title: "",
|
||||
artist_commentary_desc: "blah",
|
||||
)
|
||||
@upload = FactoryBot.create(:source_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
@upload.include_artist_commentary = "1"
|
||||
@upload.artist_commentary_title = ""
|
||||
@upload.artist_commentary_desc = "blah"
|
||||
end
|
||||
|
||||
should "create an artist commentary when processed" do
|
||||
@@ -172,7 +197,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process completely for a downloaded image" do
|
||||
@upload = FactoryGirl.create(:source_upload,
|
||||
@upload = FactoryBot.create(:source_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
@@ -198,17 +223,17 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "automatic tagging" do
|
||||
should "tag animated png files" do
|
||||
@upload = FactoryGirl.build(:upload, file_ext: "png", file: upload_file("test/files/apng/normal_apng.png"))
|
||||
@upload = FactoryBot.build(:upload, file_ext: "png", file: upload_file("test/files/apng/normal_apng.png"))
|
||||
assert_equal("animated_png", @upload.automatic_tags)
|
||||
end
|
||||
|
||||
should "tag animated gif files" do
|
||||
@upload = FactoryGirl.build(:upload, file_ext: "gif", file: upload_file("test/files/test-animated-86x52.gif"))
|
||||
@upload = FactoryBot.build(:upload, file_ext: "gif", file: upload_file("test/files/test-animated-86x52.gif"))
|
||||
assert_equal("animated_gif", @upload.automatic_tags)
|
||||
end
|
||||
|
||||
should "not tag static gif files" do
|
||||
@upload = FactoryGirl.build(:upload, file_ext: "gif", file: upload_file("test/files/test-static-32x32.gif"))
|
||||
@upload = FactoryBot.build(:upload, file_ext: "gif", file: upload_file("test/files/test-static-32x32.gif"))
|
||||
assert_equal("", @upload.automatic_tags)
|
||||
end
|
||||
end
|
||||
@@ -216,7 +241,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
context "that is too large" do
|
||||
should "should fail validation" do
|
||||
Danbooru.config.stubs(:max_image_resolution).returns(31*31)
|
||||
@upload = FactoryGirl.create(:upload, file: upload_file("test/files/test-static-32x32.gif"))
|
||||
@upload = FactoryBot.create(:upload, file: upload_file("test/files/test-static-32x32.gif"))
|
||||
@upload.process!
|
||||
assert_match(/image resolution is too large/, @upload.status)
|
||||
end
|
||||
@@ -224,7 +249,14 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process completely for a pixiv ugoira" do
|
||||
@upload = FactoryGirl.create(:source_upload, source: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654")
|
||||
skip "ffmpeg is not installed" unless check_ffmpeg
|
||||
|
||||
@upload = FactoryBot.create(:source_upload,
|
||||
:source => "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654",
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
assert_difference(["PixivUgoiraFrameData.count", "Post.count"]) do
|
||||
@upload.process!
|
||||
assert_equal([], @upload.errors.full_messages)
|
||||
@@ -241,7 +273,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process completely for an uploaded image" do
|
||||
@upload = FactoryGirl.create(:jpg_upload,
|
||||
@upload = FactoryBot.create(:jpg_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo",
|
||||
@@ -265,7 +297,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process completely for a .webm" do
|
||||
upload = FactoryGirl.create(:upload, rating: "s", file: upload_file("test/files/test-512x512.webm"))
|
||||
upload = FactoryBot.create(:upload, rating: "s", file: upload_file("test/files/test-512x512.webm"))
|
||||
|
||||
assert_difference("Post.count") do
|
||||
assert_nothing_raised { upload.process! }
|
||||
@@ -284,7 +316,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process completely for a .mp4" do
|
||||
upload = FactoryGirl.create(:upload, rating: "s", file: upload_file("test/files/test-300x300.mp4"))
|
||||
upload = FactoryBot.create(:upload, rating: "s", file: upload_file("test/files/test-300x300.mp4"))
|
||||
|
||||
assert_difference("Post.count") do
|
||||
assert_nothing_raised { upload.process! }
|
||||
@@ -303,11 +335,22 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process completely for a null source" do
|
||||
@upload = FactoryGirl.create(:jpg_upload, :source => nil)
|
||||
@upload = FactoryBot.create(:jpg_upload, :source => nil)
|
||||
|
||||
assert_difference("Post.count") do
|
||||
assert_nothing_raised {@upload.process!}
|
||||
end
|
||||
end
|
||||
|
||||
should "delete the temporary file upon completion" do
|
||||
@upload = FactoryBot.create(:source_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
|
||||
@upload.process!
|
||||
assert(!File.exists?(@upload.temp_file_path))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class UserDeletionTest < ActiveSupport::TestCase
|
||||
context "an invalid user deletion" do
|
||||
context "for an invalid password" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@deletion = UserDeletion.new(@user, "wrongpassword")
|
||||
@@ -19,7 +19,7 @@ class UserDeletionTest < ActiveSupport::TestCase
|
||||
|
||||
context "for an admin" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:admin_user)
|
||||
@user = FactoryBot.create(:admin_user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@deletion = UserDeletion.new(@user, "password")
|
||||
@@ -35,11 +35,11 @@ class UserDeletionTest < ActiveSupport::TestCase
|
||||
|
||||
context "a valid user deletion" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post = FactoryBot.create(:post)
|
||||
Favorite.add(post: @post, user: @user)
|
||||
|
||||
@user.update_attributes(:email => "ted@danbooru.com")
|
||||
|
||||
@@ -12,9 +12,9 @@ class UserFeedbackTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "create a dmail" do
|
||||
user = FactoryGirl.create(:user)
|
||||
gold = FactoryGirl.create(:gold_user)
|
||||
member = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
gold = FactoryBot.create(:gold_user)
|
||||
member = FactoryBot.create(:user)
|
||||
|
||||
dmail = <<~EOS.chomp
|
||||
@#{gold.name} created a "positive record":/user_feedbacks?search[user_id]=#{user.id} for your account:
|
||||
@@ -24,30 +24,30 @@ class UserFeedbackTest < ActiveSupport::TestCase
|
||||
|
||||
CurrentUser.user = gold
|
||||
assert_difference("Dmail.count", 1) do
|
||||
FactoryGirl.create(:user_feedback, :user => user, :body => "good job!")
|
||||
FactoryBot.create(:user_feedback, :user => user, :body => "good job!")
|
||||
assert_equal(dmail, user.dmails.last.body)
|
||||
end
|
||||
end
|
||||
|
||||
should "not validate if the creator is the user" do
|
||||
gold_user = FactoryGirl.create(:gold_user)
|
||||
gold_user = FactoryBot.create(:gold_user)
|
||||
CurrentUser.user = gold_user
|
||||
feedback = FactoryGirl.build(:user_feedback, :user => gold_user)
|
||||
feedback = FactoryBot.build(:user_feedback, :user => gold_user)
|
||||
feedback.save
|
||||
assert_equal(["You cannot submit feedback for yourself"], feedback.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not validate if the creator is not gold" do
|
||||
user = FactoryGirl.create(:user)
|
||||
gold = FactoryGirl.create(:gold_user)
|
||||
member = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
gold = FactoryBot.create(:gold_user)
|
||||
member = FactoryBot.create(:user)
|
||||
|
||||
CurrentUser.user = gold
|
||||
feedback = FactoryGirl.create(:user_feedback, :user => user)
|
||||
feedback = FactoryBot.create(:user_feedback, :user => user)
|
||||
assert(feedback.errors.empty?)
|
||||
|
||||
CurrentUser.user = member
|
||||
feedback = FactoryGirl.build(:user_feedback, :user => user)
|
||||
feedback = FactoryBot.build(:user_feedback, :user => user)
|
||||
feedback.save
|
||||
assert_equal(["You must be gold"], feedback.errors.full_messages)
|
||||
end
|
||||
|
||||
@@ -3,8 +3,8 @@ require 'test_helper'
|
||||
class UserNameChangeRequestTest < ActiveSupport::TestCase
|
||||
context "in all cases" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
@requester = FactoryGirl.create(:user)
|
||||
@admin = FactoryBot.create(:admin_user)
|
||||
@requester = FactoryBot.create(:user)
|
||||
CurrentUser.user = @requester
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -93,7 +93,7 @@ class UserNameChangeRequestTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not convert the desired name to lower case" do
|
||||
uncr = FactoryGirl.create(:user_name_change_request, user: @requester, original_name: "provence.", desired_name: "Provence")
|
||||
uncr = FactoryBot.create(:user_name_change_request, user: @requester, original_name: "provence.", desired_name: "Provence")
|
||||
CurrentUser.scoped(@admin) { uncr.approve! }
|
||||
|
||||
assert_equal("Provence", @requester.name)
|
||||
|
||||
@@ -4,8 +4,8 @@ class UserPasswordResetNonceTest < ActiveSupport::TestCase
|
||||
context "Creating a new nonce" do
|
||||
context "with a valid email" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user, :email => "aaa@b.net")
|
||||
@nonce = FactoryGirl.create(:user_password_reset_nonce, :email => @user.email)
|
||||
@user = FactoryBot.create(:user, :email => "aaa@b.net")
|
||||
@nonce = FactoryBot.create(:user_password_reset_nonce, :email => @user.email)
|
||||
end
|
||||
|
||||
should "validate" do
|
||||
@@ -24,7 +24,7 @@ class UserPasswordResetNonceTest < ActiveSupport::TestCase
|
||||
|
||||
context "with a blank email" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user, :email => "")
|
||||
@user = FactoryBot.create(:user, :email => "")
|
||||
@nonce = UserPasswordResetNonce.new(:email => "")
|
||||
end
|
||||
|
||||
|
||||
@@ -3,23 +3,18 @@ require 'test_helper'
|
||||
class UserRevertTest < ActiveSupport::TestCase
|
||||
context "Reverting a user's changes" do
|
||||
setup do
|
||||
@creator = FactoryGirl.create(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@creator = create(:user)
|
||||
@user = create(:user)
|
||||
|
||||
CurrentUser.scoped(@creator) do
|
||||
@parent = FactoryGirl.create(:post)
|
||||
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
@parent = create(:post)
|
||||
@post = create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
end
|
||||
|
||||
@post.stubs(:merge_version?).returns(false)
|
||||
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "", :rating => "e")
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
CurrentUser.scoped(@user) do
|
||||
@post.update(:tag_string => "bbb ccc xxx", :source => "", :rating => "e")
|
||||
end
|
||||
end
|
||||
|
||||
subject { UserRevert.new(@user.id) }
|
||||
@@ -32,7 +27,9 @@ class UserRevertTest < ActiveSupport::TestCase
|
||||
|
||||
context "when processed" do
|
||||
setup do
|
||||
subject.process
|
||||
CurrentUser.as(@user) do
|
||||
subject.process
|
||||
end
|
||||
@post.reload
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
context "A user" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
@@ -15,7 +15,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
context "promoting a user" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:moderator_user)
|
||||
CurrentUser.user = FactoryBot.create(:moderator_user)
|
||||
end
|
||||
|
||||
should "create a neutral feedback" do
|
||||
@@ -27,7 +27,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "send an automated dmail to the user" do
|
||||
bot = FactoryGirl.create(:user)
|
||||
bot = FactoryBot.create(:user)
|
||||
User.stubs(:system).returns(bot)
|
||||
|
||||
assert_difference("Dmail.count", 1) do
|
||||
@@ -40,7 +40,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been invited by a mod" do
|
||||
setup do
|
||||
@mod = FactoryGirl.create(:moderator_user)
|
||||
@mod = FactoryBot.create(:moderator_user)
|
||||
end
|
||||
|
||||
should "work" do
|
||||
@@ -60,10 +60,9 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not validate if the originating ip address is banned" do
|
||||
FactoryGirl.create(:ip_ban)
|
||||
user = FactoryGirl.build(:user)
|
||||
FactoryBot.create(:ip_ban, ip_addr: '127.0.0.1')
|
||||
user = FactoryBot.build(:user)
|
||||
user.save
|
||||
assert(user.errors.any?)
|
||||
assert_equal("IP address is banned", user.errors.full_messages.join)
|
||||
end
|
||||
|
||||
@@ -74,13 +73,13 @@ class UserTest < ActiveSupport::TestCase
|
||||
assert_equal(10, @user.upload_limit)
|
||||
|
||||
9.times do
|
||||
FactoryGirl.create(:post, :uploader => @user, :is_pending => true)
|
||||
FactoryBot.create(:post, :uploader => @user, :is_pending => true)
|
||||
end
|
||||
|
||||
@user = User.find(@user.id)
|
||||
assert_equal(1, @user.upload_limit)
|
||||
assert(@user.can_upload?)
|
||||
FactoryGirl.create(:post, :uploader => @user, :is_pending => true)
|
||||
FactoryBot.create(:post, :uploader => @user, :is_pending => true)
|
||||
@user = User.find(@user.id)
|
||||
assert(!@user.can_upload?)
|
||||
end
|
||||
@@ -90,8 +89,8 @@ class UserTest < ActiveSupport::TestCase
|
||||
Danbooru.config.stubs(:member_comment_limit).returns(10)
|
||||
assert(@user.can_comment_vote?)
|
||||
10.times do
|
||||
comment = FactoryGirl.create(:comment)
|
||||
FactoryGirl.create(:comment_vote, :comment_id => comment.id, :score => -1)
|
||||
comment = FactoryBot.create(:comment)
|
||||
FactoryBot.create(:comment_vote, :comment_id => comment.id, :score => -1)
|
||||
end
|
||||
|
||||
assert(!@user.can_comment_vote?)
|
||||
@@ -108,14 +107,14 @@ class UserTest < ActiveSupport::TestCase
|
||||
assert(@user.can_comment?)
|
||||
assert(!@user.is_comment_limited?)
|
||||
(Danbooru.config.member_comment_limit).times do
|
||||
FactoryGirl.create(:comment)
|
||||
FactoryBot.create(:comment)
|
||||
end
|
||||
assert(@user.is_comment_limited?)
|
||||
end
|
||||
|
||||
should "verify" do
|
||||
assert(@user.is_verified?)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.generate_email_verification_key
|
||||
@user.save
|
||||
assert(!@user.is_verified?)
|
||||
@@ -132,21 +131,21 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "normalize its level" do
|
||||
user = FactoryGirl.create(:user, :level => User::Levels::ADMIN)
|
||||
user = FactoryBot.create(:user, :level => User::Levels::ADMIN)
|
||||
assert(user.is_moderator?)
|
||||
assert(user.is_gold?)
|
||||
|
||||
user = FactoryGirl.create(:user, :level => User::Levels::MODERATOR)
|
||||
user = FactoryBot.create(:user, :level => User::Levels::MODERATOR)
|
||||
assert(!user.is_admin?)
|
||||
assert(user.is_moderator?)
|
||||
assert(user.is_gold?)
|
||||
|
||||
user = FactoryGirl.create(:user, :level => User::Levels::GOLD)
|
||||
user = FactoryBot.create(:user, :level => User::Levels::GOLD)
|
||||
assert(!user.is_admin?)
|
||||
assert(!user.is_moderator?)
|
||||
assert(user.is_gold?)
|
||||
|
||||
user = FactoryGirl.create(:user)
|
||||
user = FactoryBot.create(:user)
|
||||
assert(!user.is_admin?)
|
||||
assert(!user.is_moderator?)
|
||||
assert(!user.is_gold?)
|
||||
@@ -159,36 +158,36 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
should "not contain whitespace" do
|
||||
# U+2007: https://en.wikipedia.org/wiki/Figure_space
|
||||
user = FactoryGirl.build(:user, :name => "foo\u2007bar")
|
||||
user = FactoryBot.build(:user, :name => "foo\u2007bar")
|
||||
user.save
|
||||
assert_equal(["Name cannot have whitespace or colons"], user.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not contain a colon" do
|
||||
user = FactoryGirl.build(:user, :name => "a:b")
|
||||
user = FactoryBot.build(:user, :name => "a:b")
|
||||
user.save
|
||||
assert_equal(["Name cannot have whitespace or colons"], user.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not begin with an underscore" do
|
||||
user = FactoryGirl.build(:user, :name => "_x")
|
||||
user = FactoryBot.build(:user, :name => "_x")
|
||||
user.save
|
||||
assert_equal(["Name cannot begin or end with an underscore"], user.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not end with an underscore" do
|
||||
user = FactoryGirl.build(:user, :name => "x_")
|
||||
user = FactoryBot.build(:user, :name => "x_")
|
||||
user.save
|
||||
assert_equal(["Name cannot begin or end with an underscore"], user.errors.full_messages)
|
||||
end
|
||||
|
||||
should "be fetched given a user id" do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
assert_equal(@user.name, User.id_to_name(@user.id))
|
||||
end
|
||||
|
||||
should "be updated" do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.update_attribute(:name, "danzig")
|
||||
assert_equal(@user.name, User.id_to_name(@user.id))
|
||||
end
|
||||
@@ -196,7 +195,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
context "ip address" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
context "in the json representation" do
|
||||
@@ -214,7 +213,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
context "password" do
|
||||
should "match the cookie hash" do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.password = "zugzug5"
|
||||
@user.password_confirmation = "zugzug5"
|
||||
@user.save
|
||||
@@ -223,7 +222,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "match the confirmation" do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.old_password = "password"
|
||||
@user.password = "zugzug5"
|
||||
@user.password_confirmation = "zugzug5"
|
||||
@@ -233,7 +232,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "fail if the confirmation does not match" do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.password = "zugzug6"
|
||||
@user.password_confirmation = "zugzug5"
|
||||
@user.save
|
||||
@@ -241,7 +240,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not be too short" do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
@user.password = "x5"
|
||||
@user.password_confirmation = "x5"
|
||||
@user.save
|
||||
@@ -249,38 +248,38 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "should be reset" do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
new_pass = @user.reset_password
|
||||
assert(User.authenticate(@user.name, new_pass), "Authentication should have succeeded")
|
||||
end
|
||||
|
||||
should "not change the password if the password and old password are blank" do
|
||||
@user = FactoryGirl.create(:user, :password => "67890")
|
||||
@user = FactoryBot.create(:user, :password => "67890")
|
||||
@user.update_attributes(:password => "", :old_password => "")
|
||||
assert(@user.bcrypt_password == User.sha1("67890"))
|
||||
end
|
||||
|
||||
should "not change the password if the old password is incorrect" do
|
||||
@user = FactoryGirl.create(:user, :password => "67890")
|
||||
@user = FactoryBot.create(:user, :password => "67890")
|
||||
@user.update_attributes(:password => "12345", :old_password => "abcdefg")
|
||||
assert(@user.bcrypt_password == User.sha1("67890"))
|
||||
end
|
||||
|
||||
should "not change the password if the old password is blank" do
|
||||
@user = FactoryGirl.create(:user, :password => "67890")
|
||||
@user = FactoryBot.create(:user, :password => "67890")
|
||||
@user.update_attributes(:password => "12345", :old_password => "")
|
||||
assert(@user.bcrypt_password == User.sha1("67890"))
|
||||
end
|
||||
|
||||
should "change the password if the old password is correct" do
|
||||
@user = FactoryGirl.create(:user, :password => "67890")
|
||||
@user = FactoryBot.create(:user, :password => "67890")
|
||||
@user.update_attributes(:password => "12345", :old_password => "67890")
|
||||
assert(@user.bcrypt_password == User.sha1("12345"))
|
||||
end
|
||||
|
||||
context "in the json representation" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
should "not appear" do
|
||||
@@ -290,7 +289,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
context "in the xml representation" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
should "not appear" do
|
||||
@@ -301,13 +300,13 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
context "that might be a sock puppet" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user, last_ip_addr: "127.0.0.2")
|
||||
@user = FactoryBot.create(:user, last_ip_addr: "127.0.0.2")
|
||||
Danbooru.config.unstub(:enable_sock_puppet_validation?)
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
CurrentUser.scoped(nil, "127.0.0.2") do
|
||||
@user = FactoryGirl.build(:user)
|
||||
@user = FactoryBot.build(:user)
|
||||
@user.save
|
||||
assert_equal(["Last ip addr was used recently for another account and cannot be reused for another day"], @user.errors.full_messages)
|
||||
end
|
||||
@@ -316,9 +315,9 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
context "when searched by name" do
|
||||
should "match wildcards" do
|
||||
user1 = FactoryGirl.create(:user, :name => "foo")
|
||||
user2 = FactoryGirl.create(:user, :name => "foo*bar")
|
||||
user3 = FactoryGirl.create(:user, :name => "bar\*baz")
|
||||
user1 = FactoryBot.create(:user, :name => "foo")
|
||||
user2 = FactoryBot.create(:user, :name => "foo*bar")
|
||||
user3 = FactoryBot.create(:user, :name => "bar\*baz")
|
||||
|
||||
assert_equal([user2.id, user1.id], User.search(name: "foo*").map(&:id))
|
||||
assert_equal([user2.id], User.search(name: "foo\*bar").map(&:id))
|
||||
|
||||
@@ -13,17 +13,17 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
context "A wiki page" do
|
||||
context "that is locked" do
|
||||
should "not be editable by a member" do
|
||||
CurrentUser.user = FactoryGirl.create(:moderator_user)
|
||||
@wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true)
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = FactoryBot.create(:moderator_user)
|
||||
@wiki_page = FactoryBot.create(:wiki_page, :is_locked => true)
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
@wiki_page.update_attributes(:body => "hello")
|
||||
assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages)
|
||||
end
|
||||
|
||||
should "be editable by a moderator" do
|
||||
CurrentUser.user = FactoryGirl.create(:moderator_user)
|
||||
@wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true)
|
||||
CurrentUser.user = FactoryGirl.create(:moderator_user)
|
||||
CurrentUser.user = FactoryBot.create(:moderator_user)
|
||||
@wiki_page = FactoryBot.create(:wiki_page, :is_locked => true)
|
||||
CurrentUser.user = FactoryBot.create(:moderator_user)
|
||||
@wiki_page.update_attributes(:body => "hello")
|
||||
assert_equal([], @wiki_page.errors.full_messages)
|
||||
end
|
||||
@@ -31,9 +31,9 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
|
||||
context "updated by a moderator" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:moderator_user)
|
||||
@user = FactoryBot.create(:moderator_user)
|
||||
CurrentUser.user = @user
|
||||
@wiki_page = FactoryGirl.create(:wiki_page)
|
||||
@wiki_page = FactoryBot.create(:wiki_page)
|
||||
end
|
||||
|
||||
should "allow the is_locked attribute to be updated" do
|
||||
@@ -45,14 +45,14 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
|
||||
context "updated by a regular user" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
@wiki_page = FactoryGirl.create(:wiki_page, :title => "HOT POTATO", :other_names => "foo*bar baz")
|
||||
@wiki_page = FactoryBot.create(:wiki_page, :title => "HOT POTATO", :other_names => "foo*bar baz")
|
||||
end
|
||||
|
||||
should "not allow the is_locked attribute to be updated" do
|
||||
@wiki_page.update_attributes(:is_locked => true)
|
||||
assert_equal(["Is locked can be modified by builders only", "Is locked and cannot be updated"], @wiki_page.errors.full_messages)
|
||||
assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages)
|
||||
@wiki_page.reload
|
||||
assert_equal(false, @wiki_page.is_locked?)
|
||||
end
|
||||
@@ -79,7 +79,7 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
|
||||
should "create versions" do
|
||||
assert_difference("WikiPageVersion.count") do
|
||||
@wiki_page = FactoryGirl.create(:wiki_page, :title => "xxx")
|
||||
@wiki_page = FactoryBot.create(:wiki_page, :title => "xxx")
|
||||
end
|
||||
|
||||
assert_difference("WikiPageVersion.count") do
|
||||
@@ -102,7 +102,7 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "differentiate between updater and creator" do
|
||||
another_user = FactoryGirl.create(:user)
|
||||
another_user = FactoryBot.create(:user)
|
||||
CurrentUser.scoped(another_user, "127.0.0.1") do
|
||||
@wiki_page.title = "yyy"
|
||||
@wiki_page.save
|
||||
|
||||
Reference in New Issue
Block a user