Fix aaj to allow setting the journal user, note, and attributes directly.

This will allow the Journaled object to reliability set the fields on the Journal
without calling init_journal (which is a before_save hook and shouldn't be called
directly).
This commit is contained in:
Eric Davis 2011-07-11 16:55:28 -07:00
parent 067ab21309
commit 3b9980b449
3 changed files with 16 additions and 2 deletions

View File

@ -101,4 +101,17 @@ class JournalTest < ActiveSupport::TestCase
assert_equal nil, journal.journaled
end
end
test "setting journal fields through the journaled object for creation" do
@issue = Issue.generate_for_project!(Project.generate!)
@issue.journal_user = @issue.author
@issue.journal_notes = 'Test setting fields on Journal from Issue'
assert_difference('Journal.count') do
assert @issue.save
end
assert_equal "Test setting fields on Journal from Issue", @issue.last_journal.notes
assert_equal @issue.author, @issue.last_journal.user
end
end

View File

@ -120,7 +120,8 @@ module Redmine::Acts::Journalized
def journal_attributes
attributes = { :journaled_id => self.id, :activity_type => activity_type,
:changes => journal_changes, :version => last_version + 1,
:notes => journal_notes, :user_id => (journal_user.try(:id) || User.current.try(:id)) }
:notes => journal_notes, :user_id => (journal_user.try(:id) || User.current.try(:id))
}.merge(extra_journal_attributes || {})
end
end
end

View File

@ -28,7 +28,7 @@ module Redmine::Acts::Journalized
before_save :init_journal
after_save :reset_instance_variables
attr_reader :journal_notes, :journal_user
attr_accessor :journal_notes, :journal_user, :extra_journal_attributes
end
end