fix callbacks in ruby 2.0

Change-Id: I49aa8b21eb6183a5b71b55e81e775bc0217d65f3
Reviewed-on: https://gerrit.instructure.com/26965
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2013-12-04 12:34:24 -07:00
parent 8476d923bc
commit f114b53cc5
1 changed files with 16 additions and 0 deletions

View File

@ -303,4 +303,20 @@ ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
alias_method_chain :construct_scope, :has_many_fix
end
# in ruby 2.0, respond_to? returns false for protected methods; Rails 2 doesn't know this,
# so replace this method with that knowledge
ActiveRecord::Callbacks.class_eval do
def callback(method)
result = run_callbacks(method) { |result, object| false == result }
if result != false && respond_to_without_attributes?(method, true)
result = send(method)
end
notify(method)
return result
end
end
end