fixes #1897
This commit is contained in:
@@ -95,20 +95,44 @@ class Artist < ActiveRecord::Base
|
|||||||
module VersionMethods
|
module VersionMethods
|
||||||
def create_version(force=false)
|
def create_version(force=false)
|
||||||
if name_changed? || url_string_changed? || is_active_changed? || is_banned_changed? || other_names_changed? || group_name_changed? || notes_changed? || force
|
if name_changed? || url_string_changed? || is_active_changed? || is_banned_changed? || other_names_changed? || group_name_changed? || notes_changed? || force
|
||||||
ArtistVersion.create(
|
if merge_version?
|
||||||
:artist_id => id,
|
merge_version
|
||||||
:name => name,
|
else
|
||||||
:updater_id => CurrentUser.user.id,
|
create_new_version
|
||||||
:updater_ip_addr => CurrentUser.ip_addr,
|
end
|
||||||
:url_string => url_string,
|
|
||||||
:is_active => is_active,
|
|
||||||
:is_banned => is_banned,
|
|
||||||
:other_names => other_names,
|
|
||||||
:group_name => group_name
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_new_version
|
||||||
|
ArtistVersion.create(
|
||||||
|
:artist_id => id,
|
||||||
|
:name => name,
|
||||||
|
:updater_id => CurrentUser.user.id,
|
||||||
|
:updater_ip_addr => CurrentUser.ip_addr,
|
||||||
|
:url_string => url_string,
|
||||||
|
:is_active => is_active,
|
||||||
|
:is_banned => is_banned,
|
||||||
|
:other_names => other_names,
|
||||||
|
:group_name => group_name
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def merge_version
|
||||||
|
prev = versions.last
|
||||||
|
prev.update_attributes(
|
||||||
|
:url_string => url_string,
|
||||||
|
:is_active => is_active,
|
||||||
|
:is_banned => is_banned,
|
||||||
|
:other_names => other_names,
|
||||||
|
:group_name => group_name
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def merge_version?
|
||||||
|
prev = versions.last
|
||||||
|
prev && prev.updater_id == CurrentUser.user.id && prev.updated_at > 1.hour.ago
|
||||||
|
end
|
||||||
|
|
||||||
def revert_to!(version)
|
def revert_to!(version)
|
||||||
self.name = version.name
|
self.name = version.name
|
||||||
self.url_string = version.url_string
|
self.url_string = version.url_string
|
||||||
|
|||||||
@@ -185,7 +185,9 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_difference("ArtistVersion.count") do
|
assert_difference("ArtistVersion.count") do
|
||||||
artist.other_names = "xxx"
|
artist.other_names = "xxx"
|
||||||
artist.save
|
Timecop.travel(1.day.from_now) do
|
||||||
|
artist.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
first_version = ArtistVersion.first
|
first_version = ArtistVersion.first
|
||||||
|
|||||||
Reference in New Issue
Block a user