artists: fix artist bans not being recorded in artist history.

Using update_column bypasses callbacks, so a new artist version wasn't
created when the is_banned flag was changed.
This commit is contained in:
evazion
2020-05-04 02:54:10 -05:00
parent 6937c40747
commit 66c8c1f53f
3 changed files with 15 additions and 7 deletions

View File

@@ -178,7 +178,7 @@ class Artist < ApplicationRecord
post.update(tag_string: fixed_tags)
end
update_column(:is_banned, false)
update!(is_banned: false)
ModAction.log("unbanned artist ##{id}", :artist_unban)
end
end
@@ -195,7 +195,7 @@ class Artist < ApplicationRecord
tag_implication.approve!(approver: banner)
end
update_column(:is_banned, true)
update!(is_banned: true)
ModAction.log("banned artist ##{id}", :artist_ban)
end
end

View File

@@ -111,7 +111,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
context "unban action" do
should "unban an artist" do
@artist.ban!(banner: @admin)
as(@admin) { @artist.ban!(banner: @admin) }
put_auth unban_artist_path(@artist.id), @admin
assert_redirected_to(@artist)

View File

@@ -74,13 +74,17 @@ class ArtistTest < ActiveSupport::TestCase
end
should "allow unbanning" do
assert_equal(true, @artist.reload.is_banned?)
assert_equal(true, @post.reload.is_banned?)
assert_equal(true, @artist.versions.last.is_banned?)
assert_difference("TagImplication.count", -1) do
@artist.unban!
end
@post.reload
@artist.reload
assert(!@artist.is_banned?, "artist should not be banned")
assert(!@post.is_banned?, "post should not be banned")
assert_equal(false, @artist.reload.is_banned?)
assert_equal(false, @post.reload.is_banned?)
assert_equal(false, @artist.versions.last.is_banned?)
assert_equal("aaa", @post.tag_string)
end
@@ -102,6 +106,10 @@ class ArtistTest < ActiveSupport::TestCase
ta = TagImplication.where(:antecedent_name => "aaa", :consequent_name => "banned_artist").first
assert_equal(@admin.id, ta.approver.id)
end
should "update the artist history" do
assert_equal(true, @artist.versions.last.is_banned?)
end
end
should "normalize its name" do