Skip to content

Commit abeeef2

Browse files
committed
Add test suite and CI configuration
- Add test suite structured so that you can run bundle exec rake test - Add functional, integration, and unit tests with some tests stubbed out for future reference - Add CI workflow configuration for automated testing
1 parent 6c493c5 commit abeeef2

17 files changed

+1043
-93
lines changed

test/.DS_Store

6 KB
Binary file not shown.

test/cases/finder_test.rb

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

test/cases/helper.rb

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

test/functional/finder_test.rb

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# # frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
require "models/author"
6+
require "models/post"
7+
8+
class FinderTest < TestCase
9+
fixtures :posts
10+
11+
def setup
12+
# Debug fixture loading
13+
puts "=== FinderTest Setup Debug ==="
14+
puts "Ruby version: #{RUBY_VERSION}"
15+
puts "ActiveRecord version: #{ActiveRecord.version}"
16+
puts "Posts table exists: #{ActiveRecord::Base.connection.table_exists?('posts')}"
17+
puts "Posts count: #{Post.count}"
18+
19+
if Post.count > 0
20+
puts "First post: #{Post.first&.attributes}"
21+
puts "All posts: #{Post.all.map(&:attributes)}"
22+
else
23+
puts "No posts found - checking fixture loading..."
24+
puts "Fixture paths: #{self.class.fixture_paths}"
25+
puts "Loaded fixtures: #{loaded_fixtures.keys}" if respond_to?(:loaded_fixtures)
26+
27+
# Try to manually check table contents
28+
begin
29+
result = ActiveRecord::Base.connection.execute("SELECT COUNT(*) as count FROM posts")
30+
puts "Direct SQL count: #{result.first['count'] rescue 'error'}"
31+
32+
result = ActiveRecord::Base.connection.execute("SELECT * FROM posts LIMIT 3")
33+
puts "Direct SQL results: #{result.to_a rescue 'error'}"
34+
rescue => e
35+
puts "SQL error: #{e.message}"
36+
end
37+
38+
# Try to reload fixtures manually
39+
begin
40+
puts "Attempting to reload fixtures..."
41+
self.class.fixture_paths.each do |fixture_path|
42+
puts "Fixture path: #{fixture_path}"
43+
puts "Posts fixture exists: #{File.exist?(File.join(fixture_path, 'posts.yml'))}"
44+
end
45+
46+
# Force fixture reload
47+
ActiveRecord::FixtureSet.reset_cache
48+
setup_fixtures
49+
puts "After manual setup - Posts count: #{Post.count}"
50+
rescue => e
51+
puts "Fixture reload error: #{e.message}"
52+
puts "Backtrace: #{e.backtrace.first(3).join(', ')}"
53+
end
54+
end
55+
puts "=========================="
56+
end
57+
58+
def test_find
59+
assert_equal(posts(:first).title, Post.find(1).title)
60+
end
61+
62+
def skip_test_bigint
63+
# TODO: 多分だけど、DuckDBで返ってきたIDの値が、見た目上はInteger型だけど、実際は違う??どっかでCastしないといけない??
64+
# Primary KeyをBigIntにすると、in_order_ofで、うまく結果が返ってこない。これは、多分IntとBigIntが違うからだと思う。
65+
66+
records = Post.where(enabled: true).where(id: [1, 2]).records
67+
p h = records.index_by(&:id)
68+
p h.keys
69+
p Post.find(h.keys)
70+
p [1, 2]
71+
p Post.find([1, 2])
72+
p h.keys.equal? [1, 2]
73+
p h.keys.map { |v| v.object_id }
74+
p [1, 2].map { |v| v.object_id }
75+
p h.keys.map { |v| v.class.ancestors }
76+
p [1, 2].map { |v| v.class.ancestors }
77+
end
78+
79+
def test_find_where
80+
records = Post.where(enabled: true).find([2, 1, 3])
81+
assert_equal 3, records.size
82+
assert_equal posts(:second).title, records[0].title
83+
assert_equal posts(:first).title, records[1].title
84+
assert_equal posts(:third).title, records[2].title
85+
end
86+
87+
def test_exists
88+
assert_equal true, Post.exists?(1)
89+
assert_equal true, Post.exists?("1")
90+
assert_equal true, Post.exists?(title: Post.find(1).title)
91+
assert_equal true, Post.exists?(id: [1, 9999])
92+
93+
assert_equal false, Post.exists?(45)
94+
assert_equal false, Post.exists?(9999999999999999999999999999999)
95+
assert_equal false, Post.exists?(Post.new.id)
96+
end
97+
end

test/cases/models_test.rb renamed to test/functional/models_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# frozen_string_literal: true
1+
# # frozen_string_literal: true
22

3-
require "cases/helper"
3+
require "test_helper"
44
require "models/author"
55
require "models/post"
66

test/cases/persistence_test.rb renamed to test/functional/persistence_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# frozen_string_literal: true
1+
# # frozen_string_literal: true
22

3-
require "cases/helper"
3+
require "test_helper"
44
require "models/author"
55
require "models/post"
66

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "models/author"
5+
require "models/post"
6+
7+
class AssociationsTest < TestCase
8+
fixtures :authors, :posts
9+
10+
def test_has_many_association
11+
# TODO: Test author.posts returns collection of posts
12+
skip "Association tests not implemented yet"
13+
end
14+
15+
def test_belongs_to_association
16+
# TODO: Test post.author returns the associated author
17+
skip "Association tests not implemented yet"
18+
end
19+
20+
def test_association_create
21+
# TODO: Test author.posts.create(...) creates associated record
22+
skip "Association tests not implemented yet"
23+
end
24+
25+
def test_association_build
26+
# TODO: Test author.posts.build(...) builds associated record
27+
skip "Association tests not implemented yet"
28+
end
29+
30+
def test_association_destroy
31+
# TODO: Test destroying associated records
32+
skip "Association tests not implemented yet"
33+
end
34+
35+
def test_association_dependent_destroy
36+
# TODO: Test has_many :posts, dependent: :destroy
37+
skip "Association tests not implemented yet"
38+
end
39+
40+
def test_association_counter_cache
41+
# TODO: Test counter_cache functionality
42+
skip "Association tests not implemented yet"
43+
end
44+
45+
def test_association_includes
46+
# TODO: Test Post.includes(:author) to prevent N+1 queries
47+
skip "Association tests not implemented yet"
48+
end
49+
50+
def test_association_joins
51+
# TODO: Test Post.joins(:author) for inner joins
52+
skip "Association tests not implemented yet"
53+
end
54+
55+
def test_association_conditions
56+
# TODO: Test association with where conditions
57+
skip "Association tests not implemented yet"
58+
end
59+
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class MigrationsTest < TestCase
6+
def setup
7+
@migration_dir = 'test/tmp/migrations'
8+
FileUtils.mkdir_p(@migration_dir)
9+
end
10+
11+
def teardown
12+
FileUtils.rm_rf(@migration_dir) if Dir.exist?(@migration_dir)
13+
end
14+
15+
def test_create_table_migration
16+
# TODO: Test creating tables through migrations
17+
skip "Migration tests not implemented yet"
18+
end
19+
20+
def test_add_column_migration
21+
# TODO: Test adding columns to existing tables
22+
skip "Migration tests not implemented yet"
23+
end
24+
25+
def test_remove_column_migration
26+
# TODO: Test removing columns from existing tables
27+
skip "Migration tests not implemented yet"
28+
end
29+
30+
def test_migration_rollback
31+
# TODO: Test rolling back migrations
32+
skip "Migration tests not implemented yet"
33+
end
34+
35+
def test_migration_versioning
36+
# TODO: Test schema_migrations table and version tracking
37+
skip "Migration tests not implemented yet"
38+
end
39+
40+
def test_change_column_migration
41+
# TODO: Test changing column types/properties
42+
skip "Migration tests not implemented yet"
43+
end
44+
45+
def test_add_index_migration
46+
# TODO: Test adding indexes through migrations
47+
skip "Migration tests not implemented yet"
48+
end
49+
50+
def test_remove_index_migration
51+
# TODO: Test removing indexes through migrations
52+
skip "Migration tests not implemented yet"
53+
end
54+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "models/author"
5+
require "models/post"
6+
7+
class ValidationsTest < TestCase
8+
fixtures :authors, :posts
9+
10+
def test_presence_validation
11+
# TODO: Test validates :name, presence: true
12+
skip "Validation tests not implemented yet"
13+
end
14+
15+
def test_uniqueness_validation
16+
# TODO: Test validates :email, uniqueness: true
17+
skip "Validation tests not implemented yet"
18+
end
19+
20+
def test_length_validation
21+
# TODO: Test validates :name, length: { maximum: 50 }
22+
skip "Validation tests not implemented yet"
23+
end
24+
25+
def test_numericality_validation
26+
# TODO: Test validates :count, numericality: { greater_than: 0 }
27+
skip "Validation tests not implemented yet"
28+
end
29+
30+
def test_format_validation
31+
# TODO: Test validates :email, format: { with: email_regex }
32+
skip "Validation tests not implemented yet"
33+
end
34+
35+
def test_inclusion_validation
36+
# TODO: Test validates :status, inclusion: { in: %w[active inactive] }
37+
skip "Validation tests not implemented yet"
38+
end
39+
40+
def test_custom_validation
41+
# TODO: Test custom validation methods
42+
skip "Validation tests not implemented yet"
43+
end
44+
45+
def test_validation_callbacks
46+
# TODO: Test before_validation, after_validation callbacks
47+
skip "Validation tests not implemented yet"
48+
end
49+
end

test/test.duckdb

5.01 MB
Binary file not shown.

0 commit comments

Comments
 (0)