aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-04-28 19:17:03 +0200
committerJosé Valim <jose.valim@gmail.com>2011-04-28 19:17:03 +0200
commite59491355e921c2275980fba5a85dfc8b5ed25f7 (patch)
tree1635eaad8129b50e41cd903718cb1b51be0c5457 /activemodel/test
parentfc343d26ffec073c7df64a8a4c2508104f78e9d4 (diff)
parent7db7aa505375db75c2205f35df743becc7647c95 (diff)
downloadrails-e59491355e921c2275980fba5a85dfc8b5ed25f7.tar.gz
rails-e59491355e921c2275980fba5a85dfc8b5ed25f7.tar.bz2
rails-e59491355e921c2275980fba5a85dfc8b5ed25f7.zip
Merge remote branch 'myron/am_disabling_fix_memory_leaks'
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/observer_array_test.rb100
1 files changed, 99 insertions, 1 deletions
diff --git a/activemodel/test/cases/observer_array_test.rb b/activemodel/test/cases/observer_array_test.rb
index 215ca80bb4..fc5f18008b 100644
--- a/activemodel/test/cases/observer_array_test.rb
+++ b/activemodel/test/cases/observer_array_test.rb
@@ -38,6 +38,16 @@ class ObserverArrayTest < ActiveModel::TestCase
assert_observer_notified Budget, AuditTrail
end
+ test "can enable individual observers using a class constant" do
+ ORM.observers.disable :all
+ ORM.observers.enable AuditTrail
+
+ assert_observer_not_notified Widget, WidgetObserver
+ assert_observer_not_notified Budget, BudgetObserver
+ assert_observer_notified Widget, AuditTrail
+ assert_observer_notified Budget, AuditTrail
+ end
+
test "can disable individual observers using a symbol" do
ORM.observers.disable :budget_observer
@@ -47,6 +57,35 @@ class ObserverArrayTest < ActiveModel::TestCase
assert_observer_notified Budget, AuditTrail
end
+ test "can enable individual observers using a symbol" do
+ ORM.observers.disable :all
+ ORM.observers.enable :audit_trail
+
+ assert_observer_not_notified Widget, WidgetObserver
+ assert_observer_not_notified Budget, BudgetObserver
+ assert_observer_notified Widget, AuditTrail
+ assert_observer_notified Budget, AuditTrail
+ end
+
+ test "can disable multiple observers at a time" do
+ ORM.observers.disable :widget_observer, :budget_observer
+
+ assert_observer_not_notified Widget, WidgetObserver
+ assert_observer_not_notified Budget, BudgetObserver
+ assert_observer_notified Widget, AuditTrail
+ assert_observer_notified Budget, AuditTrail
+ end
+
+ test "can enable multiple observers at a time" do
+ ORM.observers.disable :all
+ ORM.observers.enable :widget_observer, :budget_observer
+
+ assert_observer_notified Widget, WidgetObserver
+ assert_observer_notified Budget, BudgetObserver
+ assert_observer_not_notified Widget, AuditTrail
+ assert_observer_not_notified Budget, AuditTrail
+ end
+
test "can disable all observers using :all" do
ORM.observers.disable :all
@@ -56,7 +95,17 @@ class ObserverArrayTest < ActiveModel::TestCase
assert_observer_not_notified Budget, AuditTrail
end
- test "can disable observers on individual models without affecting observers on other models" do
+ test "can enable all observers using :all" do
+ ORM.observers.disable :all
+ ORM.observers.enable :all
+
+ assert_observer_notified Widget, WidgetObserver
+ assert_observer_notified Budget, BudgetObserver
+ assert_observer_notified Widget, AuditTrail
+ assert_observer_notified Budget, AuditTrail
+ end
+
+ test "can disable observers on individual models without affecting those observers on other models" do
Widget.observers.disable :all
assert_observer_not_notified Widget, WidgetObserver
@@ -65,6 +114,16 @@ class ObserverArrayTest < ActiveModel::TestCase
assert_observer_notified Budget, AuditTrail
end
+ test "can enable observers on individual models without affecting those observers on other models" do
+ ORM.observers.disable :all
+ Budget.observers.enable AuditTrail
+
+ assert_observer_not_notified Widget, WidgetObserver
+ assert_observer_not_notified Budget, BudgetObserver
+ assert_observer_not_notified Widget, AuditTrail
+ assert_observer_notified Budget, AuditTrail
+ end
+
test "can disable observers for the duration of a block" do
yielded = false
ORM.observers.disable :budget_observer do
@@ -118,5 +177,44 @@ class ObserverArrayTest < ActiveModel::TestCase
ORM.observers.disable Widget
end
end
+
+ test "allows #enable at the superclass level to override #disable at the subclass level when called last" do
+ Widget.observers.disable :all
+ ORM.observers.enable :all
+
+ assert_observer_notified Widget, WidgetObserver
+ assert_observer_notified Budget, BudgetObserver
+ assert_observer_notified Widget, AuditTrail
+ assert_observer_notified Budget, AuditTrail
+ end
+
+ test "allows #disable at the superclass level to override #enable at the subclass level when called last" do
+ Budget.observers.enable :audit_trail
+ ORM.observers.disable :audit_trail
+
+ assert_observer_notified Widget, WidgetObserver
+ assert_observer_notified Budget, BudgetObserver
+ assert_observer_not_notified Widget, AuditTrail
+ assert_observer_not_notified Budget, AuditTrail
+ end
+
+ test "can use the block form at different levels of the hierarchy" do
+ yielded = false
+ Widget.observers.disable :all
+
+ ORM.observers.enable :all do
+ yielded = true
+ assert_observer_notified Widget, WidgetObserver
+ assert_observer_notified Budget, BudgetObserver
+ assert_observer_notified Widget, AuditTrail
+ assert_observer_notified Budget, AuditTrail
+ end
+
+ assert yielded
+ assert_observer_not_notified Widget, WidgetObserver
+ assert_observer_notified Budget, BudgetObserver
+ assert_observer_not_notified Widget, AuditTrail
+ assert_observer_notified Budget, AuditTrail
+ end
end