forked from e621ng/e621ng
[Artists] Fix wiki page renaming on alias approval
It was trying to set the body to nil since @notes wasn't set.
This commit is contained in:
parent
9d1d195fa2
commit
6a530993bc
@ -353,18 +353,14 @@ class Artist < ApplicationRecord
|
||||
if persisted? && saved_change_to_name? && attribute_before_last_save("name").present? && WikiPage.titled(attribute_before_last_save("name")).exists?
|
||||
# we're renaming the artist, so rename the corresponding wiki page
|
||||
old_page = WikiPage.titled(name_before_last_save).first
|
||||
|
||||
if wiki_page.present?
|
||||
# a wiki page with the new name already exists, so update the content
|
||||
wiki_page.update(body: "#{wiki_page.body}\n\n#{@notes}")
|
||||
else
|
||||
if wiki_page.nil?
|
||||
# a wiki page doesn't already exist for the new name, so rename the old one
|
||||
old_page.update(title: name, body: @notes)
|
||||
old_page.update(title: name, body: @notes || old_page.body)
|
||||
end
|
||||
elsif wiki_page.nil?
|
||||
# if there are any notes, we need to create a new wiki page
|
||||
if @notes.present?
|
||||
wp = create_wiki_page(body: @notes, title: name)
|
||||
create_wiki_page(body: @notes, title: name)
|
||||
end
|
||||
elsif (!@notes.nil? && (wiki_page.body != @notes)) || wiki_page.title != name
|
||||
# if anything changed, we need to update the wiki page
|
||||
|
@ -99,16 +99,6 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal("bbb", @wiki_page.title)
|
||||
assert_equal("more testing", @wiki_page.body)
|
||||
end
|
||||
|
||||
should "merge the new notes with the existing wiki page's contents if a wiki page for the new name already exists" do
|
||||
as(@user) do
|
||||
@existing_wiki_page = create(:wiki_page, title: "bbb", body: "xxx")
|
||||
end
|
||||
put_auth artist_path(@artist.id), @user, params: {artist: {name: "bbb", notes: "yyy"}}
|
||||
@existing_wiki_page.reload
|
||||
assert_equal("bbb", @existing_wiki_page.title)
|
||||
assert_equal("xxx\n\nyyy", @existing_wiki_page.body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user