/artists: add wildcard, regex search to url field (#3900)
Allow searching the URL field by regex or by wildcard. If the query looks like `/twitter/` do a regex search, otherwise if it looks like `http://www.twitter.com/*` do a wildcard search, otherwise if it looks like an url do an artist finder search, lastly if it looks like `twitter` do a `*twitter*` search.
This commit is contained in:
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class ArtistTest < ActiveSupport::TestCase
|
||||
def assert_artist_found(expected_name, source_url)
|
||||
artists = Artist.url_matches(source_url).to_a
|
||||
artists = Artist.find_artists(source_url).to_a
|
||||
|
||||
assert_equal(1, artists.size)
|
||||
assert_equal(expected_name, artists.first.name, "Testing URL: #{source_url}")
|
||||
@@ -11,7 +11,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
def assert_artist_not_found(source_url)
|
||||
artists = Artist.url_matches(source_url).to_a
|
||||
artists = Artist.find_artists(source_url).to_a
|
||||
assert_equal(0, artists.size, "Testing URL: #{source_url}")
|
||||
rescue Net::OpenTimeout
|
||||
skip "Remote connection failed for #{source_url}"
|
||||
@@ -427,6 +427,15 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
assert_not_nil(Artist.search(:any_name_matches => "/cat/").first)
|
||||
end
|
||||
|
||||
should "search on url and return matches" do
|
||||
bkub = FactoryBot.create(:artist, name: "bkub", url_string: "http://bkub.com")
|
||||
|
||||
assert_equal([bkub.id], Artist.search(url_matches: "bkub").map(&:id))
|
||||
assert_equal([bkub.id], Artist.search(url_matches: "*bkub*").map(&:id))
|
||||
assert_equal([bkub.id], Artist.search(url_matches: "/rifyu|bkub/").map(&:id))
|
||||
assert_equal([bkub.id], Artist.search(url_matches: "http://bkub.com/test.jpg").map(&:id))
|
||||
end
|
||||
|
||||
should "search on has_tag and return matches" do
|
||||
post = FactoryBot.create(:post, tag_string: "bkub")
|
||||
bkub = FactoryBot.create(:artist, name: "bkub")
|
||||
|
||||
Reference in New Issue
Block a user