forked from e621ng/e621ng
[Artists] Fix reverting removing urls when validations fail
This commit is contained in:
parent
a3d9e9dcd2
commit
eb7033dbc2
@ -208,6 +208,11 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
def url_string=(string)
|
||||
# FIXME: This is a hack. Setting an association directly immediatly updates without regard for the parents validity.
|
||||
# As a consequence, removing urls always works. This does not create a new ArtistVersion.
|
||||
# This fix isn't great but it's the best I came up with without rather large changes.
|
||||
return unless valid?
|
||||
|
||||
url_string_was = url_string
|
||||
|
||||
self.urls = string.to_s.scan(/[^[:space:]]+/).map do |url|
|
||||
|
@ -337,6 +337,43 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
assert_equal("artist_user_unlinked", mod_action.action)
|
||||
assert_equal({ "artist_page" => @artist.id, "user_id" => user.id }, mod_action.values)
|
||||
end
|
||||
|
||||
should "fail if the user is limited" do
|
||||
@artist.url_string = "https://e621.net"
|
||||
as(create(:user)) { @artist.save }
|
||||
|
||||
@artist.reload
|
||||
assert_equal("https://e621.net", @artist.url_string)
|
||||
|
||||
Danbooru.config.stubs(:disable_throttles?).returns(false)
|
||||
Danbooru.config.stubs(:artist_edit_limit).returns(0)
|
||||
|
||||
@artist.url_string = ""
|
||||
assert_no_difference(-> { ArtistVersion.count }) do
|
||||
as(create(:user)) { @artist.save }
|
||||
end
|
||||
|
||||
@artist.reload
|
||||
assert_equal("https://e621.net", @artist.url_string)
|
||||
end
|
||||
|
||||
should "not change urls when locked" do
|
||||
@artist.url_string = "https://e621.net"
|
||||
as(create(:user)) { @artist.save }
|
||||
|
||||
@artist.reload
|
||||
assert_equal("https://e621.net", @artist.url_string)
|
||||
|
||||
@artist.update_column(:is_locked, true)
|
||||
|
||||
@artist.url_string = "https://e926.net"
|
||||
assert_no_difference(-> { ArtistVersion.count }) do
|
||||
as(create(:user)) { @artist.save }
|
||||
end
|
||||
|
||||
@artist.reload
|
||||
assert_equal("https://e621.net", @artist.url_string)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user