Skip to content
This repository
Browse code

Remove deprecation warnings from tests

  • Loading branch information...
commit f944d528c495fe2ac04caeb1354260eae953f4c7 1 parent 62c955d
Rafael Mendonça França authored
20  activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1144,7 +1144,8 @@ def test_depends_and_nullify
1144 1144
   end
1145 1145
 
1146 1146
   def test_restrict
1147  
-    # ActiveRecord::Base.dependent_restrict_raises = true, by default
  1147
+    option_before = ActiveRecord::Base.dependent_restrict_raises
  1148
+    ActiveRecord::Base.dependent_restrict_raises = true
1148 1149
 
1149 1150
     firm = RestrictedFirm.create!(:name => 'restrict')
1150 1151
     firm.companies.create(:name => 'child')
@@ -1153,13 +1154,13 @@ def test_restrict
1153 1154
     assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
1154 1155
     assert RestrictedFirm.exists?(:name => 'restrict')
1155 1156
     assert firm.companies.exists?(:name => 'child')
  1157
+  ensure
  1158
+    ActiveRecord::Base.dependent_restrict_raises = option_before
1156 1159
   end
1157 1160
 
1158 1161
   def test_restrict_when_dependent_restrict_raises_config_set_to_false
1159  
-    # ActiveRecord::Base.dependent_restrict_raises = true, by default
1160  
-
  1162
+    option_before = ActiveRecord::Base.dependent_restrict_raises
1161 1163
     ActiveRecord::Base.dependent_restrict_raises = false
1162  
-    # add an error on the model instead of raising ActiveRecord::DeleteRestrictionError
1163 1164
 
1164 1165
     firm = RestrictedFirm.create!(:name => 'restrict')
1165 1166
     firm.companies.create(:name => 'child')
@@ -1174,7 +1175,7 @@ def test_restrict_when_dependent_restrict_raises_config_set_to_false
1174 1175
     assert RestrictedFirm.exists?(:name => 'restrict')
1175 1176
     assert firm.companies.exists?(:name => 'child')
1176 1177
   ensure
1177  
-    ActiveRecord::Base.dependent_restrict_raises = true
  1178
+    ActiveRecord::Base.dependent_restrict_raises = option_before
1178 1179
   end
1179 1180
 
1180 1181
   def test_included_in_collection
@@ -1680,9 +1681,14 @@ def test_replace
1680 1681
   end
1681 1682
 
1682 1683
   def test_building_has_many_association_with_restrict_dependency
  1684
+    option_before = ActiveRecord::Base.dependent_restrict_raises
  1685
+    ActiveRecord::Base.dependent_restrict_raises = true
  1686
+
1683 1687
     klass = Class.new(ActiveRecord::Base)
1684  
-    
1685  
-    assert_deprecated     { klass.has_many :companies, :dependent => :restrict }  
  1688
+
  1689
+    assert_deprecated     { klass.has_many :companies, :dependent => :restrict }
1686 1690
     assert_not_deprecated { klass.has_many :companies }
  1691
+  ensure
  1692
+    ActiveRecord::Base.dependent_restrict_raises = option_before
1687 1693
   end
1688 1694
 end
18  activerecord/test/cases/associations/has_one_associations_test.rb
@@ -157,7 +157,8 @@ def test_dependence_with_nil_associate
157 157
   end
158 158
 
159 159
   def test_dependence_with_restrict
160  
-    # ActiveRecord::Base.dependent_restrict_raises = true, by default
  160
+    option_before = ActiveRecord::Base.dependent_restrict_raises
  161
+    ActiveRecord::Base.dependent_restrict_raises = true
161 162
 
162 163
     firm = RestrictedFirm.create!(:name => 'restrict')
163 164
     firm.create_account(:credit_limit => 10)
@@ -167,13 +168,13 @@ def test_dependence_with_restrict
167 168
     assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
168 169
     assert RestrictedFirm.exists?(:name => 'restrict')
169 170
     assert firm.account.present?
  171
+  ensure
  172
+    ActiveRecord::Base.dependent_restrict_raises = option_before
170 173
   end
171 174
 
172 175
   def test_dependence_with_restrict_with_dependent_restrict_raises_config_set_to_false
173  
-    # ActiveRecord::Base.dependent_restrict_raises = true, by default
174  
-
  176
+    option_before = ActiveRecord::Base.dependent_restrict_raises
175 177
     ActiveRecord::Base.dependent_restrict_raises = false
176  
-    # adds an error on the model instead of raising ActiveRecord::DeleteRestrictionError
177 178
 
178 179
     firm = RestrictedFirm.create!(:name => 'restrict')
179 180
     firm.create_account(:credit_limit => 10)
@@ -187,7 +188,7 @@ def test_dependence_with_restrict_with_dependent_restrict_raises_config_set_to_f
187 188
     assert RestrictedFirm.exists?(:name => 'restrict')
188 189
     assert firm.account.present?
189 190
   ensure
190  
-    ActiveRecord::Base.dependent_restrict_raises = true
  191
+    ActiveRecord::Base.dependent_restrict_raises = option_before
191 192
   end
192 193
 
193 194
   def test_successful_build_association
@@ -484,9 +485,14 @@ def test_association_attributes_are_available_to_after_initialize
484 485
   end
485 486
 
486 487
   def test_building_has_one_association_with_dependent_restrict
  488
+    option_before = ActiveRecord::Base.dependent_restrict_raises
  489
+    ActiveRecord::Base.dependent_restrict_raises = true
  490
+
487 491
     klass = Class.new(ActiveRecord::Base)
488  
-    
  492
+
489 493
     assert_deprecated     { klass.has_one :account, :dependent => :restrict }
490 494
     assert_not_deprecated { klass.has_one :account }
  495
+  ensure
  496
+    ActiveRecord::Base.dependent_restrict_raises = option_before
491 497
   end
492 498
 end
3  activerecord/test/cases/helper.rb
@@ -22,6 +22,9 @@
22 22
 # Enable Identity Map only when ENV['IM'] is set to "true"
23 23
 ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "true")
24 24
 
  25
+# Avoid deprecation warning setting dependent_restric_raises to false. The default is true
  26
+ActiveRecord::Base.dependent_restrict_raises = false
  27
+
25 28
 # Connect to the database
26 29
 ARTest.connect
27 30
 

0 notes on commit f944d52

Please sign in to comment.
Something went wrong with that request. Please try again.