enforce disabled aggregations

due to limited time resolution we can't assume that a setting of 0 will implicitly disable aggregation
pull/3301/head
Jan Sandbrink 9 years ago
parent 443c42c788
commit 3fe8b33f78
  1. 5
      app/models/journal/aggregated_journal.rb
  2. 23
      spec/models/journal/aggregated_journal_spec.rb

@ -223,6 +223,11 @@ class Journal::AggregatedJournal
# proximity into account.
def sql_beyond_aggregation_time?(predecessor, successor)
aggregation_time_seconds = Setting.journal_aggregation_time_minutes.to_i.minutes
if aggregation_time_seconds == 0
# if aggregation is disabled, we consider everything to be beyond aggregation time
# even if creation dates are exactly equal
return '(true = true)'
end
if OpenProject::Database.mysql?
difference = "TIMESTAMPDIFF(second, #{predecessor}.created_at, #{successor}.created_at)"

@ -244,6 +244,29 @@ describe Journal::AggregatedJournal, type: :model do
end
end
context 'aggregation is disabled' do
before do
allow(Setting).to receive(:journal_aggregation_time_minutes).and_return(0)
end
context 'WP updated within milliseconds' do
let(:delay) { 0.001.seconds }
before do
work_package.status = FactoryGirl.build(:status)
work_package.save!
work_package.journals.second.created_at = work_package.journals.first.created_at + delay
work_package.journals.second.save!
end
it 'returns both journals' do
expect(subject.count).to eql 2
expect(subject.first).to be_equivalent_to_journal work_package.journals.first
expect(subject.second).to be_equivalent_to_journal work_package.journals.second
end
end
end
context 'different WP updated immediately after change' do
let(:other_wp) { FactoryGirl.build(:work_package) }
before do

Loading…
Cancel
Save