Permalink
Browse files

Allow full instances to be fired on rather than just references

  • Loading branch information...
1 parent 0fb2989 commit 5c1162e6e4e7fe6c21485093df55189da363ec64 @holman committed Mar 3, 2010
Showing with 7 additions and 2 deletions.
  1. +1 −1 README.rdoc
  2. +1 −1 generators/timeline_fu/templates/model.rb
  3. +5 −0 test/fires_test.rb
View
@@ -28,7 +28,7 @@ as you want.
They are hooked for you after standard ActiveRecord events. In
the previous example, it's an after_create on Posts.
-If you want to manually trigger an event outside of normal callbacks, take a look at <tt>TimelineEvent.fire</tt>. It has a syntax similar to the <tt>fires</tt> event on models:
+If you want to manually trigger an event outside of normal callbacks, take a look at <tt>TimelineEvent.fire</tt>. It has a syntax similar to the <tt>fires</tt> event on models. For your options hash, you may pass symbol references (<tt>{:actor => :user}</tt>) or full instances:
TimelineEvent.fire(@user_notice, 'new_notice', {:actor => @user})
@@ -11,7 +11,7 @@ def self.fire(instance, event_type, opts={})
when :self
memo[sym] = instance
else
- memo[sym] = instance.send(opts[sym]) if opts[sym]
+ memo[sym] = (opts[sym].kind_of?(Symbol) ? instance.send(opts[sym]) : opts[sym]) if opts[sym]
end
memo
end
View
@@ -37,6 +37,11 @@ def test_should_manually_fire_and_assign_object_associations
TimelineEvent.expects(:create!).with(:event_type => 'test_event', :subject => @list, :actor => @james)
TimelineEvent.fire(@list, 'test_event', {:actor => :author})
end
+
+ def test_should_manually_fire_using_full_instances
+ TimelineEvent.expects(:create!).with(:event_type => 'test_event', :subject => @james, :actor => @mat)
+ TimelineEvent.fire(@james, 'test_event', {:actor => @mat})
+ end
def test_exception_raised_if_on_missing
# This needs to be tested with should_raise, to check out the msg content

0 comments on commit 5c1162e

Please sign in to comment.