2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "test_helper"
|
2010-03-10 18:21:43 -05:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
2010-12-01 18:50:04 -05:00
|
|
|
context "An artists controller" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
@admin = create(:admin_user)
|
|
|
|
@user = create(:user)
|
2022-11-26 06:49:35 -05:00
|
|
|
as(@user) do
|
2018-04-02 13:51:26 -04:00
|
|
|
@artist = create(:artist, notes: "message")
|
|
|
|
@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
|
2010-12-01 18:50:04 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
should "get the new page" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get_auth new_artist_path, @user
|
2010-12-01 18:50:04 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
should "get the show_or_new page for an existing artist" do
|
|
|
|
get_auth show_or_new_artists_path(name: "masao"), @user
|
2017-02-05 17:22:34 -05:00
|
|
|
assert_redirected_to(@masao)
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2017-02-05 17:22:34 -05:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
should "get the show_or_new page for a nonexisting artist" do
|
|
|
|
get_auth show_or_new_artists_path(name: "nobody"), @user
|
2017-07-06 19:17:21 -04:00
|
|
|
assert_response :success
|
2017-02-05 17:22:34 -05:00
|
|
|
end
|
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
should "get the edit page" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get_auth edit_artist_path(@artist.id), @user
|
2010-12-01 18:50:04 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
should "get the show page" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get artist_path(@artist.id)
|
2010-12-01 18:50:04 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
should "get the index page" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get artists_path
|
2010-12-01 18:50:04 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2024-08-03 17:15:26 -04:00
|
|
|
context "when creating an artist" do
|
|
|
|
should "work" do
|
|
|
|
attributes = attributes_for(:artist)
|
|
|
|
assert_difference("Artist.count", 1) do
|
|
|
|
attributes.delete(:is_active)
|
|
|
|
post_auth artists_path, @user, params: { artist: attributes }
|
|
|
|
end
|
|
|
|
|
|
|
|
artist = Artist.find_by_name(attributes[:name])
|
|
|
|
assert_not_nil(artist)
|
|
|
|
assert_redirected_to(artist_path(artist.id))
|
2010-12-01 18:50:04 -05:00
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2017-04-18 18:57:20 -04:00
|
|
|
context "with an artist that has notes" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
as(@admin) do
|
2018-10-04 22:55:17 -04:00
|
|
|
@artist = create(:artist, name: "aaa", notes: "testing", url_string: "http://example.com")
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2017-04-18 18:57:20 -04:00
|
|
|
@wiki_page = @artist.wiki_page
|
2018-04-02 13:51:26 -04:00
|
|
|
@another_user = create(:user)
|
2017-04-18 18:57:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
should "update an artist" do
|
|
|
|
old_timestamp = @wiki_page.updated_at
|
2018-04-02 13:51:26 -04:00
|
|
|
travel_to(1.minute.from_now) do
|
2018-05-25 13:16:52 -04:00
|
|
|
put_auth artist_path(@artist.id), @user, params: {artist: {notes: "rex", url_string: "http://example.com\nhttp://monet.com"}}
|
2017-04-18 18:57:20 -04:00
|
|
|
end
|
|
|
|
@artist.reload
|
2018-04-02 13:51:26 -04:00
|
|
|
@wiki_page = @artist.wiki_page
|
2017-04-18 18:57:20 -04:00
|
|
|
assert_equal("rex", @artist.notes)
|
|
|
|
assert_not_equal(old_timestamp, @wiki_page.updated_at)
|
2018-04-02 13:51:26 -04:00
|
|
|
assert_redirected_to(artist_path(@artist.id))
|
2017-04-18 18:57:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
should "not touch the updater_id and updated_at fields when nothing is changed" do
|
|
|
|
old_timestamp = @wiki_page.updated_at
|
|
|
|
old_updater_id = @wiki_page.updater_id
|
|
|
|
|
2022-11-26 07:52:37 -05:00
|
|
|
travel_to(1.minute.from_now) do
|
2018-04-02 13:51:26 -04:00
|
|
|
as(@another_user) do
|
|
|
|
@artist.update(notes: "testing")
|
2017-04-18 18:57:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
@artist.reload
|
|
|
|
@wiki_page = @artist.wiki_page
|
2023-02-27 07:00:28 -05:00
|
|
|
assert_in_delta(old_timestamp.to_i, @wiki_page.updated_at.to_i, 1)
|
2017-04-18 18:57:20 -04:00
|
|
|
assert_equal(old_updater_id, @wiki_page.updater_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when renaming an artist" do
|
|
|
|
should "automatically rename the artist's wiki page" do
|
|
|
|
assert_difference("WikiPage.count", 0) do
|
2018-04-02 13:51:26 -04:00
|
|
|
put_auth artist_path(@artist.id), @user, params: {artist: {name: "bbb", notes: "more testing"}}
|
2017-04-18 18:57:20 -04:00
|
|
|
end
|
|
|
|
@wiki_page.reload
|
|
|
|
assert_equal("bbb", @wiki_page.title)
|
|
|
|
assert_equal("more testing", @wiki_page.body)
|
|
|
|
end
|
|
|
|
end
|
2010-12-01 18:50:04 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2024-07-20 14:45:36 -04:00
|
|
|
context "destroy action" do
|
|
|
|
should "work" do
|
|
|
|
assert_difference({ "Artist.count" => -1, "ModAction.count" => 1 }) do
|
|
|
|
delete_auth artist_path(@artist), @admin
|
|
|
|
end
|
|
|
|
assert_redirected_to(artists_path)
|
|
|
|
assert_raises(ActiveRecord::RecordNotFound) { @artist.reload }
|
|
|
|
end
|
2017-02-05 17:22:34 -05:00
|
|
|
end
|
|
|
|
|
2016-10-11 00:07:28 -04:00
|
|
|
context "reverting an artist" do
|
|
|
|
should "work" do
|
2022-11-26 06:49:35 -05:00
|
|
|
as(@user) do
|
2018-04-02 13:51:26 -04:00
|
|
|
@artist.update(name: "xyz")
|
|
|
|
@artist.update(name: "abc")
|
|
|
|
end
|
2016-10-11 00:07:28 -04:00
|
|
|
version = @artist.versions.first
|
2018-04-02 13:51:26 -04:00
|
|
|
put_auth revert_artist_path(@artist.id), @user, params: {version_id: version.id}
|
2016-10-11 00:07:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
should "not allow reverting to a previous version of another artist" do
|
2022-11-26 06:49:35 -05:00
|
|
|
as(@user) do
|
2018-04-02 13:51:26 -04:00
|
|
|
@artist2 = create(:artist)
|
|
|
|
end
|
|
|
|
put_auth artist_path(@artist.id), @user, params: {version_id: @artist2.versions.first.id}
|
2016-10-11 00:07:28 -04:00
|
|
|
@artist.reload
|
|
|
|
assert_not_equal(@artist.name, @artist2.name)
|
2018-04-02 13:51:26 -04:00
|
|
|
assert_redirected_to(artist_path(@artist.id))
|
2016-10-11 00:07:28 -04:00
|
|
|
end
|
2010-12-01 18:50:04 -05:00
|
|
|
end
|
2024-08-03 17:15:26 -04:00
|
|
|
|
|
|
|
context "with a dnp entry" do
|
|
|
|
setup do
|
|
|
|
@bd_user = create(:bd_staff_user)
|
|
|
|
CurrentUser.user = @bd_user
|
|
|
|
@avoid_posting = create(:avoid_posting, artist: @artist)
|
|
|
|
end
|
|
|
|
|
|
|
|
should "not allow destroying" do
|
|
|
|
assert_no_difference("Artist.count") do
|
|
|
|
delete_auth artist_path(@artist), @bd_user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# technical restriction
|
|
|
|
should "not allow destroying even if the dnp is inactive" do
|
|
|
|
@avoid_posting.update(is_active: false)
|
|
|
|
assert_no_difference("Artist.count") do
|
|
|
|
delete_auth artist_path(@artist), @bd_user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
should "not allow editing protected properties" do
|
|
|
|
@janitor = create(:janitor_user)
|
|
|
|
name = @artist.name
|
|
|
|
group_name = @artist.group_name
|
|
|
|
other_names = @artist.other_names
|
|
|
|
assert_no_difference("ModAction.count") do
|
|
|
|
put_auth artist_path(@artist), @janitor, params: { artist: { name: "another_name", group_name: "some_group", other_names: "some other names" } }
|
|
|
|
end
|
|
|
|
|
|
|
|
@artist.reload
|
|
|
|
assert_equal(name, @artist.name)
|
|
|
|
assert_equal(group_name, @artist.group_name)
|
|
|
|
assert_equal(other_names, @artist.other_names)
|
|
|
|
assert_equal(name, @artist.wiki_page.reload.title)
|
|
|
|
assert_equal(name, @avoid_posting.reload.artist_name)
|
|
|
|
end
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
|
|
|
end
|