-
Notifications
You must be signed in to change notification settings - Fork 465
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
Conversation
we're validating the column, it doesn't make sense to validate it against a string when the column only accepts integers properly defining the table primary key
siblings should probably not return themselves and siblings of roots should not return nodes at all
@@ -116,6 +116,10 @@ def ancestry_changed? | |||
end | |||
end | |||
|
|||
def sane_ancestor_ids? | |||
valid? || errors[self.ancestry_base_class.ancestry_column].blank? | |||
end |
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
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
the goal is to focus on a single format agnostic field
@@ -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 comment
The 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.
And since we are moving the serialization to a single method - the chances of failure is much lower than when this field was formed all over the code.
/review request @d-m-u |
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.
yeah, this all looks good
Introduce sane_ancestor_ids
specs going towards
ancestor_ids
Prep for ancestor_ids work -- #481