diff options
Diffstat (limited to 'activerecord/test')
| -rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 22 | ||||
| -rw-r--r-- | activerecord/test/cases/associations/has_one_associations_test.rb | 18 | ||||
| -rw-r--r-- | activerecord/test/cases/helper.rb | 3 | ||||
| -rw-r--r-- | activerecord/test/cases/reflection_test.rb | 4 | ||||
| -rw-r--r-- | activerecord/test/models/company.rb | 2 |
5 files changed, 32 insertions, 17 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 367f87031c..ab1e821aab 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1144,7 +1144,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_restrict - # ActiveRecord::Base.dependent_restrict_raises = true, by default + option_before = ActiveRecord::Base.dependent_restrict_raises + ActiveRecord::Base.dependent_restrict_raises = true firm = RestrictedFirm.create!(:name => 'restrict') firm.companies.create(:name => 'child') @@ -1153,13 +1154,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy } assert RestrictedFirm.exists?(:name => 'restrict') assert firm.companies.exists?(:name => 'child') + ensure + ActiveRecord::Base.dependent_restrict_raises = option_before end def test_restrict_when_dependent_restrict_raises_config_set_to_false - # ActiveRecord::Base.dependent_restrict_raises = true, by default - + option_before = ActiveRecord::Base.dependent_restrict_raises ActiveRecord::Base.dependent_restrict_raises = false - # add an error on the model instead of raising ActiveRecord::DeleteRestrictionError firm = RestrictedFirm.create!(:name => 'restrict') firm.companies.create(:name => 'child') @@ -1174,7 +1175,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert RestrictedFirm.exists?(:name => 'restrict') assert firm.companies.exists?(:name => 'child') ensure - ActiveRecord::Base.dependent_restrict_raises = true + ActiveRecord::Base.dependent_restrict_raises = option_before end def test_included_in_collection @@ -1279,7 +1280,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_get_ids_for_ordered_association - assert_equal [companies(:second_client).id, companies(:first_client).id], companies(:first_firm).clients_ordered_by_rating_ids + assert_equal [companies(:second_client).id, companies(:first_client).id], companies(:first_firm).clients_ordered_by_name_ids end def test_assign_ids_ignoring_blanks @@ -1680,9 +1681,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_building_has_many_association_with_restrict_dependency + option_before = ActiveRecord::Base.dependent_restrict_raises + ActiveRecord::Base.dependent_restrict_raises = true + klass = Class.new(ActiveRecord::Base) - - assert_deprecated { klass.has_many :companies, :dependent => :restrict } + + assert_deprecated { klass.has_many :companies, :dependent => :restrict } assert_not_deprecated { klass.has_many :companies } + ensure + ActiveRecord::Base.dependent_restrict_raises = option_before end end diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 7c6736fb95..37be6a279d 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -157,7 +157,8 @@ class HasOneAssociationsTest < ActiveRecord::TestCase end def test_dependence_with_restrict - # ActiveRecord::Base.dependent_restrict_raises = true, by default + option_before = ActiveRecord::Base.dependent_restrict_raises + ActiveRecord::Base.dependent_restrict_raises = true firm = RestrictedFirm.create!(:name => 'restrict') firm.create_account(:credit_limit => 10) @@ -167,13 +168,13 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy } assert RestrictedFirm.exists?(:name => 'restrict') assert firm.account.present? + ensure + ActiveRecord::Base.dependent_restrict_raises = option_before end def test_dependence_with_restrict_with_dependent_restrict_raises_config_set_to_false - # ActiveRecord::Base.dependent_restrict_raises = true, by default - + option_before = ActiveRecord::Base.dependent_restrict_raises ActiveRecord::Base.dependent_restrict_raises = false - # adds an error on the model instead of raising ActiveRecord::DeleteRestrictionError firm = RestrictedFirm.create!(:name => 'restrict') firm.create_account(:credit_limit => 10) @@ -187,7 +188,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert RestrictedFirm.exists?(:name => 'restrict') assert firm.account.present? ensure - ActiveRecord::Base.dependent_restrict_raises = true + ActiveRecord::Base.dependent_restrict_raises = option_before end def test_successful_build_association @@ -484,9 +485,14 @@ class HasOneAssociationsTest < ActiveRecord::TestCase end def test_building_has_one_association_with_dependent_restrict + option_before = ActiveRecord::Base.dependent_restrict_raises + ActiveRecord::Base.dependent_restrict_raises = true + klass = Class.new(ActiveRecord::Base) - + assert_deprecated { klass.has_one :account, :dependent => :restrict } assert_not_deprecated { klass.has_one :account } + ensure + ActiveRecord::Base.dependent_restrict_raises = option_before end end diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index b4598ab32a..359cabd016 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -22,6 +22,9 @@ ActiveSupport::Deprecation.debug = true # Enable Identity Map only when ENV['IM'] is set to "true" ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "true") +# Avoid deprecation warning setting dependent_restric_raises to false. The default is true +ActiveRecord::Base.dependent_restrict_raises = false + # Connect to the database ARTest.connect diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index 297fb56570..16f05f2198 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -189,8 +189,8 @@ class ReflectionTest < ActiveRecord::TestCase def test_reflection_of_all_associations # FIXME these assertions bust a lot - assert_equal 38, Firm.reflect_on_all_associations.size - assert_equal 28, Firm.reflect_on_all_associations(:has_many).size + assert_equal 39, Firm.reflect_on_all_associations.size + assert_equal 29, Firm.reflect_on_all_associations(:has_many).size assert_equal 10, Firm.reflect_on_all_associations(:has_one).size assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size end diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 764f1c1df5..fbdfaa2c29 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -45,7 +45,7 @@ class Firm < Company has_many :unsorted_clients_with_symbol, :class_name => :Client has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC" has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" - has_many :clients_ordered_by_rating, :order => "rating", :class_name => "Client" + has_many :clients_ordered_by_name, :order => "name", :class_name => "Client" has_many :unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all |
