artists: fix artist finder to return nothing if it finds too many duplicates
This commit is contained in:
@@ -235,6 +235,9 @@ module ArtistFinder
|
|||||||
break if url =~ SITE_BLACKLIST_REGEXP
|
break if url =~ SITE_BLACKLIST_REGEXP
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Assume no matches if we found too may duplicates.
|
||||||
|
return Artist.none if artists.size >= 4
|
||||||
|
|
||||||
Artist.where(id: artists.uniq.take(20))
|
Artist.where(id: artists.uniq.take(20))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -200,6 +200,11 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
assert_artist_found("warhol", "http://warhol.com/x/test.jpg")
|
assert_artist_found("warhol", "http://warhol.com/x/test.jpg")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "not return duplicates if too many artists found" do
|
||||||
|
create_list(:artist, 5, url_string: "https://www.example.com")
|
||||||
|
assert_artist_not_found("https://www.example.com/image.jpg")
|
||||||
|
end
|
||||||
|
|
||||||
should "not include duplicate urls" do
|
should "not include duplicate urls" do
|
||||||
artist = FactoryBot.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)
|
assert_equal(["http://foo.com"], artist.url_array)
|
||||||
|
|||||||
Reference in New Issue
Block a user