提交 c57cddf5 编写于 作者: B blackst0ne

[Rails5] Update Event#subclass_from_attributes method

In Rails 5.0 the `ActiveRecord::Inheritance::subclass_from_attributes`
method was updated.
Now it calls the `find_sti_class` method [1] which is overriden in the `Event`
model and returns needed class (`Event` vs `PushEvent`).

[1]: https://github.com/rails/rails/blob/5-0-stable/activerecord/lib/active_record/inheritance.rb#L209

This commit fixes the errors like
```
143) User#contributed_projects doesn't include IDs for unrelated projects
      Failure/Error: action = attrs.with_indifferent_access[inheritance_column].to_i

      NoMethodError:
        undefined method `with_indifferent_access' for nil:NilClass
      # ./app/models/event.rb:118:in `subclass_from_attributes'
```
which are raised on the `RAILS5=1 rspec ...` command.
上级 fc7d76ae
......@@ -110,7 +110,10 @@ class Event < ActiveRecord::Base
end
end
# Remove this method when removing Gitlab.rails5? code.
def subclass_from_attributes(attrs)
return super if Gitlab.rails5?
# Without this Rails will keep calling this method on the returned class,
# resulting in an infinite loop.
return unless self == Event
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册