closes #1653
This commit is contained in:
Toks
2013-10-26 00:08:37 -04:00
parent 06995dd11b
commit 11871d88b6
8 changed files with 44 additions and 77 deletions

View File

@@ -1,7 +1,7 @@
class ArtistsController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only, :except => [:index, :show, :banned]
before_filter :builder_only, :only => [:edit_name, :update_name, :destroy]
before_filter :builder_only, :only => [:destroy]
before_filter :admin_only, :only => [:ban]
def new
@@ -14,17 +14,6 @@ class ArtistsController < ApplicationController
respond_with(@artist)
end
def edit_name
@artist = Artist.find(params[:id])
respond_with(@artist)
end
def update_name
@artist = Artist.find(params[:id])
@artist.rename!(params[:artist][:name])
respond_with(@artist)
end
def banned
@artists = Artist.where("is_banned = ?", true).order("name")
respond_with(@artists) do |format|
@@ -79,7 +68,12 @@ class ArtistsController < ApplicationController
def update
@artist = Artist.find(params[:id])
@artist.update_attributes(params[:artist], :as => CurrentUser.role)
body = params[:artist].delete("notes")
@artist.assign_attributes(params[:artist], :as => CurrentUser.role)
if body
@artist.notes = body
end
@artist.save
respond_with(@artist)
end

View File

@@ -80,18 +80,6 @@ class Artist < ActiveRecord::Base
def other_names_comma=(string)
self.other_names = string.split(/,/).map {|x| Artist.normalize_name(x)}.join(" ")
end
def rename!(new_name)
new_wiki_page = WikiPage.titled(new_name).first
if new_wiki_page && wiki_page
# Merge the old wiki page into the new one
new_wiki_page.update_attributes(:body => new_wiki_page.body + "\n\n" + notes)
elsif wiki_page
wiki_page.update_attribute(:title, new_name)
end
reload
update_attribute(:name, new_name)
end
end
module GroupMethods
@@ -159,9 +147,21 @@ class Artist < ActiveRecord::Base
end
def notes=(msg)
if name_changed? && name_was.present?
old_wiki_page = WikiPage.titled(name_was).first
end
if wiki_page
wiki_page.body = msg
wiki_page.save if wiki_page.body_changed? || wiki_page.title_changed?
if name_changed? && name_was.present?
wiki_page.body = wiki_page.body + "\n\n" + msg
else
wiki_page.body = msg
end
wiki_page.save if wiki_page.body_changed?
elsif old_wiki_page
old_wiki_page.title = name
old_wiki_page.body = msg
old_wiki_page.save if old_wiki_page.body_changed? || old_wiki_page.title_changed?
elsif msg.present?
self.wiki_page = WikiPage.new(:title => name, :body => msg)
end

View File

@@ -1,7 +1,7 @@
<%= simple_form_for(@artist) do |f| %>
<div class="input">
<label for="artist_name">Name</label>
<% if @artist.new_record? %>
<% if @artist.new_record? || CurrentUser.user.is_builder? %>
<%= text_field "artist", "name" %>
[<%= link_to "check", "#", :id => "check-name-link" %>]
<span id="check-name-result"></span>

View File

@@ -12,9 +12,6 @@
<% if CurrentUser.is_member? %>
<li><%= link_to "Edit", edit_artist_path(@artist) %></li>
<% end %>
<% if CurrentUser.is_builder? %>
<li><%= link_to "Rename", edit_name_artist_path(@artist) %></li>
<% end %>
<li><%= link_to "History", artist_versions_path(:search => {:artist_id => @artist.id}) %></li>
<% if @artist.deletable_by?(CurrentUser.user) %>
<% if @artist.is_active? %>

View File

@@ -1,20 +0,0 @@
<div id="c-artists">
<div id="a-edit">
<h1>Rename Artist</h1>
<%= form_tag(update_name_artist_path(@artist), :class => "simple_form", :method => :put) do %>
<div class="input">
<label for="artist_name">Name</label>
<%= text_field :artist, :name %>
[<%= link_to "check", "#", :id => "check-name-link" %>]
<span id="check-name-result"></span>
</div>
<div><%= submit_tag "Submit" %></div>
<% end %>
</div>
</div>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Rename Artist - <%= Danbooru.config.app_name %>
<% end %>

View File

@@ -60,8 +60,6 @@ Danbooru::Application.routes.draw do
member do
put :revert
put :ban
get :edit_name
put :update_name
post :undelete
end
collection do

View File

@@ -57,6 +57,28 @@ class ArtistsControllerTest < ActionController::TestCase
assert_redirected_to(artist_path(@artist))
end
context "when renaming an artist" do
should "automatically rename the artist's wiki page" do
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
wiki_page = artist.wiki_page
assert_difference("WikiPage.count", 0) do
post :update, {:id => artist.id, :artist => {:name => "bbb", :notes => "more testing"}}, {:user_id => @user.id}
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
artist = FactoryGirl.create(:artist, :name => "aaa")
existing_wiki_page = FactoryGirl.create(:wiki_page, :title => "bbb", :body => "xxx")
post :update, {:id => artist.id, :artist => {:name => "bbb", :notes => "yyy"}}, {:user_id => @user.id}
existing_wiki_page.reload
assert_equal("bbb", existing_wiki_page.title)
assert_equal("xxx\n\nyyy", existing_wiki_page.body)
end
end
should "revert an artist" do
@artist.update_attributes(:name => "xyz")
@artist.update_attributes(:name => "abc")

View File

@@ -14,30 +14,6 @@ class ArtistTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
context "#rename!" do
setup do
@artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "xxx")
end
should "rename the wiki page" do
wiki_page = @artist.wiki_page
@artist.rename!("bbb")
assert_equal("bbb", @artist.name)
wiki_page.reload
assert_equal("bbb", wiki_page.title)
end
should "merge the old wiki page into the new one if a wiki page for the new name already exists" do
FactoryGirl.create(:wiki_page, :title => "bbb", :body => "abcabc")
wiki_page = @artist.wiki_page
@artist.rename!("bbb")
wiki_page.reload
@artist.reload
assert_equal("xxx", wiki_page.body)
assert_equal("abcabc\n\nxxx", @artist.wiki_page.body)
end
end
context "with a matching tag alias" do
setup do
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")