Skip to content

Commit

Permalink
fix: Test fixes (#426)
Browse files Browse the repository at this point in the history
* 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 <module:TagExamples>'

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
  • Loading branch information
jkraemer authored Jan 16, 2024
1 parent 2b1f088 commit cd2fac1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
46 changes: 23 additions & 23 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# 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'
t.integer 'sort_order'
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'
Expand All @@ -24,115 +24,115 @@
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

add_index 'tag_hierarchies', %i[ancestor_id descendant_id generations], unique: true,
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'
t.string 'description'
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
Expand Down
1 change: 1 addition & 0 deletions test/closure_tree/tag_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'test_helper'
require 'support/tag_examples'

describe Tag do
include TagExamples
Expand Down
1 change: 1 addition & 0 deletions test/closure_tree/uuid_tag_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'test_helper'
require 'support/tag_examples'

describe UUIDTag do
include TagExamples
Expand Down
5 changes: 2 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -67,4 +67,3 @@ class Spec
require 'closure_tree'
require_relative '../spec/support/schema'
require_relative '../spec/support/models'
require 'support/tag_examples'

0 comments on commit cd2fac1

Please sign in to comment.