ranked-model
ranked-model copied to clipboard
Rails 5 depreciation warning for `attribute_changed?` method
https://github.com/mixonic/ranked-model/blob/ef7690276723e40b87c1337cb4e86a3db0eb1902/lib/ranked-model/ranker.rb#L105-L107
If a method called in a after_*
callback changes the rank, then you will get a deprecation warning:
DEPRECATION WARNING: The behavior of
attribute_changed?
inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method aftersave
returned (e.g. the opposite of what it returns now). To maintain the current behavior, usesaved_change_to_attribute?
instead.
Maybe check if a newer rails version is in use using #respond_to?
?
def rank_changed?
return instance.send "saved_change_to_#{ranker.column}?" if instance.respond_to?("saved_change_to_#{ranker.column}?".to_sym)
instance.send "#{ranker.column}_changed?"
end
@jwilsjustin, could you check if the latest version of the gem still has this problem? :)
@brendon It reproduces on 0.4.4 (https://github.com/mixonic/ranked-model/blob/master/lib/ranked-model/ranker.rb#L114)
Just looking quickly, the only place this is called is in:
before_save :handle_ranking
Would you mind generating a failing test case showing the problem as I don't think we use after_
callbacks in this gem.
It could be related to a cascading change where your model in particular is calling save again in an after_
callback, thus the before
callback is nested in an after
callback. Not sure what we can do about that though.
I'll look more. I can't find who's generating some deprecations and after commenting our ranked model they didn't show up. Didn't spent too much time on it.
Thanks @razvan-sv, I suspect it'll be as a described above.
Any plan to fix this in an upcoming release?
So far no one has created a PR with a failing test case showing that the issue lies within ranked-model
. I'd be happy to look at a fix if someone does this. Or if they want to go further and do a complete PR with a test and fix that would be even better! :D