summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb56
1 files changed, 28 insertions, 28 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 1578ae9c4cc..e8e3a106f1d 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -25,7 +25,7 @@ class Note < ActiveRecord::Base
class << self
def values
- constants.map {|const| self.const_get(const)}
+ constants.map {|const| const_get(const)}
end
end
end
@@ -66,7 +66,7 @@ class Note < ActiveRecord::Base
belongs_to :noteable, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
belongs_to :author, class_name: "User"
belongs_to :updated_by, class_name: "User"
- belongs_to :last_edited_by, class_name: 'User'
+ belongs_to :last_edited_by, class_name: "User"
has_many :todos
@@ -88,17 +88,17 @@ class Note < ActiveRecord::Base
validates :project, presence: true, if: :for_project_noteable?
# Attachments are deprecated and are handled by Markdown uploader
- validates :attachment, file_size: { maximum: :max_attachment_size }
+ validates :attachment, file_size: {maximum: :max_attachment_size}
validates :noteable_type, presence: true
validates :noteable_id, presence: true, unless: [:for_commit?, :importing?]
validates :commit_id, presence: true, if: :for_commit?
validates :author, presence: true
- validates :discussion_id, presence: true, format: { with: /\A\h{40}\z/ }
+ validates :discussion_id, presence: true, format: {with: /\A\h{40}\z/}
validate unless: [:for_commit?, :importing?, :skip_project_check?] do |note|
unless note.noteable.try(:project) == note.project
- errors.add(:project, 'does not match noteable project')
+ errors.add(:project, "does not match noteable project")
end
end
@@ -111,15 +111,15 @@ class Note < ActiveRecord::Base
scope :user, -> { where(system: false) }
scope :common, -> { where(noteable_type: ["", nil]) }
scope :fresh, -> { order(created_at: :asc, id: :asc) }
- scope :updated_after, ->(time) { where('updated_at > ?', time) }
+ scope :updated_after, ->(time) { where("updated_at > ?", time) }
scope :inc_author_project, -> { includes(:project, :author) }
scope :inc_author, -> { includes(:author) }
scope :inc_relations_for_view, -> do
- includes(:project, { author: :status }, :updated_by, :resolved_by, :award_emoji,
- :system_note_metadata, :note_diff_file, :suggestions)
+ includes(:project, {author: :status}, :updated_by, :resolved_by, :award_emoji,
+ :system_note_metadata, :note_diff_file, :suggestions)
end
- scope :with_notes_filter, -> (notes_filter) do
+ scope :with_notes_filter, ->(notes_filter) do
case notes_filter
when UserPreference::NOTES_FILTERS[:only_comments]
user
@@ -130,14 +130,14 @@ class Note < ActiveRecord::Base
end
end
- scope :diff_notes, -> { where(type: %w(LegacyDiffNote DiffNote)) }
- scope :new_diff_notes, -> { where(type: 'DiffNote') }
- scope :non_diff_notes, -> { where(type: ['Note', 'DiscussionNote', nil]) }
+ scope :diff_notes, -> { where(type: %w[LegacyDiffNote DiffNote]) }
+ scope :new_diff_notes, -> { where(type: "DiffNote") }
+ scope :non_diff_notes, -> { where(type: ["Note", "DiscussionNote", nil]) }
scope :with_associations, -> do
# FYI noteable cannot be loaded for LegacyDiffNote for commits
includes(:author, :noteable, :updated_by,
- project: [:project_members, :namespace, { group: [:group_members] }])
+ project: [:project_members, :namespace, {group: [:group_members]}])
end
scope :with_metadata, -> { includes(:system_note_metadata) }
@@ -151,7 +151,7 @@ class Note < ActiveRecord::Base
class << self
def model_name
- ActiveModel::Name.new(self, nil, 'note')
+ ActiveModel::Name.new(self, nil, "note")
end
def discussions(context_noteable = nil)
@@ -190,7 +190,7 @@ class Note < ActiveRecord::Base
end
def count_for_collection(ids, type)
- user.select('noteable_id', 'COUNT(*) as count')
+ user.select("noteable_id", "COUNT(*) as count")
.group(:noteable_id)
.where(noteable_type: type, noteable_id: ids)
end
@@ -290,7 +290,7 @@ class Note < ActiveRecord::Base
end
def special_role=(role)
- raise "Role is undefined, #{role} not found in #{SpecialRole.values}" unless SpecialRole.values.include?(role)
+ raise "Role is undefined, #{role} not found in #{SpecialRole.values}" unless SpecialRole.value?(role)
@special_role = role
end
@@ -300,7 +300,7 @@ class Note < ActiveRecord::Base
end
def specialize_for_first_contribution!(noteable)
- return unless noteable.author_id == self.author_id
+ return unless noteable.author_id == author_id
self.special_role = Note::SpecialRole::FIRST_TIME_CONTRIBUTOR
end
@@ -338,7 +338,7 @@ class Note < ActiveRecord::Base
end
def can_be_discussion_note?
- self.noteable.supports_discussions? && !part_of_discussion?
+ noteable.supports_discussions? && !part_of_discussion?
end
def can_create_todo?
@@ -374,7 +374,7 @@ class Note < ActiveRecord::Base
# Consider using `#to_discussion` if we do not need to render the discussion
# and all its notes and if we don't care about the discussion's resolvability status.
def discussion
- full_discussion = self.noteable.notes.find_discussion(self.discussion_id) if part_of_discussion?
+ full_discussion = noteable.notes.find_discussion(discussion_id) if part_of_discussion?
full_discussion || to_discussion
end
@@ -391,9 +391,9 @@ class Note < ActiveRecord::Base
in_reply_to?(other.noteable)
end
when Discussion
- self.discussion_id == other.id
+ discussion_id == other.id
when Noteable
- self.noteable == other
+ noteable == other
else
false
end
@@ -463,25 +463,25 @@ class Note < ActiveRecord::Base
private
def keep_around_commit
- project.repository.keep_around(self.commit_id)
+ project.repository.keep_around(commit_id)
end
def nullify_blank_type
- self.type = nil if self.type.blank?
+ self.type = nil if type.blank?
end
def nullify_blank_line_code
- self.line_code = nil if self.line_code.blank?
+ self.line_code = nil if line_code.blank?
end
def ensure_discussion_id
- return unless self.persisted?
+ return unless persisted?
# Needed in case the SELECT statement doesn't ask for `discussion_id`
- return unless self.has_attribute?(:discussion_id)
- return if self.discussion_id
+ return unless has_attribute?(:discussion_id)
+ return if discussion_id
set_discussion_id
- update_column(:discussion_id, self.discussion_id)
+ update_column(:discussion_id, discussion_id)
end
def set_discussion_id