fixes #1653
This commit is contained in:
@@ -2,6 +2,7 @@ class ArtistsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show, :banned]
|
||||
before_filter :admin_only, :only => [:ban]
|
||||
before_filter :builder_only, :only => [:edit_name, :update_name]
|
||||
|
||||
def new
|
||||
@artist = Artist.new_with_defaults(params)
|
||||
@@ -20,7 +21,7 @@ class ArtistsController < ApplicationController
|
||||
|
||||
def update_name
|
||||
@artist = Artist.find(params[:id])
|
||||
@artist.update_attribute(:name, params[:artist][:name])
|
||||
@artist.rename!(params[:artist][:name])
|
||||
respond_with(@artist)
|
||||
end
|
||||
|
||||
|
||||
@@ -78,6 +78,18 @@ 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
|
||||
# Merge the old wiki page into the new one
|
||||
new_wiki_page.update_attributes(:body => new_wiki_page.body + "\n\n" + notes)
|
||||
else
|
||||
wiki_page.update_attribute(:title, new_name)
|
||||
end
|
||||
reload
|
||||
update_attribute(:name, new_name)
|
||||
end
|
||||
end
|
||||
|
||||
module GroupMethods
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
<li><%= link_to "Show", artist_path(@artist) %></li>
|
||||
<% if CurrentUser.is_member? %>
|
||||
<li><%= link_to "Edit", edit_artist_path(@artist) %></li>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_builder? %>
|
||||
<li><%= link_to "Edit name", edit_name_artist_path(@artist) %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "History", artist_versions_path(:search => {:artist_id => @artist.id}) %></li>
|
||||
|
||||
@@ -14,6 +14,30 @@ 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")
|
||||
|
||||
Reference in New Issue
Block a user