Skip to content

Commit

Permalink
rails 4.2: fix attachment_fu callbacks
Browse files Browse the repository at this point in the history
refs #CNVS-26056

Change-Id: I6048e9c9e0d3eaf897c4082f7d936fe2b687c66c
Reviewed-on: https://gerrit.instructure.com/69499
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <[email protected]>
Product-Review: James Williams  <[email protected]>
QA-Review: James Williams  <[email protected]>
  • Loading branch information
maneframe committed Dec 30, 2015
1 parent 06a5413 commit c400e13
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions gems/attachment_fu/lib/attachment_fu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ def after_process_attachment
callback :after_save_and_attachment_processing
end

if connection.open_transactions == 1
connection.after_transaction_commit(&save_and_callbacks)
if self.class.connection.open_transactions == 1
self.class.connection.after_transaction_commit(&save_and_callbacks)
else
save_and_callbacks.call()
end
Expand All @@ -583,13 +583,23 @@ def callback(method)
chain = ActiveSupport::Callbacks::CallbackChain.new(method, {})

kind, chain_name = method.to_s.split('_', 2) # e.g. :after_save becomes 'after', 'save'
chain.concat(self.send("_#{chain_name}_callbacks").to_a.select{|callback| callback.kind.to_s == kind})

str = chain.compile
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{runner_method}() #{str} end
protected :#{runner_method}
RUBY_EVAL
chain.append(*(self.send("_#{chain_name}_callbacks").to_a.select{|callback| callback.kind.to_s == kind}))

if CANVAS_RAILS4_0
str = chain.compile
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{runner_method}()
#{str}
end
protected :#{runner_method}
RUBY_EVAL
else
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{runner_method}(&block)
__run_callbacks__(_#{chain_name}_callbacks, &block)
end
RUBY
end
end
self.send(runner_method)
end
Expand Down

0 comments on commit c400e13

Please sign in to comment.