artists: improve prefilling of new artist form (#4028)

* When creating an artist by clicking the '?' next to the artist tag in
  the tag list, prefill the new artist form by finding the artist's last
  upload and fetching its source data.

  Previously we filled the urls with the source of the artist's last
  upload, which was wrong because it was usually a direct image URL (#3078).

* Fix the other names field not escaping spaces within names to underscores.

* Fix the other names field being potentially prefilled with duplicate names.
This commit is contained in:
evazion
2018-12-27 15:03:11 -06:00
parent 286bf2f285
commit 2170961f47
5 changed files with 52 additions and 11 deletions

View File

@@ -550,5 +550,26 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal(1, @artist.urls.count)
end
end
context "#new_with_defaults" do
should "fetch the defaults from the given source" do
source = "https://i.pximg.net/img-original/img/2018/01/28/23/56/50/67014762_p0.jpg"
artist = Artist.new_with_defaults(source: source)
assert_equal("niceandcool", artist.name)
assert_equal("nice_and_cool", artist.other_names_string)
assert_equal("https://www.pixiv.net/member.php?id=906442", artist.url_string)
end
should "fetch the defaults from the given tag" do
source = "https://i.pximg.net/img-original/img/2018/01/28/23/56/50/67014762_p0.jpg"
FactoryBot.create(:post, source: source, tag_string: "test_artist")
artist = Artist.new_with_defaults(name: "test_artist")
assert_equal("test_artist", artist.name)
assert_equal("nice_and_cool", artist.other_names_string)
assert_equal("https://www.pixiv.net/member.php?id=906442", artist.url_string)
end
end
end
end