Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6093 from marcandre/observer_public

notify_observers should be public
  • Loading branch information...
commit cb5b0cf93ff45c3f08ac6b6ce524846419275067 2 parents 206b43a + dc74f0c
@jeremy jeremy authored
View
37 activemodel/lib/active_model/observing.rb
@@ -110,25 +110,24 @@ def inherited(subclass)
end
end
- private
- # Fires notifications to model's observers
- #
- # def save
- # notify_observers(:before_save)
- # ...
- # notify_observers(:after_save)
- # end
- #
- # Custom notifications can be sent in a similar fashion:
- #
- # notify_observers(:custom_notification, :foo)
- #
- # This will call +custom_notification+, passing as arguments
- # the current object and :foo.
- #
- def notify_observers(method, *extra_args)
- self.class.notify_observers(method, self, *extra_args)
- end
+ # Fires notifications to model's observers
+ #
+ # def save
+ # notify_observers(:before_save)
+ # ...
+ # notify_observers(:after_save)
+ # end
+ #
+ # Custom notifications can be sent in a similar fashion:
+ #
+ # notify_observers(:custom_notification, :foo)
+ #
+ # This will call +custom_notification+, passing as arguments
+ # the current object and :foo.
+ #
+ def notify_observers(method, *extra_args)
+ self.class.notify_observers(method, self, *extra_args)
+ end
end
# == Active Model Observers
View
11 activemodel/test/cases/observing_test.rb
@@ -138,7 +138,14 @@ def teardown
foo = Foo.new
FooObserver.instance.stub = stub
FooObserver.instance.stub.expects(:event_with).with(foo)
- Foo.send(:notify_observers, :on_spec, foo)
+ Foo.notify_observers(:on_spec, foo)
+ end
+
+ test "calls existing observer event from the instance" do
+ foo = Foo.new
+ FooObserver.instance.stub = stub
+ FooObserver.instance.stub.expects(:event_with).with(foo)
+ foo.notify_observers(:on_spec)
end
test "passes extra arguments" do
@@ -150,7 +157,7 @@ def teardown
test "skips nonexistent observer event" do
foo = Foo.new
- Foo.send(:notify_observers, :whatever, foo)
+ Foo.notify_observers(:whatever, foo)
end
test "update passes a block on to the observer" do
Please sign in to comment.
Something went wrong with that request. Please try again.