Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixbuenemann/f34610a8006519f2e09b to your computer and use it in GitHub Desktop.
Save felixbuenemann/f34610a8006519f2e09b to your computer and use it in GitHub Desktop.
diff --git a/lib/acts_as_tree.rb b/lib/acts_as_tree.rb
index 3279d87..1395481 100644
--- a/lib/acts_as_tree.rb
+++ b/lib/acts_as_tree.rb
@@ -240,7 +240,7 @@ module ActsAsTree
# subchild1.leaf? # => true
# child1.leaf? # => false
def leaf?
- children.empty?
+ children.size == 0
end
private
diff --git a/test/acts_as_tree_test.rb b/test/acts_as_tree_test.rb
index 539a82b..95b85cd 100644
--- a/test/acts_as_tree_test.rb
+++ b/test/acts_as_tree_test.rb
@@ -21,13 +21,13 @@ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
# AR keeps printing annoying schema statements
$stdout = StringIO.new
-def setup_db
+def setup_db(counter_cache = false)
ActiveRecord::Base.logger
ActiveRecord::Schema.define(version: 1) do
create_table :mixins do |t|
t.column :type, :string
t.column :parent_id, :integer
- t.column :children_count, :integer, default: 0
+ t.column :children_count, :integer, default: 0 if counter_cache
end
end
end
@@ -395,7 +395,7 @@ end
class TreeTestWithCounterCache < MiniTest::Unit::TestCase
def setup
teardown_db
- setup_db
+ setup_db(true)
@root = TreeMixinWithCounterCache.create!
@child1 = TreeMixinWithCounterCache.create! parent_id: @root.id
@child1_child1 = TreeMixinWithCounterCache.create! parent_id: @child1.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment