-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bugs with *_including_tree argument list
- Loading branch information
Tom Smyth
committed
Oct 21, 2016
1 parent
59238dc
commit 043b0bc
Showing
3 changed files
with
38 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,18 +26,36 @@ | |
user3.children << user5 | ||
user3.children << user6 | ||
|
||
user1.contracts.create!(contract_type: ct1) | ||
user2.contracts.create!(contract_type: ct1) | ||
user3.contracts.create!(contract_type: ct1) | ||
user3.contracts.create!(contract_type: ct2) | ||
user4.contracts.create!(contract_type: ct2) | ||
user5.contracts.create!(contract_type: ct1) | ||
user6.contracts.create!(contract_type: ct2) | ||
user1.contracts.create!(title: "Contract 1", contract_type: ct1) | ||
user2.contracts.create!(title: "Contract 2", contract_type: ct1) | ||
user3.contracts.create!(title: "Contract 3", contract_type: ct1) | ||
user3.contracts.create!(title: "Contract 4", contract_type: ct2) | ||
user4.contracts.create!(title: "Contract 5", contract_type: ct2) | ||
user5.contracts.create!(title: "Contract 6", contract_type: ct1) | ||
user6.contracts.create!(title: "Contract 7", contract_type: ct2) | ||
end | ||
|
||
context "with basic config" do | ||
let!(:group) { Group.create!(name: "TheGroup") } | ||
|
||
it "loads all nodes in a constant number of queries" do | ||
expect do | ||
root = group_reloaded.root_user_including_tree | ||
expect(root.children[0].email).to eq "[email protected]" | ||
expect(root.children[0].parent.children[1].email).to eq "[email protected]" | ||
end.to_not exceed_query_limit(2) | ||
end | ||
|
||
it "loads all nodes plus single association in a constant number of queries" do | ||
expect do | ||
root = group_reloaded.root_user_including_tree(:contracts) | ||
expect(root.children[0].email).to eq "[email protected]" | ||
expect(root.children[0].parent.children[1].email).to eq "[email protected]" | ||
expect(root.children[0].children[0].contracts[0].user. | ||
parent.parent.children[1].children[1].contracts[0].title).to eq "Contract 7" | ||
end.to_not exceed_query_limit(3) | ||
end | ||
|
||
it "loads all nodes and associations in a constant number of queries" do | ||
expect do | ||
root = group_reloaded.root_user_including_tree(contracts: :contract_type) | ||
|
@@ -66,6 +84,10 @@ | |
to eq "[email protected]" | ||
end | ||
|
||
it "works if true passed on first call" do | ||
expect(group_reloaded.root_user_including_tree(true).email).to eq "[email protected]" | ||
end | ||
|
||
it "eager loads inverse association to group" do | ||
expect do | ||
root = group_reloaded.root_user_including_tree | ||
|