• Douwe Maan's avatar
    Merge branch 'fix-mentioned-users-on-diff-notes' into 'master' · 3b9e5895
    Douwe Maan authored
    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
    3b9e5895
To find the state of this project's repository at the time of any of these versions, check out the tags.
CHANGELOG 168 KB