Commit c57cddf5 authored by blackst0ne's avatar 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.
parent 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%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment