aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_one_associations_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/associations/has_one_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb47
1 files changed, 16 insertions, 31 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index ad0d47920d..ed22a9802f 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -186,25 +186,6 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
assert firm.account.present?
end
- def test_restrict_with_error_is_deprecated_using_key_one
- I18n.backend = I18n::Backend::Simple.new
- I18n.backend.store_translations :en, activerecord: { errors: { messages: { restrict_dependent_destroy: { one: "message for deprecated key" } } } }
-
- firm = RestrictedWithErrorFirm.create!(name: "restrict")
- firm.create_account(credit_limit: 10)
-
- assert_not_nil firm.account
-
- assert_deprecated { firm.destroy }
-
- assert !firm.errors.empty?
- assert_equal "message for deprecated key", firm.errors[:base].first
- assert RestrictedWithErrorFirm.exists?(name: "restrict")
- assert firm.account.present?
- ensure
- I18n.backend.reload!
- end
-
def test_restrict_with_error
firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.create_account(credit_limit: 10)
@@ -221,7 +202,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
def test_restrict_with_error_with_locale
I18n.backend = I18n::Backend::Simple.new
- I18n.backend.store_translations "en", activerecord: {attributes: {restricted_with_error_firm: {account: "firm account"}}}
+ I18n.backend.store_translations "en", activerecord: { attributes: { restricted_with_error_firm: { account: "firm account" } } }
firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.create_account(credit_limit: 10)
@@ -326,6 +307,16 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_reload_association
+ odegy = companies(:odegy)
+
+ assert_equal 53, odegy.account.credit_limit
+ Account.where(id: odegy.account.id).update_all(credit_limit: 80)
+ assert_equal 53, odegy.account.credit_limit
+
+ assert_equal 80, odegy.reload_account.credit_limit
+ end
+
def test_build
firm = Firm.new("name" => "GlobalMegaCorp")
firm.save
@@ -539,21 +530,21 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
def test_build_with_block
car = Car.create(name: "honda")
- bulb = car.build_bulb{ |b| b.color = "Red" }
+ bulb = car.build_bulb { |b| b.color = "Red" }
assert_equal "RED!", bulb.color
end
def test_create_with_block
car = Car.create(name: "honda")
- bulb = car.create_bulb{ |b| b.color = "Red" }
+ bulb = car.create_bulb { |b| b.color = "Red" }
assert_equal "RED!", bulb.color
end
def test_create_bang_with_block
car = Car.create(name: "honda")
- bulb = car.create_bulb!{ |b| b.color = "Red" }
+ bulb = car.create_bulb! { |b| b.color = "Red" }
assert_equal "RED!", bulb.color
end
@@ -601,7 +592,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
new_ship = Ship.create(name: "new name")
assert_queries(2) do
- # One query for updating name and second query for updating pirate_id
+ # One query to nullify the old ship, one query to update the new ship
pirate.ship = new_ship
end
@@ -654,12 +645,6 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
end
end
- def test_association_force_reload_with_only_true_is_deprecated
- firm = Firm.find(1)
-
- assert_deprecated { firm.account(true) }
- end
-
class SpecialBook < ActiveRecord::Base
self.table_name = "books"
belongs_to :author, class_name: "SpecialAuthor"
@@ -675,6 +660,6 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
book = SpecialBook.create!(status: "published")
author.book = book
- refute_equal 0, SpecialAuthor.joins(:book).where(books: { status: "published" } ).count
+ refute_equal 0, SpecialAuthor.joins(:book).where(books: { status: "published" }).count
end
end