Merge pull request #125 from finnlabs/pulls/708/journal_class_name_in_attribute
Bug #708: AAJ does not create journals, when models are created using sub classes
This commit is contained in:
commit
ba0ded88c3
@ -115,4 +115,29 @@ class JournalTest < ActiveSupport::TestCase
|
|||||||
assert_equal "Test setting fields on Journal from Issue", @issue.last_journal.notes
|
assert_equal "Test setting fields on Journal from Issue", @issue.last_journal.notes
|
||||||
assert_equal @issue.author, @issue.last_journal.user
|
assert_equal @issue.author, @issue.last_journal.user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "subclasses of journaled models should have journal of parent type" do
|
||||||
|
Ticket = Class.new(Issue)
|
||||||
|
|
||||||
|
project = Project.generate!
|
||||||
|
ticket = Ticket.new do |t|
|
||||||
|
t.project = project
|
||||||
|
t.subject = "Test initial journal"
|
||||||
|
t.tracker = project.trackers.first
|
||||||
|
t.author = User.generate!
|
||||||
|
t.description = "Some content"
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
oldstdout = $stdout
|
||||||
|
$stdout = StringIO.new
|
||||||
|
ticket.save!
|
||||||
|
assert $stdout.string.empty?, "No errors should be logged to stdout."
|
||||||
|
ensure
|
||||||
|
$stdout = oldstdout
|
||||||
|
end
|
||||||
|
|
||||||
|
journal = ticket.journals.first
|
||||||
|
assert_equal IssueJournal, journal.class
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -32,6 +32,10 @@ module Redmine
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
attr_writer :journal_class_name
|
||||||
|
def journal_class_name
|
||||||
|
defined?(@journal_class_name) ? @journal_class_name : superclass.journal_class_name
|
||||||
|
end
|
||||||
|
|
||||||
def plural_name
|
def plural_name
|
||||||
self.name.underscore.pluralize
|
self.name.underscore.pluralize
|
||||||
@ -55,6 +59,8 @@ module Redmine
|
|||||||
def acts_as_journalized(options = {}, &block)
|
def acts_as_journalized(options = {}, &block)
|
||||||
activity_hash, event_hash, journal_hash = split_option_hashes(options)
|
activity_hash, event_hash, journal_hash = split_option_hashes(options)
|
||||||
|
|
||||||
|
self.journal_class_name = journal_hash.delete(:class_name) || "#{name.gsub("::", "_")}Journal"
|
||||||
|
|
||||||
acts_as_activity(activity_hash)
|
acts_as_activity(activity_hash)
|
||||||
|
|
||||||
return if journaled?
|
return if journaled?
|
||||||
@ -77,13 +83,13 @@ module Redmine
|
|||||||
|
|
||||||
(journal_hash[:except] ||= []) << self.primary_key << inheritance_column <<
|
(journal_hash[:except] ||= []) << self.primary_key << inheritance_column <<
|
||||||
:updated_on << :updated_at << :lock_version << :lft << :rgt
|
:updated_on << :updated_at << :lock_version << :lft << :rgt
|
||||||
|
|
||||||
prepare_journaled_options(journal_hash)
|
prepare_journaled_options(journal_hash)
|
||||||
has_many :journals, journal_hash.merge({:class_name => journal_class.name,
|
|
||||||
:foreign_key => "journaled_id"}), &block
|
has_many :journals, journal_hash, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
def journal_class
|
def journal_class
|
||||||
journal_class_name = "#{name.gsub("::", "_")}Journal"
|
|
||||||
if Object.const_defined?(journal_class_name)
|
if Object.const_defined?(journal_class_name)
|
||||||
Object.const_get(journal_class_name)
|
Object.const_get(journal_class_name)
|
||||||
else
|
else
|
||||||
|
@ -63,11 +63,12 @@ module Redmine::Acts::Journalized
|
|||||||
options.symbolize_keys!
|
options.symbolize_keys!
|
||||||
options.reverse_merge!(Configuration.options)
|
options.reverse_merge!(Configuration.options)
|
||||||
options.reverse_merge!(
|
options.reverse_merge!(
|
||||||
:class_name => 'Journal',
|
:class_name => journal_class_name,
|
||||||
:dependent => :delete_all
|
:dependent => :delete_all,
|
||||||
|
:foreign_key => "journaled_id"
|
||||||
)
|
)
|
||||||
options.reverse_merge!(
|
options.reverse_merge!(
|
||||||
:order => "#{options[:class_name].constantize.table_name}.version ASC"
|
:order => "#{journal_class.table_name}.version ASC"
|
||||||
)
|
)
|
||||||
|
|
||||||
class_inheritable_accessor :vestal_journals_options
|
class_inheritable_accessor :vestal_journals_options
|
||||||
|
Loading…
x
Reference in New Issue
Block a user