fix specs, use relation hooks

This commit is contained in:
Dylan Knutson
2025-07-15 06:16:01 +00:00
parent fd91328334
commit 239afcbadb
6 changed files with 190 additions and 54 deletions

View File

@@ -293,15 +293,14 @@ RSpec.describe HasAuxTable do
expect(car_names).to eq(["Tesla Model 3", "Toyota Prius"])
end
it "doesn't add joins for queries without auxiliary columns",
skip: true do
it "doesn't add joins for queries without auxiliary columns" do
toyota_cars = Car.where(name: "Toyota Prius")
expect(toyota_cars.length).to eq(1)
expect(toyota_cars.first.name).to eq("Toyota Prius")
expect(toyota_cars.first.fuel_type).to eq("hybrid")
end
it "works with chained where clauses", skip: true do
it "works with chained where clauses" do
# Chain where clauses with auxiliary columns
efficient_cars = Car.where(fuel_type: "hybrid").where(engine_size: 1.8)
@@ -529,7 +528,7 @@ RSpec.describe HasAuxTable do
)
end
it "works with empty where conditions", skip: true do
it "works with empty where conditions" do
# Empty where should not cause issues
cars = Car.where({})
expect(cars.length).to eq(3)
@@ -629,7 +628,7 @@ RSpec.describe HasAuxTable do
end
describe "nested associations" do
it "can create a driver through the association", skip: true do
it "can create a driver through the association" do
driver = @car.drivers.create!(name: "John Doe")
expect(driver.car).to eq(@car)
expect(driver.car_id).to eq(@car.id)
@@ -637,7 +636,7 @@ RSpec.describe HasAuxTable do
expect(driver.car.engine_size).to eq(1.5)
end
it "can create a driver directly", skip: true do
it "can create a driver directly" do
driver = Driver.create!(car: @car, name: "John Doe")
expect(driver.car).to eq(@car)
expect(driver.car_id).to eq(@car.id)
@@ -645,13 +644,13 @@ RSpec.describe HasAuxTable do
expect(driver.car.engine_size).to eq(1.5)
end
it "can be accessed through the association", skip: true do
it "can be accessed through the association" do
driver = @car.drivers.create!(name: "John Doe")
expect(@car.drivers).to eq([driver])
end
it "can be destroyed through the association", skip: true do
driver = @car.drivers.build(name: "John Doe")
it "can be destroyed through the association" do
driver = @car.drivers.create!(name: "John Doe")
expect { driver.destroy }.to change { @car.drivers.count }.by(-1)
end
end