namespaced model support

This commit is contained in:
Dylan Knutson
2025-07-16 18:31:28 +00:00
parent fe0f7b9bbe
commit f3990e2654
2 changed files with 38 additions and 1 deletions

View File

@@ -73,6 +73,20 @@ RSpec.describe HasAuxTable do
}
end
end
create_base_table :utensils do |t|
t.string :name
t.string :material
t.timestamps
t.create_aux :fork do |t|
t.integer :num_tongs
end
t.create_aux :spoon do |t|
t.string :curvature
end
end
end
class Vehicle < ActiveRecord::Base
@@ -109,6 +123,20 @@ RSpec.describe HasAuxTable do
aux_table :passenger
belongs_to :boat, inverse_of: :passengers
end
module Kitchen
class Utensil < ActiveRecord::Base
include HasAuxTable
end
class Fork < Utensil
aux_table :fork
end
class Spoon < Utensil
aux_table :spoon
end
end
end
# Car class will be defined after schema setup
@@ -711,4 +739,13 @@ RSpec.describe HasAuxTable do
end
end
end
describe "namespaced models" do
it "works with namespaced models" do
fork1 =
Kitchen::Fork.create!(name: "Fork", material: "metal", num_tongs: 3)
expect(fork1.material).to eq("metal")
expect(fork1.num_tongs).to eq(3)
end
end
end