diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-03-17 13:25:52 -0600 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-04-05 17:44:14 +0100 |
commit | 79889a6aa3dc878d196d0f2f445ab6b10ef10c74 (patch) | |
tree | 25367a69b4a529335e106d0d65c2d9a38e97f092 /app/models/note.rb | |
parent | 80b2e18fb62b8da7410f90b3e5340b9e63e765a3 (diff) | |
download | gitlab-ce-79889a6aa3dc878d196d0f2f445ab6b10ef10c74.tar.gz |
Add specs
Diffstat (limited to 'app/models/note.rb')
-rw-r--r-- | app/models/note.rb | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index 06ceb60b982..00a58afd2b6 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -56,7 +56,7 @@ class Note < ActiveRecord::Base validate unless: [:for_commit?, :importing?, :for_personal_snippet?] do |note| unless note.noteable.try(:project) == note.project - errors.add(:invalid_project, 'Note and noteable project mismatch') + errors.add(:project, 'does not match noteable project') end end @@ -236,14 +236,14 @@ class Note < ActiveRecord::Base end def can_be_discussion_note? - DiscussionNote::NOTEABLE_TYPES.include?(self.noteable_type) + DiscussionNote::NOTEABLE_TYPES.include?(self.noteable_type) && !part_of_discussion? end def discussion_class(noteable = nil) # When commit notes are rendered on an MR's Discussion page, they are # displayed in one discussion instead of individually - if noteable && noteable != self.noteable && for_commit? - CommitDiscussion + if noteable && noteable != self.noteable + OutOfContextDiscussion else IndividualNoteDiscussion end @@ -268,7 +268,24 @@ class Note < ActiveRecord::Base end def part_of_discussion? - !to_discussion.render_as_individual_notes? + !to_discussion.individual_note? + end + + def in_reply_to?(other) + case other + when Note + if part_of_discussion? + in_reply_to?(other.noteable) && in_reply_to?(other.to_discussion) + else + in_reply_to?(other.noteable) + end + when Discussion + self.discussion_id == other.id + when Noteable + self.noteable == other + else + false + end end private |