artists: don't create new version when nothing changed.

Fix an issue where saving an artist entry without changing anything
would create a new artist version.
This commit is contained in:
evazion
2018-10-04 19:37:18 -05:00
parent 03cc3dfa50
commit bb5f291112
2 changed files with 41 additions and 9 deletions

View File

@@ -493,15 +493,44 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal(Tag.categories.artist, tag.category)
end
context "when updated" do
context "when saving" do
setup do
@artist = FactoryBot.create(:artist)
@artist = FactoryBot.create(:artist, url_string: "http://foo.com")
@artist.stubs(:merge_version?).returns(false)
end
should "create a new version" do
should "create a new version when an url is added" do
assert_difference("ArtistVersion.count") do
@artist.update(:url_string => "http://foo.com")
@artist.update(:url_string => "http://foo.com http://bar.com")
assert_equal(%w[http://bar.com http://foo.com], @artist.versions.last.url_array)
end
end
should "create a new version when an url is removed" do
assert_difference("ArtistVersion.count") do
@artist.update(:url_string => "")
assert_equal(%w[], @artist.versions.last.url_array)
end
end
should "create a new version when an url is marked inactive" do
assert_difference("ArtistVersion.count") do
@artist.update(:url_string => "-http://foo.com")
assert_equal(%w[-http://foo.com], @artist.versions.last.url_array)
end
end
should "not create a new version when nothing has changed" do
assert_no_difference("ArtistVersion.count") do
@artist.save
assert_equal(%w[http://foo.com], @artist.versions.last.url_array)
end
end
should "not save invalid urls" do
assert_no_difference("ArtistVersion.count") do
@artist.update(:url_string => "http://foo.com www.example.com")
assert_equal(%w[http://foo.com], @artist.versions.last.url_array)
end
end
end