api without block syntax

This commit is contained in:
Dylan Knutson
2025-07-13 03:36:29 +00:00
parent af97998393
commit e1c1e03e74
4 changed files with 376 additions and 96 deletions

View File

@@ -40,7 +40,7 @@ RSpec.describe ActiveRecord::AuxTable do
include ActiveRecord::AuxTable
self.table_name = "test_classes"
aux_table(:test_table) { |t| t.string :name }
aux_table(:test_table)
end
class Vehicle < ActiveRecord::Base
@@ -49,7 +49,7 @@ RSpec.describe ActiveRecord::AuxTable do
end
class Car < Vehicle
aux_table(:car_aux) { |t| t.string :fuel_type }
aux_table(:car_aux)
end
it "has a version number" do
@@ -86,7 +86,7 @@ RSpec.describe ActiveRecord::AuxTable do
config = TestClass.aux_table_configuration(:test_table)
expect(config).to be_a(ActiveRecord::AuxTable::Configuration)
expect(config.table_name).to eq(:test_table)
expect(config.block).to be_a(Proc)
expect(config.block).to be_nil # No block provided in new API
# Test string to symbol conversion
expect(TestClass.aux_table_configurations.keys).to include(:test_table)
@@ -158,8 +158,11 @@ RSpec.describe ActiveRecord::AuxTable do
}.to raise_error(TypeError)
end
it "raises TypeError when block is missing" do
expect { TestClass.aux_table(:test_table) }.to raise_error(TypeError)
it "works without a block (new simplified API)" do
# Test that the method works without a block (block is now optional)
# We'll test this by checking that block is nil when no block is provided
config = TestClass.aux_table_configuration(:test_table)
expect(config.block).to be_nil
end
it "raises ArgumentError for duplicate table definitions" do
@@ -187,14 +190,6 @@ RSpec.describe ActiveRecord::AuxTable do
expect(config.block).to eq(block)
end
it "initializes columns as empty array" do
expect(config.columns).to eq([])
end
it "initializes indexes as empty array" do
expect(config.indexes).to eq([])
end
it "initializes model_class as nil" do
expect(config.model_class).to be_nil
end
@@ -210,13 +205,7 @@ RSpec.describe ActiveRecord::AuxTable do
config.model_class = model_class
hash = config.to_hash
expect(hash).to include(
table_name: :test_table,
block: block,
columns: [],
indexes: [],
model_class: model_class
)
expect(hash).to include(table_name: :test_table, model_class: model_class)
end
end