Skip to content

Commit

Permalink
style: Fix rubocop violations
Browse files Browse the repository at this point in the history
  • Loading branch information
hasghari committed Jan 18, 2024
1 parent a2e4c29 commit 92deaac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lib/parentry/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def ancestors(scopes = {})
end

def leaf?
children.size.zero?
children.empty?
end
alias childless? leaf?

Expand Down
22 changes: 11 additions & 11 deletions spec/parentry/navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
end

describe '#child_ids' do
it { expect(tree_nodes(:n1).child_ids).to match_array [2, 3] }
it { expect(tree_nodes(:n1).child_ids).to contain_exactly(2, 3) }
it { expect(tree_nodes(:n1_n2).child_ids).to eq [4] }
end

Expand Down Expand Up @@ -88,31 +88,31 @@
end

describe '#subtree_ids' do
it { expect(tree_nodes(:n1).subtree_ids).to match_array [1, 2, 3, 4] }
it { expect(tree_nodes(:n1_n2).subtree_ids).to match_array [2, 4] }
it { expect(tree_nodes(:n1).subtree_ids).to contain_exactly(1, 2, 3, 4) }
it { expect(tree_nodes(:n1_n2).subtree_ids).to contain_exactly(2, 4) }
it { expect(tree_nodes(:n1_n2_n4).subtree_ids).to eq [4] }
it { expect(tree_nodes(:n5).subtree_ids).to match_array [5, 6, 7, 8] }
it { expect(tree_nodes(:n5).subtree_ids).to contain_exactly(5, 6, 7, 8) }
end

describe '#subtree' do
it { expect(tree_nodes(:n1).subtree.map(&:id)).to match_array [1, 2, 3, 4] }
it { expect(tree_nodes(:n1_n2).subtree.map(&:id)).to match_array [2, 4] }
it { expect(tree_nodes(:n1).subtree.map(&:id)).to contain_exactly(1, 2, 3, 4) }
it { expect(tree_nodes(:n1_n2).subtree.map(&:id)).to contain_exactly(2, 4) }
it { expect(tree_nodes(:n1_n2_n4).subtree.map(&:id)).to eq [4] }
it { expect(tree_nodes(:n5).subtree.map(&:id)).to match_array [5, 6, 7, 8] }
it { expect(tree_nodes(:n5).subtree.map(&:id)).to contain_exactly(5, 6, 7, 8) }
end

describe '#descendant_ids' do
it { expect(tree_nodes(:n1).descendant_ids).to match_array [2, 3, 4] }
it { expect(tree_nodes(:n1).descendant_ids).to contain_exactly(2, 3, 4) }
it { expect(tree_nodes(:n1_n2).descendant_ids).to eq [4] }
it { expect(tree_nodes(:n1_n2_n4).descendant_ids).to eq [] }
it { expect(tree_nodes(:n5).descendant_ids).to match_array [6, 7, 8] }
it { expect(tree_nodes(:n5).descendant_ids).to contain_exactly(6, 7, 8) }
end

describe '#descendants' do
it { expect(tree_nodes(:n1).descendants.map(&:id)).to match_array [2, 3, 4] }
it { expect(tree_nodes(:n1).descendants.map(&:id)).to contain_exactly(2, 3, 4) }
it { expect(tree_nodes(:n1_n2).descendants.map(&:id)).to eq [4] }
it { expect(tree_nodes(:n1_n2_n4).descendants.map(&:id)).to eq [] }
it { expect(tree_nodes(:n5).descendants.map(&:id)).to match_array [6, 7, 8] }
it { expect(tree_nodes(:n5).descendants.map(&:id)).to contain_exactly(6, 7, 8) }
end

describe '#depth' do
Expand Down
42 changes: 21 additions & 21 deletions spec/parentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@
fixtures :tree_nodes

it 'has a version number' do
expect(Parentry::VERSION).not_to be nil
expect(Parentry::VERSION).not_to be_nil
end

it 'responds to parentry' do
expect(TreeNode).to respond_to :parentry
end

describe 'scopes' do
it { expect(TreeNode.before_depth(1).pluck(:id)).to match_array [1, 5] }
it { expect(TreeNode.before_depth(2).pluck(:id)).to match_array [1, 2, 3, 5, 6] }
it { expect(TreeNode.before_depth(1).pluck(:id)).to contain_exactly(1, 5) }
it { expect(TreeNode.before_depth(2).pluck(:id)).to contain_exactly(1, 2, 3, 5, 6) }

it { expect(TreeNode.to_depth(1).pluck(:id)).to match_array [1, 2, 3, 5, 6] }
it { expect(TreeNode.to_depth(2).pluck(:id)).to match_array [1, 2, 3, 4, 5, 6, 7] }
it { expect(TreeNode.to_depth(1).pluck(:id)).to contain_exactly(1, 2, 3, 5, 6) }
it { expect(TreeNode.to_depth(2).pluck(:id)).to contain_exactly(1, 2, 3, 4, 5, 6, 7) }

it { expect(TreeNode.at_depth(0).pluck(:id)).to match_array [1, 5] }
it { expect(TreeNode.at_depth(1).pluck(:id)).to match_array [2, 3, 6] }
it { expect(TreeNode.at_depth(1).joins(:children).pluck(:id)).to match_array [2, 6] }
it { expect(TreeNode.at_depth(2).pluck(:id)).to match_array [4, 7] }
it { expect(TreeNode.at_depth(0).pluck(:id)).to contain_exactly(1, 5) }
it { expect(TreeNode.at_depth(1).pluck(:id)).to contain_exactly(2, 3, 6) }
it { expect(TreeNode.at_depth(1).joins(:children).pluck(:id)).to contain_exactly(2, 6) }
it { expect(TreeNode.at_depth(2).pluck(:id)).to contain_exactly(4, 7) }

it { expect(TreeNode.from_depth(0).pluck(:id)).to match_array [1, 2, 3, 4, 5, 6, 7, 8] }
it { expect(TreeNode.from_depth(1).pluck(:id)).to match_array [2, 3, 4, 6, 7, 8] }
it { expect(TreeNode.from_depth(2).pluck(:id)).to match_array [4, 7, 8] }
it { expect(TreeNode.from_depth(0).pluck(:id)).to contain_exactly(1, 2, 3, 4, 5, 6, 7, 8) }
it { expect(TreeNode.from_depth(1).pluck(:id)).to contain_exactly(2, 3, 4, 6, 7, 8) }
it { expect(TreeNode.from_depth(2).pluck(:id)).to contain_exactly(4, 7, 8) }

it { expect(TreeNode.after_depth(0).pluck(:id)).to match_array [2, 3, 4, 6, 7, 8] }
it { expect(TreeNode.after_depth(1).pluck(:id)).to match_array [4, 7, 8] }
it { expect(TreeNode.after_depth(2).pluck(:id)).to match_array [8] }
it { expect(TreeNode.after_depth(0).pluck(:id)).to contain_exactly(2, 3, 4, 6, 7, 8) }
it { expect(TreeNode.after_depth(1).pluck(:id)).to contain_exactly(4, 7, 8) }
it { expect(TreeNode.after_depth(2).pluck(:id)).to contain_exactly(8) }

it { expect(TreeNode.roots.pluck(:id)).to match_array [1, 5] }
it { expect(TreeNode.roots.pluck(:id)).to contain_exactly(1, 5) }

it { expect(TreeNode.ancestors_of(tree_nodes(:n1_n2_n4)).pluck(:id)).to match_array [1, 2] }
it { expect(TreeNode.ancestors_of(tree_nodes(:n1_n2_n4)).pluck(:id)).to contain_exactly(1, 2) }

it { expect(TreeNode.children_of(tree_nodes(:n1)).pluck(:id)).to match_array [2, 3] }
it { expect(TreeNode.children_of(tree_nodes(:n1)).pluck(:id)).to contain_exactly(2, 3) }

it { expect(TreeNode.descendants_of(tree_nodes(:n1)).pluck(:id)).to match_array [2, 3, 4] }
it { expect(TreeNode.descendants_of(tree_nodes(:n1)).pluck(:id)).to contain_exactly(2, 3, 4) }

it { expect(TreeNode.subtree_of(tree_nodes(:n1)).pluck(:id)).to match_array [1, 2, 3, 4] }
it { expect(TreeNode.subtree_of(tree_nodes(:n1)).pluck(:id)).to contain_exactly(1, 2, 3, 4) }

it { expect(TreeNode.siblings_of(tree_nodes(:n1_n2)).pluck(:id)).to match_array [3] }
it { expect(TreeNode.siblings_of(tree_nodes(:n1_n2)).pluck(:id)).to contain_exactly(3) }
end

describe '::arrange' do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/array.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Array
# The sole purpose of this method is to serialize the data for the fixtures based on the strategy being used.
def to_parentry
case ENV['STRATEGY']
case ENV.fetch('STRATEGY', nil)
when 'array'
self
else
Expand Down

0 comments on commit 92deaac

Please sign in to comment.