-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: expire_changed_association_uniq_keys and inverse_instance
- Loading branch information
OuYangJinTing
committed
Apr 2, 2020
1 parent
493243b
commit 65482e5
Showing
7 changed files
with
54 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,20 +47,20 @@ def test_has_one_preload_caches_includes | |
]) | ||
namespaces = users.map { |user| user.create_namespace(name: user.name) } | ||
|
||
assert_queries(2) { User.includes(:namespace).order(id: :asc).to_a } # Write cache | ||
assert_queries(2) { User.includes(:namespace).order(id: :asc).to_a } # Write cache | ||
assert_queries(1) do | ||
assert_equal namespaces, User.includes(:namespace).order(id: :asc).map(&:namespace) | ||
end | ||
end | ||
|
||
def test_belongs_to_when_read_multi_missed_from_cache_should_will_fetch_missed_records_from_db | ||
def test_has_one_when_read_multi_missed_from_cache_should_will_fetch_missed_records_from_db | ||
users = User.create([ | ||
{ name: "foobar1", email: "[email protected]" }, | ||
{ name: "foobar2", email: "[email protected]" }, | ||
{ name: "foobar3", email: "[email protected]" } | ||
]) | ||
namespaces = users.map { |user| user.create_namespace(name: user.name) } | ||
assert_queries(2) { User.includes(:namespace).order(id: :asc).to_a } # Write cache | ||
assert_queries(2) { User.includes(:namespace).order(id: :asc).to_a } # Write cache | ||
expired_namespace = namespaces.first | ||
expired_namespace.expire_second_level_cache | ||
|
||
|
@@ -73,6 +73,28 @@ def test_belongs_to_when_read_multi_missed_from_cache_should_will_fetch_missed_r | |
end | ||
end | ||
|
||
def test_has_one_preloader_returns_correct_records_after_modify | ||
user = User.create(name: "foobar", email: "[email protected]") | ||
|
||
old_namespace = user.create_namespace(name: "old") | ||
assert_queries(2) { User.includes(:namespace).order(id: :asc).to_a } # Write cache | ||
assert_queries(1) do | ||
assert_equal old_namespace, User.includes(:namespace).first.namespace | ||
end | ||
|
||
new_namespace = user.create_namespace(name: "new") | ||
assert_queries(2) { User.includes(:namespace).order(id: :asc).to_a } # Write cache | ||
assert_queries(1) do | ||
assert_equal new_namespace, User.includes(:namespace).first.namespace | ||
end | ||
end | ||
|
||
def test_has_one_preloader_caches_includes_tried_set_inverse_instance | ||
User.create(name: "foobar", email: "[email protected]").create_account(site: "foobar") | ||
users = User.includes(:account) | ||
assert_equal users.first.object_id, users.first.account.user.object_id | ||
end | ||
|
||
def test_has_many_preloader_returns_correct_results | ||
topic = Topic.create(id: 1) | ||
Post.create(id: 1) | ||
|