summaryrefslogtreecommitdiff
path: root/app/models/concerns
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-07-15 19:21:02 +0000
committerDouwe Maan <douwe@gitlab.com>2016-07-15 19:21:02 +0000
commit3b9e58953f5e846280d7f14a87a9816c24c1cc8d (patch)
tree78ccdc3e7343c8a3ef375f57ecdf27a2e3a32ce5 /app/models/concerns
parent263f005e905088dc7b84276f0a14be567fd158b0 (diff)
parentefe18f0507e08c7fd0f90a99e0c241c3c4ce107a (diff)
downloadgitlab-ce-3b9e58953f5e846280d7f14a87a9816c24c1cc8d.tar.gz
Merge branch 'fix-mentioned-users-on-diff-notes' into 'master'
Fix mentioned users on diff notes ## Summary `DiffNote`, and `LegacyDiffNote` returns empty array for `mentionable_attrs`, because `mentionable_attrs` is not inheritable by subclasses. The problem can be illustrated with this small sample: ```ruby module Mentionable extend ActiveSupport::Concern module ClassMethods def attr_mentionable(attr) mentionable_attrs << [attr.to_s] end def mentionable_attrs @mentionable_attrs ||= [] end end end class A include Mentionable attr_mentionable :foo end class B < A end A.mentionable_attrs => [["foo", {}]] B.mentionable_attrs => [] ``` Possible solution using `cattr_accessor`: ```ruby module Mentionable extend ActiveSupport::Concern module ClassMethods def attr_mentionable(attr) mentionable_attrs << [attr.to_s] end end included do cattr_accessor :mentionable_attrs, instance_accessor: false do [] end end end class A include Mentionable attr_mentionable :foo end class B < A end A.mentionable_attrs => [["foo"]] B.mentionable_attrs => [["foo"]] B.mentionable_attrs < [:bar] => [["foo"], ["bar"]] A.mentionable_attrs => [["foo"], ["bar"]] ``` `mentionable_attrs` is inheritable by subclasses. If a subclass changes the value then that would also change the value for parent class. Similarly if parent class changes the value then that would change the value of subclasses too. ## What are the relevant issue numbers? Fixes #19807 Fixes #18022 /cc @stanhu @DouweM @rspeicher See merge request !5243
Diffstat (limited to 'app/models/concerns')
-rw-r--r--app/models/concerns/mentionable.rb8
-rw-r--r--app/models/concerns/participable.rb7
2 files changed, 9 insertions, 6 deletions
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index 8cac47246db..ec9e0f1b1d0 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -14,14 +14,14 @@ module Mentionable
attr = attr.to_s
mentionable_attrs << [attr, options]
end
+ end
+ included do
# Accessor for attributes marked mentionable.
- def mentionable_attrs
- @mentionable_attrs ||= []
+ cattr_accessor :mentionable_attrs, instance_accessor: false do
+ []
end
- end
- included do
if self < Participable
participant -> (user, ext) { all_references(user, extractor: ext) }
end
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb
index 9822844357d..70740c76e43 100644
--- a/app/models/concerns/participable.rb
+++ b/app/models/concerns/participable.rb
@@ -41,9 +41,12 @@ module Participable
def participant(attr)
participant_attrs << attr
end
+ end
- def participant_attrs
- @participant_attrs ||= []
+ included do
+ # Accessor for participant attributes.
+ cattr_accessor :participant_attrs, instance_accessor: false do
+ []
end
end