Skip to content
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

Merged
merged 4 commits into from
Aug 10, 2020

Conversation

kbrock
Copy link
Collaborator

@kbrock kbrock commented Aug 4, 2020

Introduce sane_ancestor_ids
specs going towards ancestor_ids

Prep for ancestor_ids work -- #481

kbrock added 4 commits August 3, 2020 19:53
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
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 96.585% when pulling 06449ad on kbrock:attribute_prep into 9c4eb73 on stefankroes:master.

@@ -116,6 +116,10 @@ def ancestry_changed?
end
end

def sane_ancestor_ids?
valid? || errors[self.ancestry_base_class.ancestry_column].blank?
end
Copy link
Collaborator Author

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] }
Copy link
Collaborator Author

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|
Copy link
Collaborator Author

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.

@kbrock
Copy link
Collaborator Author

kbrock commented Aug 9, 2020

/review request @d-m-u

Copy link
Contributor

@d-m-u d-m-u left a 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

@kbrock kbrock merged commit 00d8ded into stefankroes:master Aug 10, 2020
@kbrock kbrock deleted the attribute_prep branch August 10, 2020 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants