artists/edit: refactor editing nested wiki pages.
Refactor to use accepts_nested_attributes_for instead of the notes attribute to facilitate editing wikis on the artist edit page. This fixes the notes attribute unintentionally showing up in the API. This also changes it so that renaming an artist entry doesn't automatically rename the corresponding wiki page. This had bad behavior when there was a conflict between wiki pages (the wikis would be silently merged, which usually isn't what you want). It also didn't warn about wiki links being broken by renames.
This commit is contained in:
@@ -32,7 +32,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
@admin = create(:admin_user)
|
||||
@user = create(:user)
|
||||
as_user do
|
||||
@artist = create(:artist, notes: "message")
|
||||
@artist = create(:artist)
|
||||
@masao = create(:artist, name: "masao", url_string: "http://www.pixiv.net/member.php?id=32777")
|
||||
@artgerm = create(:artist, name: "artgerm", url_string: "http://artgerm.deviantart.com/")
|
||||
end
|
||||
@@ -135,23 +135,23 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to(artist_path(artist.id))
|
||||
end
|
||||
|
||||
context "with an artist that has notes" do
|
||||
context "with an artist that has a wiki page" do
|
||||
setup do
|
||||
as(@admin) do
|
||||
@artist = create(:artist, name: "aaa", notes: "testing", url_string: "http://example.com")
|
||||
@artist = create(:artist, name: "aaa", url_string: "http://example.com")
|
||||
@wiki_page = create(:wiki_page, title: "aaa", body: "testing")
|
||||
end
|
||||
@wiki_page = @artist.wiki_page
|
||||
@another_user = create(:user)
|
||||
end
|
||||
|
||||
should "update an artist" do
|
||||
should "update the wiki with the artist" do
|
||||
old_timestamp = @wiki_page.updated_at
|
||||
travel(1.minute) do
|
||||
put_auth artist_path(@artist.id), @user, params: {artist: {notes: "rex", url_string: "http://example.com\nhttp://monet.com"}}
|
||||
put_auth artist_path(@artist.id), @user, params: {artist: { wiki_page_attributes: { body: "rex" }, url_string: "http://example.com\nhttp://monet.com"}}
|
||||
end
|
||||
@artist.reload
|
||||
@wiki_page = @artist.wiki_page
|
||||
assert_equal("rex", @artist.notes)
|
||||
assert_equal("rex", @artist.wiki_page.body)
|
||||
assert_not_equal(old_timestamp, @wiki_page.updated_at)
|
||||
assert_redirected_to(artist_path(@artist.id))
|
||||
end
|
||||
@@ -160,31 +160,10 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
old_timestamp = @wiki_page.updated_at
|
||||
|
||||
travel(1.minute)
|
||||
as(@another_user) { @artist.update(notes: "testing") }
|
||||
as(@another_user) { @artist.update(wiki_page_attributes: { body: "testing" }) }
|
||||
|
||||
assert_equal(old_timestamp.to_i, @artist.reload.wiki_page.updated_at.to_i)
|
||||
end
|
||||
|
||||
context "when renaming an artist" do
|
||||
should "automatically rename the artist's wiki page" do
|
||||
assert_difference("WikiPage.count", 0) do
|
||||
put_auth artist_path(@artist.id), @user, params: {artist: {name: "bbb", notes: "more testing"}}
|
||||
end
|
||||
@wiki_page.reload
|
||||
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
|
||||
|
||||
should "delete an artist" do
|
||||
|
||||
Reference in New Issue
Block a user