Merge branch 'fix/wp_journal_not_added' into release/3.0

pull/1244/head
Markus Kahl 11 years ago
commit a9fd52fd71
  1. 5
      app/models/journal_manager.rb
  2. 2
      doc/CHANGELOG.md
  3. 81
      lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/save_hooks.rb
  4. 18
      spec/models/work_package/work_package_acts_as_journalized_spec.rb
  5. 3
      test/functional/wiki_controller_test.rb

@ -128,9 +128,12 @@ class JournalManager
def self.add_journal(journable, user = User.current, notes = "")
if is_journalized? journable
# Maximum version might be nil, so use to_i here.
version = journable.journals.maximum(:version).to_i + 1
journal_attributes = { journable_id: journable.id,
journable_type: journal_class_name(journable.class),
version: (journable.journals.count + 1),
version: version,
activity_type: journable.send(:activity_type),
changed_data: journable.attributes.symbolize_keys }

@ -29,6 +29,8 @@ See doc/COPYRIGHT.rdoc for more details.
# Changelog
* `#7177` Fix: Journal not created in connection with deleted note
## 3.0.1
* `#5265` Fix: Error adding Work Package

@ -55,7 +55,7 @@ module Redmine::Acts::Journalized
base.class_eval do
after_save :save_journals
attr_accessor :journal_notes, :journal_user, :extra_journal_attributes
end
end
@ -68,7 +68,7 @@ module Redmine::Acts::Journalized
JournalManager.add_journal self, @journal_user, @journal_notes if add_journal
journals.select{|j| j.new_record?}.each {|j| j.save}
journals.select { |j| j.new_record? }.each { |j| j.save! }
@journal_user = nil
@journal_notes = nil
@ -79,83 +79,6 @@ module Redmine::Acts::Journalized
@journal_notes ||= notes
end
## Saves the current custom values, notes and journal to include them in the next journal
## Called before save
#def init_journal(user = User.current, notes = "")
# @journal_notes ||= notes
# @journal_user ||= user
# @associations_before_save ||= {}
# @associations = {}
# save_possible_association :custom_values, :key => :custom_field_id, :value => :value
# save_possible_association :attachments, :key => :id, :value => :filename
# @current_journal ||= last_journal
#end
## Saves the notes and custom value changes in the last Journal
## Called before create_journal
#def update_journal
# unless (@associations || {}).empty?
# changed_associations = {}
# changed_associations.merge!(possibly_updated_association :custom_values)
# changed_associations.merge!(possibly_updated_association :attachments)
# end
# unless changed_associations.blank?
# update_extended_journal_contents(changed_associations)
# end
#end
#def reset_instance_variables
# if last_journal != @current_journal
# if last_journal.user != @journal_user
# last_journal.update_attribute(:user_id, @journal_user.id)
# end
# end
# @associations_before_save = @current_journal = @journal_notes = @journal_user = @extra_journal_attributes = nil
#end
#def save_possible_association(method, options)
# @associations[method] = options
# if self.respond_to? method
# @associations_before_save[method] ||= send(method).inject({}) do |hash, cv|
# hash[cv.send(options[:key])] = cv.send(options[:value])
# hash
# end
# end
#end
#def possibly_updated_association(method)
# if @associations_before_save[method]
# # Has custom values from init_journal_notes
# return changed_associations(method, @associations_before_save[method])
# end
# {}
#end
## Saves the notes and changed custom values to the journal
## Creates a new journal, if no immediate attributes were changed
#def update_extended_journal_contents(changed_associations)
# journal_changes.merge!(changed_associations)
#end
#def changed_associations(method, previous)
# send(method).reload # Make sure the associations are reloaded
# send(method).inject({}) do |hash, c|
# key = c.send(@associations[method][:key])
# new_value = c.send(@associations[method][:value])
# if previous[key].blank? && new_value.blank?
# # The key was empty before, don't add a blank value
# elsif previous[key] != new_value
# # The key's value changed
# hash["#{method}#{key}"] = [previous[key], new_value]
# end
# hash
# end
#end
module ClassMethods
end
end

@ -191,6 +191,24 @@ describe WorkPackage do
end
end
end
describe "adding journal with a missing journal and an existing journal" do
before do
work_package.update_by!(current_user, notes: 'note to be deleted')
work_package.reload
work_package.update_by!(current_user, description: 'description v2')
work_package.reload
work_package.journals.find_by_notes('note to be deleted').delete
work_package.update_by!(current_user, description: 'description v4')
end
it 'should create a journal for the last change' do
last_journal = work_package.journals.order(:id).last
expect(last_journal.data.description).to eql('description v4')
end
end
end
context "attachments" do

@ -180,6 +180,7 @@ class WikiControllerTest < ActionController::TestCase
def test_update_stale_page_should_not_raise_an_error
journal = FactoryGirl.create :wiki_content_journal,
journable_id: 2,
version: 1,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. Another page\n\n\nthis is a link to ticket: #2")
@request.session[:user_id] = 2
@ -214,7 +215,7 @@ class WikiControllerTest < ActionController::TestCase
c.reload
assert_equal 'Previous text', c.text
assert_equal journal.version, c.version
assert_equal 2, c.version
end
def test_preview

Loading…
Cancel
Save