Make `resolvable_types` a class method

This turns Notable::RESOLVABLE_TYPES into a
`Notable.resolvable_types`. That allows us to override it in EE.
This commit is contained in:
Bob Van Landuyt 2019-06-03 16:41:05 +02:00
parent 2ad5b30b6c
commit 4504959aa6
5 changed files with 25 additions and 7 deletions

View File

@ -3,14 +3,16 @@
module Noteable
extend ActiveSupport::Concern
# `Noteable` class names that support resolvable notes.
RESOLVABLE_TYPES = %w(MergeRequest).freeze
class_methods do
# `Noteable` class names that support replying to individual notes.
def replyable_types
%w(Issue MergeRequest)
end
# `Noteable` class names that support resolvable notes.
def resolvable_types
%w(MergeRequest)
end
end
# The timestamp of the note (e.g. the :created_at or :updated_at attribute if provided via
@ -36,7 +38,7 @@ module Noteable
end
def supports_resolvable_notes?
RESOLVABLE_TYPES.include?(base_class_name)
self.class.resolvable_types.include?(base_class_name)
end
def supports_discussions?
@ -131,3 +133,5 @@ module Noteable
)
end
end
Noteable.extend(Noteable::ClassMethods)

View File

@ -12,7 +12,7 @@ module ResolvableNote
validates :resolved_by, presence: true, if: :resolved?
# Keep this scope in sync with `#potentially_resolvable?`
scope :potentially_resolvable, -> { where(type: RESOLVABLE_TYPES).where(noteable_type: Noteable::RESOLVABLE_TYPES) }
scope :potentially_resolvable, -> { where(type: RESOLVABLE_TYPES).where(noteable_type: Noteable.resolvable_types) }
# Keep this scope in sync with `#resolvable?`
scope :resolvable, -> { potentially_resolvable.user }

View File

@ -15,7 +15,9 @@ class DiffNote < Note
validates :original_position, presence: true
validates :position, presence: true
validates :line_code, presence: true, line_code: true, if: :on_text?
validates :noteable_type, inclusion: { in: noteable_types }
# We need to evaluate the `noteable` types when running the validation since
# EE might have added a type when the module was prepended
validates :noteable_type, inclusion: { in: -> (_note) { noteable_types } }
validate :positions_complete
validate :verify_supported
validate :diff_refs_match_commit, if: :for_commit?

View File

@ -206,7 +206,7 @@ module API
delete_note(noteable, params[:note_id])
end
if Noteable::RESOLVABLE_TYPES.include?(noteable_type.to_s)
if Noteable.resolvable_types.include?(noteable_type.to_s)
desc "Resolve/unresolve an existing #{noteable_type.to_s.downcase} discussion" do
success Entities::Discussion
end

View File

@ -260,4 +260,16 @@ describe Noteable do
end
end
end
describe '.replyable_types' do
it 'exposes the replyable types' do
expect(described_class.replyable_types).to include('Issue', 'MergeRequest')
end
end
describe '.resolvable_types' do
it 'exposes the replyable types' do
expect(described_class.resolvable_types).to include('MergeRequest')
end
end
end