-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sane_ancestor_ids and simplify specs #495
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,11 @@ class ScopesTest < ActiveSupport::TestCase | |
def test_scopes | ||
AncestryTestDatabase.with_model :depth => 3, :width => 3 do |model, roots| | ||
# Roots assertion | ||
assert_equal roots.map(&:first), model.roots.to_a | ||
assert_equal roots.map(&:first).sort, model.roots.to_a.sort | ||
|
||
# All roots are root's siblings (want to change this) | ||
a_root = roots.first.first | ||
assert_equal model.siblings_of(a_root).sort, roots.map(&:first).sort | ||
|
||
model.all.each do |test_node| | ||
# Assertions for ancestors_of named scope | ||
|
@@ -55,12 +59,12 @@ def test_order_by | |
AncestryTestDatabase.with_model :depth => 3, :width => 3 do |model, roots| | ||
# not thrilled with this. mac postgres has odd sorting requirements | ||
if ENV["DB"].to_s =~ /pg/ && RUBY_PLATFORM !~ /x86_64-darwin/ | ||
expected = model.all.sort_by { |m| [m.ancestry.to_s.gsub('/',''), m.id.to_i] } | ||
expected = model.all.sort_by { |m| [m.ancestor_ids.map(&:to_s).join, m.id.to_i] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the goal is to focus on a single format agnostic field |
||
else | ||
expected = model.all.sort_by { |m| [m.ancestry.to_s, m.id.to_i] } | ||
expected = model.all.sort_by { |m| [m.ancestor_ids.map(&:to_s), m.id.to_i] } | ||
end | ||
actual = model.ordered_by_ancestry_and(:id) | ||
assert_equal expected.map { |r| [r.ancestry, r.id.to_s] }, actual.map { |r| [r.ancestry, r.id.to_s] } | ||
assert_equal expected.map { |r| [r.ancestor_ids, r.id.to_s] }, actual.map { |r| [r.ancestor_ids, r.id.to_s] } | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,42 +8,29 @@ def test_ancestry_column_validation | |
node.send :write_attribute, model.ancestry_column, value | ||
node.valid?; assert node.errors[model.ancestry_column].blank? | ||
end | ||
['1/3/', '/2/3', 'a', 'a/b', '-34', '/54'].each do |value| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we used to focus that the format of this field was serialized correctly. The new functionality parses these values just fine. |
||
['a', 'a/b', '-34'].each do |value| | ||
node.send :write_attribute, model.ancestry_column, value | ||
node.valid?; assert !node.errors[model.ancestry_column].blank? | ||
end | ||
end | ||
end | ||
|
||
def test_ancestry_column_validation_alt | ||
AncestryTestDatabase.with_model(:primary_key_format => /[a-z]+/) do |model| | ||
node = model.create | ||
AncestryTestDatabase.with_model(:id => :string, :primary_key_format => /[a-z]/) do |model| | ||
node = model.create(:id => 'z') | ||
['a', 'a/b', 'a/b/c', nil].each do |value| | ||
node.send :write_attribute, model.ancestry_column, value | ||
node.valid?; assert node.errors[model.ancestry_column].blank? | ||
end | ||
['1', '1/2', 'a/b/', '/a/b'].each do |value| | ||
['1', '1/2', 'a-b/c'].each do |value| | ||
node.send :write_attribute, model.ancestry_column, value | ||
node.valid?; assert !node.errors[model.ancestry_column].blank? | ||
end | ||
end | ||
end | ||
|
||
def test_ancestry_column_validation_full_key | ||
AncestryTestDatabase.with_model(:primary_key_format => /\A[a-z]+(\/[a-z]+)*\Z/) do |model| | ||
node = model.create | ||
['a', 'a/b', 'a/b/c', nil].each do |value| | ||
node.send :write_attribute, model.ancestry_column, value | ||
node.valid?; assert node.errors[model.ancestry_column].blank? | ||
end | ||
['1', '1/2', 'a/b/', '/a/b'].each do |value| | ||
node.send :write_attribute, model.ancestry_column, value | ||
node.valid?; assert !node.errors[model.ancestry_column].blank? | ||
end | ||
end | ||
end | ||
|
||
def test_validate_ancestry_exclude_self | ||
def test_ancestry_validation_exclude_self | ||
AncestryTestDatabase.with_model do |model| | ||
parent = model.create! | ||
child = parent.children.create! | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will probably get merged back in when this concept changes. But probably good enough for now