Module: ShouldaExt::Matchers::TriggerCallbackMatcher::ActiveRecordHooks
- Defined in:
- lib/shoulda_ext/matchers/trigger_callback.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.attach_to(model) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/shoulda_ext/matchers/trigger_callback.rb', line 38 def self.attach_to(model) puts "Attaching trigger_callback test hooks in #{model.name}" class << model attr_accessor :callback_tester_attrs end model.class_eval do @callback_tester_attrs = [] CALLBACK_EVENTS.each do |ce| CALLBACK_TYPES.each do |ct| callback_name = :"#{ce}_#{ct}" callback_attr = :"called_#{callback_name}" callback_method, has_on_option = (ce.to_s =~ /_on/ ? [ce.to_s.gsub('_on',''), true] : [callback_name, false]) @callback_tester_attrs << callback_attr attr_accessor callback_attr send( callback_method, (has_on_option ? {:on => ct} : {})) { instance_variable_set(:"@#{callback_attr}", true) } define_method :"#{callback_attr}?" do !!instance_variable_get(:"@#{callback_attr}") end end # - each end # - each end # - class_eval end |
.included(base) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/shoulda_ext/matchers/trigger_callback.rb', line 28 def self.included(base) class << base def inherited_with_hooks(subclass) inherited_without_hooks(subclass) ActiveRecordHooks.attach_to subclass end alias_method_chain :inherited, :hooks end end |
Instance Method Details
#reset_callback_flags! ⇒ Object
64 65 66 67 68 |
# File 'lib/shoulda_ext/matchers/trigger_callback.rb', line 64 def reset_callback_flags! self.class.callback_tester_attrs.each do |attr| send("#{attr}=", false) end end |