From cd2fac1bacd5ed1e177c6939110a34a3030972c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Kr=C3=A4mer?= Date: Wed, 17 Jan 2024 04:01:44 +0800 Subject: [PATCH] fix: Test fixes (#426) * MiniTest -> Minitest * use force: :cascade so tables can be recreated regardless of constraints * require tag_examples module where it's used Otherwise it's specs would be loaded / run out of context leading to many errors like this: 1) Error: TagExamples::from empty db::lowest_common_ancestor#test_0009_is itself for single item: NameError: uninitialized class variable @@described_class in TagExamples Did you mean? describe /closure_tree/test/support/tag_examples.rb:10:in `block (2 levels) in ' when trying to run a single test, i.e. bundle exec rake test TESTOPTS="--seed=10410" TEST=test/closure_tree/parallel_test.rb * revert to :truncation DatabaseCleaner strategy - same as specs, fixes parallel_test --- spec/support/schema.rb | 46 +++++++++++++++--------------- test/closure_tree/tag_test.rb | 1 + test/closure_tree/uuid_tag_test.rb | 1 + test/test_helper.rb | 5 ++-- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 94bdcbf..7d4513b 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true ActiveRecord::Schema.define(version: 0) do - create_table 'tags', force: true do |t| + create_table 'tags', force: :cascade do |t| t.string 'name' t.string 'title' t.references 'parent' @@ -9,13 +9,13 @@ t.timestamps null: false end - create_table 'tag_hierarchies', id: false, force: true do |t| + create_table 'tag_hierarchies', id: false, force: :cascade do |t| t.references 'ancestor', null: false t.references 'descendant', null: false t.integer 'generations', null: false end - create_table 'uuid_tags', id: false, force: true do |t| + create_table 'uuid_tags', id: false, force: :cascade do |t| t.string 'uuid', unique: true t.string 'name' t.string 'title' @@ -24,13 +24,13 @@ t.timestamps null: false end - create_table 'uuid_tag_hierarchies', id: false, force: true do |t| + create_table 'uuid_tag_hierarchies', id: false, force: :cascade do |t| t.string 'ancestor_id', null: false t.string 'descendant_id', null: false t.integer 'generations', null: false end - create_table 'destroyed_tags', force: true do |t| + create_table 'destroyed_tags', force: :cascade do |t| t.string 'name' end @@ -38,81 +38,81 @@ name: 'tag_anc_desc_idx' add_index 'tag_hierarchies', [:descendant_id], name: 'tag_desc_idx' - create_table 'groups', force: true do |t| + create_table 'groups', force: :cascade do |t| t.string 'name', null: false end - create_table 'groupings', force: true do |t| + create_table 'groupings', force: :cascade do |t| t.string 'name', null: false end - create_table 'user_sets', force: true do |t| + create_table 'user_sets', force: :cascade do |t| t.string 'name', null: false end - create_table 'teams', force: true do |t| + create_table 'teams', force: :cascade do |t| t.string 'name', null: false end - create_table 'users', force: true do |t| + create_table 'users', force: :cascade do |t| t.string 'email' t.references 'referrer' t.integer 'group_id' t.timestamps null: false end - create_table 'contracts', force: true do |t| + create_table 'contracts', force: :cascade do |t| t.references 'user', null: false t.references 'contract_type' t.string 'title' end - create_table 'contract_types', force: true do |t| + create_table 'contract_types', force: :cascade do |t| t.string 'name', null: false end - create_table 'referral_hierarchies', id: false, force: true do |t| + create_table 'referral_hierarchies', id: false, force: :cascade do |t| t.references 'ancestor', null: false t.references 'descendant', null: false t.integer 'generations', null: false end - create_table 'labels', force: true do |t| + create_table 'labels', force: :cascade do |t| t.string 'name' t.string 'type' t.integer 'column_whereby_ordering_is_inferred' t.references 'mother' end - create_table 'label_hierarchies', id: false do |t| + create_table 'label_hierarchies', id: false, force: :cascade do |t| t.references 'ancestor', null: false t.references 'descendant', null: false t.integer 'generations', null: false end - create_table 'cuisine_types', force: true do |t| + create_table 'cuisine_types', force: :cascade do |t| t.string 'name' t.references 'parent' end - create_table 'cuisine_type_hierarchies', id: false, force: true do |t| + create_table 'cuisine_type_hierarchies', id: false, force: :cascade do |t| t.references 'ancestor', null: false t.references 'descendant', null: false t.integer 'generations', null: false end - create_table 'namespace_types', force: true do |t| + create_table 'namespace_types', force: :cascade do |t| t.string 'name' t.references 'parent' end - create_table 'namespace_type_hierarchies', id: false, force: true do |t| + create_table 'namespace_type_hierarchies', id: false, force: :cascade do |t| t.references 'ancestor', null: false t.references 'descendant', null: false t.integer 'generations', null: false end - create_table 'metal', force: true do |t| + create_table 'metal', force: :cascade do |t| t.references 'parent' t.string 'metal_type' t.string 'value' @@ -120,19 +120,19 @@ t.integer 'sort_order' end - create_table 'metal_hierarchies', id: false, force: true do |t| + create_table 'metal_hierarchies', id: false, force: :cascade do |t| t.references 'ancestor', null: false t.references 'descendant', null: false t.integer 'generations', null: false end - create_table 'menu_items', force: true do |t| + create_table 'menu_items', force: :cascade do |t| t.string 'name' t.references 'parent' t.timestamps null: false end - create_table 'menu_item_hierarchies', id: false, force: true do |t| + create_table 'menu_item_hierarchies', id: false, force: :cascade do |t| t.references 'ancestor', null: false t.references 'descendant', null: false t.integer 'generations', null: false diff --git a/test/closure_tree/tag_test.rb b/test/closure_tree/tag_test.rb index e43252f..62fde57 100644 --- a/test/closure_tree/tag_test.rb +++ b/test/closure_tree/tag_test.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'test_helper' +require 'support/tag_examples' describe Tag do include TagExamples diff --git a/test/closure_tree/uuid_tag_test.rb b/test/closure_tree/uuid_tag_test.rb index 2ed9eef..e2f2f27 100644 --- a/test/closure_tree/uuid_tag_test.rb +++ b/test/closure_tree/uuid_tag_test.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'test_helper' +require 'support/tag_examples' describe UUIDTag do include TagExamples diff --git a/test/test_helper.rb b/test/test_helper.rb index 94fcfaa..c4ff05b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,9 +43,9 @@ def sqlite? ActiveRecord::Base.connection.recreate_database('closure_tree_test') unless sqlite? puts "Testing with #{env_db} database, ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}" -DatabaseCleaner.strategy = :transaction +DatabaseCleaner.strategy = :truncation -module MiniTest +module Minitest class Spec include QueryCounter @@ -67,4 +67,3 @@ class Spec require 'closure_tree' require_relative '../spec/support/schema' require_relative '../spec/support/models' -require 'support/tag_examples'