Skip to content

Commit

Permalink
Merge pull request #690 from kbrock/test_chatter
Browse files Browse the repository at this point in the history
reduce test chatter
  • Loading branch information
kbrock authored Oct 24, 2024
2 parents 6cc9398 + 5bcd89c commit 4d26788
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions ancestry.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ EOF

s.required_ruby_version = '>= 2.5'
s.add_runtime_dependency 'activerecord', '>= 5.2.6'
s.add_runtime_dependency 'logger'
s.add_development_dependency 'appraisal'
s.add_development_dependency 'minitest'
s.add_development_dependency 'rake', '~> 13.0'
Expand Down
1 change: 1 addition & 0 deletions test/concerns/db_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ def self.connection
end

c.send(:has_ancestry)
assert true, "this should not connect to the database"
end
end
23 changes: 15 additions & 8 deletions test/concerns/depth_virtual_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# These are only valid for postgres
class DepthVirtualTest < ActiveSupport::TestCase
def test_depth_caching
return unless test_virtual_column?
assert true, "only runs for postgres and recent rails versions"
return unless only_test_virtual_column?

AncestryTestDatabase.with_model :depth => 3, :width => 3, :cache_depth => :virtual do |_model, roots|
roots.each do |lvl0_node, lvl0_children|
Expand All @@ -19,7 +20,8 @@ def test_depth_caching
end

def test_depth_caching_after_subtree_movement
return unless test_virtual_column?
assert true, "only runs for postgres and recent rails versions"
return unless only_test_virtual_column?

AncestryTestDatabase.with_model :depth => 6, :width => 1, :cache_depth => :virtual do |model, _roots|
node = model.at_depth(3).first
Expand All @@ -35,7 +37,8 @@ def test_depth_caching_after_subtree_movement
end

def test_depth_scopes
return unless test_virtual_column?
assert true, "only runs for postgres and recent rails versions"
return unless only_test_virtual_column?

AncestryTestDatabase.with_model :depth => 4, :width => 2, :cache_depth => true do |model, _roots|
model.before_depth(2).all? { |node| assert node.depth < 2 }
Expand All @@ -47,7 +50,8 @@ def test_depth_scopes
end

def test_depth_scopes_without_depth_cache
return unless test_virtual_column?
assert true, "only runs for postgres and recent rails versions"
return unless only_test_virtual_column?

AncestryTestDatabase.with_model :depth => 4, :width => 2 do |model, _roots|
model.before_depth(2).all? { |node| assert node.depth < 2 }
Expand All @@ -59,7 +63,8 @@ def test_depth_scopes_without_depth_cache
end

def test_exception_when_rebuilding_depth_cache_for_model_without_depth_caching
return unless test_virtual_column?
assert true, "only runs for postgres and recent rails versions"
return unless only_test_virtual_column?

AncestryTestDatabase.with_model do |model|
assert_raise Ancestry::AncestryException do
Expand All @@ -69,7 +74,8 @@ def test_exception_when_rebuilding_depth_cache_for_model_without_depth_caching
end

def test_exception_on_unknown_depth_column
return unless test_virtual_column?
assert true, "only runs for postgres and recent rails versions"
return unless only_test_virtual_column?

AncestryTestDatabase.with_model :cache_depth => true do |model|
assert_raise Ancestry::AncestryException do
Expand All @@ -81,7 +87,8 @@ def test_exception_on_unknown_depth_column
# we are already testing generate and parse against static values
# this assumes those are methods are tested and working
def test_ancestry_depth_change
return unless test_virtual_column?
assert true, "only runs for postgres and recent rails versions"
return unless only_test_virtual_column?

AncestryTestDatabase.with_model do |model|
{
Expand All @@ -98,7 +105,7 @@ def test_ancestry_depth_change
end
end

def test_virtual_column?
def only_test_virtual_column?
AncestryTestDatabase.postgres? && ActiveRecord.version.to_s >= "7.0"
end
end
6 changes: 6 additions & 0 deletions test/concerns/materialized_path2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class MaterializedPath2Test < ActiveSupport::TestCase
def test_ancestry_column_mp2
assert true, "this runs if materialized path2"
return unless AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model do |model|
Expand Down Expand Up @@ -37,6 +38,7 @@ def test_ancestry_column_mp2
end

def test_ancestry_column_validation
assert true, "this runs if materialized path2"
return unless AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model do |model|
Expand All @@ -50,6 +52,7 @@ def test_ancestry_column_validation
end

def test_ancestry_column_validation_fails
assert true, "this runs if materialized path2"
return unless AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model do |model|
Expand All @@ -63,6 +66,7 @@ def test_ancestry_column_validation_fails
end

def test_ancestry_column_validation_string_key
assert true, "this runs if materialized path2"
return unless AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model(:id => :string, :primary_key_format => /[a-z]/) do |model|
Expand All @@ -75,6 +79,7 @@ def test_ancestry_column_validation_string_key
end

def test_ancestry_column_validation_string_key_fails
assert true, "this runs if materialized path2"
return unless AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model(:id => :string, :primary_key_format => /[a-z]/) do |model|
Expand All @@ -87,6 +92,7 @@ def test_ancestry_column_validation_string_key_fails
end

def test_ancestry_validation_exclude_self
assert true, "this runs if materialized path2"
return unless AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model do |model|
Expand Down
6 changes: 6 additions & 0 deletions test/concerns/materialized_path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class MaterializedPathTest < ActiveSupport::TestCase
def test_ancestry_column_values
assert true, "this runs if materialized path"
return if AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model do |model|
Expand Down Expand Up @@ -37,6 +38,7 @@ def test_ancestry_column_values
end

def test_ancestry_column_validation
assert true, "this runs if materialized path"
return if AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model do |model|
Expand All @@ -50,6 +52,7 @@ def test_ancestry_column_validation
end

def test_ancestry_column_validation_fails
assert true, "this runs if materialized path"
return if AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model do |model|
Expand All @@ -63,6 +66,7 @@ def test_ancestry_column_validation_fails
end

def test_ancestry_column_validation_string_key
assert true, "this runs if materialized path"
return if AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model(:id => :string, :primary_key_format => /[a-z]/) do |model|
Expand All @@ -76,6 +80,7 @@ def test_ancestry_column_validation_string_key
end

def test_ancestry_column_validation_string_key_fails
assert true, "this runs if materialized path"
return if AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model(:id => :string, :primary_key_format => /[a-z]/) do |model|
Expand All @@ -89,6 +94,7 @@ def test_ancestry_column_validation_string_key_fails
end

def test_ancestry_validation_exclude_self
assert true, "this runs if materialized path"
return if AncestryTestDatabase.materialized_path2?

AncestryTestDatabase.with_model do |model|
Expand Down
2 changes: 1 addition & 1 deletion test/concerns/scopes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def test_create_children_from_root
AncestryTestDatabase.with_model(:extra_columns => {:name => :string}) do |model|
root = model.create
record = root.children.create
# this should not throw an exception
record.reload.parent.children.find_or_create_by! :name => 'abc'
assert true, "this should not throw an exception"
end
end
end
1 change: 1 addition & 0 deletions test/concerns/tree_navigation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def test_node_in_database_children
# please create PR or issue if you have a better idea
def test_node_before_last_save
AncestryTestDatabase.with_model do |model|
assert true, "this runs for integer primary keys"
skip "only written for integer keys" unless model.primary_key_is_an_integer?
model.delete_all

Expand Down

0 comments on commit 4d26788

Please sign in to comment.