Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1f818da

Browse files
committed
fix tests
1 parent c46c513 commit 1f818da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+567
-809
lines changed

‎.github/workflows/ci.yml‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,22 @@ jobs:
3838
fail-fast: false
3939
matrix:
4040
ruby:
41-
- '3.3'
41+
- '3.4'
42+
- 'jruby'
43+
- 'truffleruby'
4244
rails:
43-
- activerecord_8.0
44-
- activerecord_7.2
45-
- activerecord_7.1
46-
- activerecord_edge
47-
adapter:
48-
- 'sqlite3:///:memory:'
49-
- mysql2://root:root@0/closure_tree_test
50-
- postgres://closure_tree:closure_tree@0/closure_tree_test
45+
- '8.0'
46+
- '7.2'
47+
- '7.1'
48+
exclude:
49+
# JRuby doesn't support Rails 8.0 yet
50+
- ruby: 'jruby'
51+
rails: '7.2'
52+
- ruby: 'jruby'
53+
rails: '8.0'
54+
# TruffleRuby also has compatibility issues with Rails 8.0
55+
- ruby: 'truffleruby'
56+
rails: '8.0'
5157

5258
steps:
5359
- name: Checkout
@@ -60,14 +66,15 @@ jobs:
6066
bundler-cache: true
6167
rubygems: latest
6268
env:
63-
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
69+
RAILS_VERSION: ${{ matrix.rails }}
6470
RAILS_ENV: test
6571

6672
- name: Test
6773
env:
6874
RAILS_ENV: test
6975
RAILS_VERSION: ${{ matrix.rails }}
70-
DB_ADAPTER: ${{ matrix.adapter }}
71-
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
76+
DATABASE_URL_PG: postgres://postgres:postgres@127.0.0.1:5432/closure_tree_test
77+
DATABASE_URL_MYSQL: mysql2://root:root@127.0.0.1:3306/closure_tree_test
78+
DATABASE_URL_SQLITE3: 'sqlite3::memory:'
7279
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
73-
run: bin/rake
80+
run: bin/rails test

‎.github/workflows/ci_jruby.yml‎

Lines changed: 0 additions & 69 deletions
This file was deleted.

‎.github/workflows/ci_truffleruby.yml‎

Lines changed: 0 additions & 72 deletions
This file was deleted.

‎Gemfile‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ source 'https://rubygems.org'
44

55
gemspec
66

7-
gem 'with_advisory_lock', github: 'closuretree/with_advisory_lock'
87
gem 'railties'
9-
# Test with ActiveRecord 7.1 directly
10-
gem 'activerecord', '~> 7.1.0'
8+
gem 'with_advisory_lock', github: 'closuretree/with_advisory_lock'
9+
10+
gem 'activerecord', "~> #{ENV['RAILS_VERSION'] || '8.0'}.0"
11+
12+
platforms :ruby, :truffleruby do
13+
# Database adapters
14+
gem 'mysql2'
15+
gem 'pg'
16+
gem 'sqlite3'
17+
end
1118

12-
# Database adapters
13-
gem 'sqlite3'
14-
gem 'pg'
15-
gem 'mysql2'
19+
platform :jruby do
20+
# JRuby-specific gems
21+
gem 'activerecord-jdbcmysql-adapter'
22+
gem 'activerecord-jdbcpostgresql-adapter'
23+
gem 'activerecord-jdbcsqlite3-adapter'
24+
end

‎bin/rails‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4+
# This command will automatically be run when you run "rails" with Rails gems
5+
# installed from the root of your application.
6+
7+
ENGINE_ROOT = File.expand_path('..', __dir__)
48
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
5-
require_relative '../test/dummy/config/boot'
6-
require 'rails/commands'
9+
10+
# Set up gems listed in the Gemfile.
11+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
12+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
13+
14+
require 'rails/all'
15+
require 'rails/engine/commands'
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class LabelOrderValueTest < ActiveSupport::TestCase
6+
def setup
7+
Label.delete_all
8+
LabelHierarchy.delete_all
9+
end
10+
11+
test "should set order_value on roots for Label" do
12+
root = Label.create(name: "root")
13+
assert_equal 0, root.order_value
14+
end
15+
16+
test "should set order_value with siblings for Label" do
17+
root = Label.create(name: "root")
18+
a = root.children.create(name: "a")
19+
b = root.children.create(name: "b")
20+
c = root.children.create(name: "c")
21+
22+
assert_equal 0, a.order_value
23+
assert_equal 1, b.order_value
24+
assert_equal 2, c.order_value
25+
end
26+
27+
test "should reset order_value when a node is moved to another location for Label" do
28+
root = Label.create(name: "root")
29+
a = root.children.create(name: "a")
30+
b = root.children.create(name: "b")
31+
c = root.children.create(name: "c")
32+
33+
root2 = Label.create(name: "root2")
34+
root2.add_child b
35+
36+
assert_equal 0, a.order_value
37+
assert_equal 0, b.order_value
38+
assert_equal 1, c.reload.order_value
39+
end
40+
41+
test "should set order_value on roots for LabelWithoutRootOrdering" do
42+
root = LabelWithoutRootOrdering.create(name: "root")
43+
assert_nil root.order_value
44+
end
45+
46+
test "should set order_value with siblings for LabelWithoutRootOrdering" do
47+
root = LabelWithoutRootOrdering.create(name: "root")
48+
a = root.children.create(name: "a")
49+
b = root.children.create(name: "b")
50+
c = root.children.create(name: "c")
51+
52+
assert_equal 0, a.order_value
53+
assert_equal 1, b.order_value
54+
assert_equal 2, c.order_value
55+
end
56+
end

‎test/closure_tree/label_test.rb‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
require "test_helper"
44

55
module CorrectOrderValue
6-
def self.shared_examples(&block)
6+
def self.shared_examples(model,expected_root_order_value)
77
describe "correct order_value" do
88
before do
9-
instance_exec(&block)
9+
@model = model
10+
@expected_root_order_value = expected_root_order_value
11+
# Clean up any existing data
12+
@model.delete_all
13+
@model.hierarchy_class.delete_all
1014
@root = @model.create(name: "root")
1115
@a, @b, @c = %w[a b c].map { |n| @root.children.create(name: n) }
1216
end
@@ -111,6 +115,11 @@ def create_preorder_tree(suffix = "")
111115
end
112116

113117
describe "roots" do
118+
before do
119+
Label.delete_all
120+
Label.hierarchy_class.delete_all
121+
end
122+
114123
it "sorts alphabetically" do
115124
expected = (0..10).to_a
116125
expected.shuffle.each do |ea|
@@ -471,17 +480,11 @@ def roots_name_and_order
471480

472481
describe "order_value must be set" do
473482
describe "with normal model" do
474-
CorrectOrderValue.shared_examples do
475-
@model = Label
476-
@expected_root_order_value = 0
477-
end
483+
CorrectOrderValue.shared_examples(Label, 0)
478484
end
479485

480486
describe "without root ordering" do
481-
CorrectOrderValue.shared_examples do
482-
@model = LabelWithoutRootOrdering
483-
@expected_root_order_value = nil
484-
end
487+
CorrectOrderValue.shared_examples(LabelWithoutRootOrdering, nil)
485488
end
486489
end
487490

‎test/closure_tree/matcher_test.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MatcherTest < ActiveSupport::TestCase
1313
end
1414

1515
test "be_a_closure_tree matcher" do
16-
assert_closure_tree UUIDTag
16+
assert_closure_tree UuidTag
1717
assert_closure_tree User
1818
assert_closure_tree Label, ordered: true
1919
assert_closure_tree Metal, ordered: :sort_order
@@ -23,7 +23,7 @@ class MatcherTest < ActiveSupport::TestCase
2323

2424
test "ordered option" do
2525
assert_closure_tree Label, ordered: true
26-
assert_closure_tree UUIDTag, ordered: true
26+
assert_closure_tree UuidTag, ordered: true
2727
assert_closure_tree Metal, ordered: :sort_order
2828
end
2929

‎test/closure_tree/user_test.rb‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
require "test_helper"
44

55
describe "empty db" do
6+
before do
7+
User.delete_all
8+
User.hierarchy_class.delete_all
9+
end
10+
611
describe "empty db" do
712
it "should return no entities" do
813
assert User.roots.empty?
@@ -79,8 +84,8 @@
7984
end
8085

8186
def assert_mid_and_leaf_remain
82-
assert ReferralHierarchy.where(ancestor_id: @root_id).empty?
83-
assert ReferralHierarchy.where(descendant_id: @root_id).empty?
87+
assert User.hierarchy_class.where(ancestor_id: @root_id).empty?
88+
assert User.hierarchy_class.where(descendant_id: @root_id).empty?
8489
assert_equal %w[matt@t.co], @mid.ancestry_path
8590
assert_equal %w[matt@t.co james@t.co], @leaf.ancestry_path
8691
assert_equal [@mid, @leaf].sort, @mid.self_and_descendants.to_a.sort

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /