diff options
Diffstat (limited to 'spec/models/concerns/noteable_spec.rb')
-rw-r--r-- | spec/models/concerns/noteable_spec.rb | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/spec/models/concerns/noteable_spec.rb b/spec/models/concerns/noteable_spec.rb index 383ed68816e..c1323d20d83 100644 --- a/spec/models/concerns/noteable_spec.rb +++ b/spec/models/concerns/noteable_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Noteable do +RSpec.describe Noteable, feature_category: :code_review_workflow do let!(:active_diff_note1) { create(:diff_note_on_merge_request) } let(:project) { active_diff_note1.project } subject { active_diff_note1.noteable } @@ -155,31 +155,38 @@ RSpec.describe Noteable do end describe '#discussion_root_note_ids' do - let!(:label_event) { create(:resource_label_event, merge_request: subject) } + let!(:label_event) do + create(:resource_label_event, merge_request: subject).tap do |event| + # Create an extra label event that should get grouped with the above event so this one should not + # be included in the resulting root nodes + create(:resource_label_event, merge_request: subject, user: event.user, created_at: event.created_at) + end + end + let!(:system_note) { create(:system_note, project: project, noteable: subject) } let!(:milestone_event) { create(:resource_milestone_event, merge_request: subject) } let!(:state_event) { create(:resource_state_event, merge_request: subject) } it 'returns ordered discussion_ids and synthetic note ids' do discussions = subject.discussion_root_note_ids(notes_filter: UserPreference::NOTES_FILTERS[:all_notes]).map do |n| - { table_name: n.table_name, discussion_id: n.discussion_id, id: n.id } + { table_name: n.table_name, id: n.id } end expect(discussions).to match( [ - a_hash_including(table_name: 'notes', discussion_id: active_diff_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: active_diff_note3.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: outdated_diff_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: discussion_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_diff_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_note2.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_discussion_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_discussion_note3.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: note2.discussion_id), + a_hash_including(table_name: 'notes', id: active_diff_note1.id), + a_hash_including(table_name: 'notes', id: active_diff_note3.id), + a_hash_including(table_name: 'notes', id: outdated_diff_note1.id), + a_hash_including(table_name: 'notes', id: discussion_note1.id), + a_hash_including(table_name: 'notes', id: commit_diff_note1.id), + a_hash_including(table_name: 'notes', id: commit_note1.id), + a_hash_including(table_name: 'notes', id: commit_note2.id), + a_hash_including(table_name: 'notes', id: commit_discussion_note1.id), + a_hash_including(table_name: 'notes', id: commit_discussion_note3.id), + a_hash_including(table_name: 'notes', id: note1.id), + a_hash_including(table_name: 'notes', id: note2.id), a_hash_including(table_name: 'resource_label_events', id: label_event.id), - a_hash_including(table_name: 'notes', discussion_id: system_note.discussion_id), + a_hash_including(table_name: 'notes', id: system_note.id), a_hash_including(table_name: 'resource_milestone_events', id: milestone_event.id), a_hash_including(table_name: 'resource_state_events', id: state_event.id) ]) @@ -187,34 +194,34 @@ RSpec.describe Noteable do it 'filters by comments only' do discussions = subject.discussion_root_note_ids(notes_filter: UserPreference::NOTES_FILTERS[:only_comments]).map do |n| - { table_name: n.table_name, discussion_id: n.discussion_id, id: n.id } + { table_name: n.table_name, id: n.id } end expect(discussions).to match( [ - a_hash_including(table_name: 'notes', discussion_id: active_diff_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: active_diff_note3.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: outdated_diff_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: discussion_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_diff_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_note2.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_discussion_note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: commit_discussion_note3.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: note1.discussion_id), - a_hash_including(table_name: 'notes', discussion_id: note2.discussion_id) + a_hash_including(table_name: 'notes', id: active_diff_note1.id), + a_hash_including(table_name: 'notes', id: active_diff_note3.id), + a_hash_including(table_name: 'notes', id: outdated_diff_note1.id), + a_hash_including(table_name: 'notes', id: discussion_note1.id), + a_hash_including(table_name: 'notes', id: commit_diff_note1.id), + a_hash_including(table_name: 'notes', id: commit_note1.id), + a_hash_including(table_name: 'notes', id: commit_note2.id), + a_hash_including(table_name: 'notes', id: commit_discussion_note1.id), + a_hash_including(table_name: 'notes', id: commit_discussion_note3.id), + a_hash_including(table_name: 'notes', id: note1.id), + a_hash_including(table_name: 'notes', id: note2.id) ]) end it 'filters by system notes only' do discussions = subject.discussion_root_note_ids(notes_filter: UserPreference::NOTES_FILTERS[:only_activity]).map do |n| - { table_name: n.table_name, discussion_id: n.discussion_id, id: n.id } + { table_name: n.table_name, id: n.id } end expect(discussions).to match( [ a_hash_including(table_name: 'resource_label_events', id: label_event.id), - a_hash_including(table_name: 'notes', discussion_id: system_note.discussion_id), + a_hash_including(table_name: 'notes', id: system_note.id), a_hash_including(table_name: 'resource_milestone_events', id: milestone_event.id), a_hash_including(table_name: 'resource_state_events', id: state_event.id) ]) |