Merge pull request #8510 from opf/fix/33744/duplicated-journals-aggregation

Use distinct(*) on aggregated journal to avoid duplicate raw journals

[ci skip]
pull/8515/head
Oliver Günther 4 years ago committed by GitHub
commit e8c316a09e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/journal/aggregated_journal.rb
  2. 1
      app/models/journal/scopes/aggregated_journal.rb
  3. 28
      spec/features/work_packages/details/markdown/activity_comments_spec.rb

@ -63,7 +63,9 @@ class Journal::AggregatedJournal
# The +until_version+ parameter can be used in conjunction with the +journable+ parameter # The +until_version+ parameter can be used in conjunction with the +journable+ parameter
# to see the aggregated journals as if no versions were known after the specified version. # to see the aggregated journals as if no versions were known after the specified version.
def aggregated_journals(journable: nil, sql: nil, until_version: nil, includes: []) def aggregated_journals(journable: nil, sql: nil, until_version: nil, includes: [])
raw_journals = Journal::Scopes::AggregatedJournal.fetch(journable: journable, sql: sql, until_version: until_version) raw_journals = Journal::Scopes::AggregatedJournal
.fetch(journable: journable, sql: sql, until_version: until_version)
.order('version ASC')
aggregated_journals = map_to_aggregated_journals(raw_journals) aggregated_journals = map_to_aggregated_journals(raw_journals)
preload_associations(journable, aggregated_journals, includes) preload_associations(journable, aggregated_journals, includes)

@ -41,6 +41,7 @@ module Journal::Scopes
# having to also use a CASE/COALESCE statement. # having to also use a CASE/COALESCE statement.
Journal Journal
.from(select_sql(journals_preselection)) .from(select_sql(journals_preselection))
.select("DISTINCT *")
end end
private private

@ -68,6 +68,34 @@ describe 'activity comments', js: true, with_mail: false do
expect(page).to have_selector('.user-comment > .message', count: 3) expect(page).to have_selector('.user-comment > .message', count: 3)
wp_page.expect_comment text: 'this is my second comment!1' wp_page.expect_comment text: 'this is my second comment!1'
expect(comment_field.editing?).to be false
comment_field.activate!
expect(comment_field.editing?).to be true
comment_field.click_and_type_slowly 'this is my third comment!1'
comment_field.submit_by_click
# Only shows three most recent
expect(page).to have_selector('.user-comment > .message', count: 3)
wp_page.expect_comment text: 'this is my third comment!1'
wp_page.switch_to_tab tab: 'Activity'
# Now showing all comments
expect(page).to have_selector('.user-comment > .message', count: 4, wait: 10)
expect(comment_field.editing?).to be false
comment_field.activate!
expect(comment_field.editing?).to be true
comment_field.click_and_type_slowly 'this is my fifth comment!1'
comment_field.submit_by_click
expect(page).to have_selector('.user-comment > .message', count: 4)
wp_page.expect_comment text: 'this is my fifth comment!1'
# Expect no activity details
expect(page).to have_no_selector('.work-package-details-activities-messages li')
end end
end end

Loading…
Cancel
Save