2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "test_helper"
|
2010-02-15 13:59:58 -05:00
|
|
|
|
|
|
|
class ArtistUrlTest < ActiveSupport::TestCase
|
2018-09-15 14:03:51 -04:00
|
|
|
def assert_search_equals(results, conditions)
|
|
|
|
assert_equal(results.map(&:id), subject.search(conditions).map(&:id))
|
|
|
|
end
|
|
|
|
|
2010-02-15 14:17:08 -05:00
|
|
|
context "An artist url" do
|
|
|
|
setup do
|
2022-11-25 15:06:54 -05:00
|
|
|
CurrentUser.user = create(:user)
|
2011-11-06 10:12:23 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2018-05-16 18:33:32 -04:00
|
|
|
should "allow urls to be marked as inactive" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "http://monet.com", is_active: false)
|
2018-05-16 18:33:32 -04:00
|
|
|
assert_equal("http://monet.com", url.url)
|
|
|
|
assert_equal("http://monet.com/", url.normalized_url)
|
2018-10-04 18:38:44 -04:00
|
|
|
assert_equal("-http://monet.com", url.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
should "disallow invalid urls" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = build(:artist_url, url: "www.example.com")
|
2018-10-04 18:38:44 -04:00
|
|
|
|
|
|
|
assert_equal(false, url.valid?)
|
|
|
|
assert_match(/must begin with http/, url.errors.full_messages.join)
|
2018-05-16 18:33:32 -04:00
|
|
|
end
|
|
|
|
|
2010-02-15 14:17:08 -05:00
|
|
|
should "always add a trailing slash when normalized" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "http://monet.com")
|
2010-02-15 14:17:08 -05:00
|
|
|
assert_equal("http://monet.com", url.url)
|
|
|
|
assert_equal("http://monet.com/", url.normalized_url)
|
|
|
|
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "http://monet.com/")
|
2010-02-15 14:17:08 -05:00
|
|
|
assert_equal("http://monet.com/", url.url)
|
|
|
|
assert_equal("http://monet.com/", url.normalized_url)
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2013-02-21 16:13:06 -05:00
|
|
|
should "normalise https" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "https://google.com")
|
2013-02-21 16:13:06 -05:00
|
|
|
assert_equal("https://google.com", url.url)
|
|
|
|
assert_equal("http://google.com/", url.normalized_url)
|
|
|
|
end
|
2010-02-15 14:17:08 -05:00
|
|
|
|
2018-09-05 20:14:24 -04:00
|
|
|
should "normalise domains to lowercase" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "https://ArtistName.example.com")
|
2018-09-05 20:14:24 -04:00
|
|
|
assert_equal("http://artistname.example.com/", url.normalized_url)
|
|
|
|
end
|
|
|
|
|
2015-08-07 18:09:30 -04:00
|
|
|
should "normalize nico seiga artist urls" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "http://seiga.nicovideo.jp/user/illust/7017777")
|
2018-08-06 20:39:25 -04:00
|
|
|
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", url.normalized_url)
|
2015-08-07 18:09:30 -04:00
|
|
|
end
|
|
|
|
|
2015-08-11 20:28:58 -04:00
|
|
|
should "normalize hentai foundry artist urls" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "http://pictures.hentai-foundry.com/a/AnimeFlux/219123.jpg")
|
2015-08-11 20:28:58 -04:00
|
|
|
assert_equal("http://pictures.hentai-foundry.com/a/AnimeFlux/219123.jpg/", url.normalized_url)
|
|
|
|
end
|
|
|
|
|
2018-08-30 20:24:44 -04:00
|
|
|
should "normalize pixiv stacc urls" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "https://www.pixiv.net/stacc/evazion")
|
2018-08-30 20:24:44 -04:00
|
|
|
assert_equal("https://www.pixiv.net/stacc/evazion", url.url)
|
|
|
|
assert_equal("http://www.pixiv.net/stacc/evazion/", url.normalized_url)
|
|
|
|
end
|
|
|
|
|
2018-09-04 15:53:58 -04:00
|
|
|
should "normalize pixiv fanbox account urls" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "http://www.pixiv.net/fanbox/creator/3113804")
|
2018-09-04 15:53:58 -04:00
|
|
|
assert_equal("http://www.pixiv.net/fanbox/creator/3113804", url.url)
|
|
|
|
assert_equal("http://www.pixiv.net/fanbox/creator/3113804/", url.normalized_url)
|
|
|
|
end
|
|
|
|
|
2018-09-16 14:34:03 -04:00
|
|
|
should "normalize https://twitter.com/intent/user?user_id=* urls" do
|
2022-11-25 15:06:54 -05:00
|
|
|
url = create(:artist_url, url: "https://twitter.com/intent/user?user_id=2784590030")
|
2018-09-16 14:34:03 -04:00
|
|
|
assert_equal("https://twitter.com/intent/user?user_id=2784590030", url.url)
|
|
|
|
assert_equal("http://twitter.com/intent/user?user_id=2784590030/", url.normalized_url)
|
|
|
|
end
|
2018-09-15 14:03:51 -04:00
|
|
|
context "#search method" do
|
|
|
|
subject { ArtistUrl }
|
|
|
|
|
|
|
|
should "work" do
|
2024-07-20 14:45:36 -04:00
|
|
|
@bkub = create(:artist, name: "bkub", url_string: "https://bkub.com")
|
2022-11-26 06:37:22 -05:00
|
|
|
as(create(:admin_user)) do
|
2024-07-20 14:45:36 -04:00
|
|
|
@masao = create(:artist, name: "masao", url_string: "-https://masao.com")
|
2022-02-19 11:07:58 -05:00
|
|
|
end
|
2018-09-15 14:03:51 -04:00
|
|
|
@bkub_url = @bkub.urls.first
|
|
|
|
@masao_url = @masao.urls.first
|
|
|
|
|
|
|
|
assert_search_equals([@bkub_url], is_active: true)
|
|
|
|
assert_search_equals([@bkub_url], artist: { name: "bkub" })
|
|
|
|
|
|
|
|
assert_search_equals([@bkub_url], url_matches: "*bkub*")
|
|
|
|
|
|
|
|
assert_search_equals([@bkub_url], normalized_url_matches: "*bkub*")
|
2022-10-13 12:22:07 -04:00
|
|
|
assert_search_equals([@bkub_url], normalized_url_matches: "http://bkub.com")
|
2018-09-15 14:03:51 -04:00
|
|
|
|
|
|
|
assert_search_equals([@bkub_url], url: "https://bkub.com")
|
|
|
|
end
|
|
|
|
end
|
2010-02-15 13:59:58 -05:00
|
|
|
end
|
|
|
|
end
|