From 92deaac59750f6ca92db63fd5ddf92f1b0ed343a Mon Sep 17 00:00:00 2001 From: Hamed Asghari Date: Thu, 18 Jan 2024 09:33:15 -0700 Subject: [PATCH] style: Fix rubocop violations --- lib/parentry/navigation.rb | 2 +- spec/parentry/navigation_spec.rb | 22 ++++++++--------- spec/parentry_spec.rb | 42 ++++++++++++++++---------------- spec/support/array.rb | 2 +- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/parentry/navigation.rb b/lib/parentry/navigation.rb index c84b620..509b31c 100644 --- a/lib/parentry/navigation.rb +++ b/lib/parentry/navigation.rb @@ -33,7 +33,7 @@ def ancestors(scopes = {}) end def leaf? - children.size.zero? + children.empty? end alias childless? leaf? diff --git a/spec/parentry/navigation_spec.rb b/spec/parentry/navigation_spec.rb index a553766..5790b12 100644 --- a/spec/parentry/navigation_spec.rb +++ b/spec/parentry/navigation_spec.rb @@ -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 @@ -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 diff --git a/spec/parentry_spec.rb b/spec/parentry_spec.rb index c734b1e..27bab6f 100644 --- a/spec/parentry_spec.rb +++ b/spec/parentry_spec.rb @@ -4,7 +4,7 @@ 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 @@ -12,36 +12,36 @@ 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 diff --git a/spec/support/array.rb b/spec/support/array.rb index 2a5ee28..f5120ef 100644 --- a/spec/support/array.rb +++ b/spec/support/array.rb @@ -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