-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from kbrock/missing_parent
Missing parent
- Loading branch information
Showing
4 changed files
with
51 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require_relative '../environment' | ||
|
||
class RelationsTest < ActiveSupport::TestCase | ||
def test_root_found | ||
AncestryTestDatabase.with_model do |model| | ||
parent = model.create | ||
child = model.create!(:ancestor_ids => [parent.id]) | ||
assert_equal(parent, child.root) | ||
end | ||
end | ||
|
||
def test_parent_not_found | ||
AncestryTestDatabase.with_model do |model| | ||
record = model.create | ||
# setting the parent_id to something not valid | ||
record.update_attribute(:ancestor_ids, [record.id + 1]) | ||
assert_nil record.root | ||
end | ||
end | ||
|
||
def test_parent_found | ||
AncestryTestDatabase.with_model do |model| | ||
parent = model.create | ||
child = model.create!(:ancestor_ids => [parent.id]) | ||
assert_equal(parent, child.parent) | ||
end | ||
end | ||
|
||
def test_parent_not_found | ||
AncestryTestDatabase.with_model do |model| | ||
record = model.create | ||
# setting the parent_id to something not valid | ||
record.update_attribute(:ancestor_ids, [record.id + 1]) | ||
assert_nil record.parent | ||
end | ||
end | ||
end |