artists: simplify artist url saving code.

Refactor the way artist urls are saved so that artist url validations
run before the artist is saved, not after.
This commit is contained in:
evazion
2017-07-29 00:26:00 -05:00
parent 4b635628cc
commit 6121b8cb25
2 changed files with 25 additions and 25 deletions

View File

@@ -168,11 +168,16 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal(["minko"], Artist.find_all_by_url("http://minko.com/x/test.jpg").map(&:name))
end
should "not allow duplicates" do
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")
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")
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)
assert_equal([], Artist.find_all_by_url("http://warhol.com/a/image.jpg").map(&:name))
@@ -407,5 +412,18 @@ class ArtistTest < ActiveSupport::TestCase
tag.reload
assert_equal(Tag.categories.artist, tag.category)
end
context "when updated" do
setup do
@artist = FactoryGirl.create(:artist)
@artist.stubs(:merge_version?).returns(false)
end
should "create a new version" do
assert_difference("@artist.versions.count") do
@artist.update(:url_string => "http://foo.com")
end
end
end
end
end