display diff of containing aggregated journal

... instead of displaying the diff for the requested journal only

- this should provide the best forward compatibility of links
- even when aggregation timeframes are changed intermittently
pull/3301/head
Jan Sandbrink 9 years ago
parent a8e1aadec7
commit f9051bba3e
  1. 8
      app/controllers/journals_controller.rb
  2. 6
      app/models/journal/aggregated_journal.rb
  3. 21
      spec/models/journal/aggregated_journal_spec.rb

@ -88,13 +88,15 @@ class JournalsController < ApplicationController
end
def diff
journal = Journal::AggregatedJournal.for_journal(@journal)
if valid_diff?
field = params[:field].parameterize.underscore.to_sym
from = @journal.details[field][0]
to = @journal.details[field][1]
from = journal.details[field][0]
to = journal.details[field][1]
@diff = Redmine::Helpers::Diff.new(to, from)
@journable = @journal.journable
@journable = journal.journable
respond_to do |format|
format.html {}
format.js { render partial: 'diff', locals: { diff: @diff } }

@ -41,6 +41,12 @@
# be dropped
class Journal::AggregatedJournal
class << self
# Returns the aggregated journal that contains the specified (vanilla) journal.
def for_journal(vanilla_journal)
Journal::AggregatedJournal.aggregated_journals(journable: vanilla_journal.journable)
.detect { |journal| journal.version >= vanilla_journal.version }
end
def with_notes_id(notes_id)
raw_journal = query_aggregated_journals
.where("#{table_name}.id = ?", notes_id)

@ -120,6 +120,14 @@ describe Journal::AggregatedJournal, type: :model do
expect(subject.first.successor).to be_nil
end
it 'returns the single journal for both original journals' do
expect(described_class.for_journal work_package.journals.first)
.to be_equivalent_to_journal subject.first
expect(described_class.for_journal work_package.journals.second)
.to be_equivalent_to_journal subject.first
end
context 'with a comment' do
let(:notes) { 'This is why I changed it.' }
@ -153,6 +161,19 @@ describe Journal::AggregatedJournal, type: :model do
it 'has the second as successor of the first journal' do
expect(subject.first.successor).to be_equivalent_to_journal subject.second
end
it 'returns the same aggregated journal for the first two originals' do
expect(described_class.for_journal work_package.journals.first)
.to be_equivalent_to_journal subject.first
expect(described_class.for_journal work_package.journals.second)
.to be_equivalent_to_journal subject.first
end
it 'returns a different aggregated journal for the last original' do
expect(described_class.for_journal work_package.journals.last)
.to be_equivalent_to_journal subject.second
end
end
context 'adding another change without comment' do

Loading…
Cancel
Save