find_by through collection proxy
This commit is contained in:
@@ -305,6 +305,12 @@ RSpec.describe HasAuxTable do
|
||||
found_car = Car.find_by(fuel_type: "diesel")
|
||||
expect(found_car).to be_nil
|
||||
end
|
||||
|
||||
it "works with find_by!" do
|
||||
expect { Car.find_by!(fuel_type: "diesel") }.to raise_error(
|
||||
ActiveRecord::RecordNotFound
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "where method with automatic joins" do
|
||||
@@ -722,6 +728,18 @@ RSpec.describe HasAuxTable do
|
||||
driver = @car.drivers.create!(name: "John Doe")
|
||||
expect { driver.destroy }.to change { @car.reload.drivers.count }.by(-1)
|
||||
end
|
||||
|
||||
it "can be queried through the association" do
|
||||
driver = @car.drivers.create!(name: "John Doe", license_number: 123_456)
|
||||
expect(@car.drivers.where(name: "John Doe")).to eq([driver])
|
||||
|
||||
drivers = @car.drivers
|
||||
d = drivers.find_by!(license_number: 123_456)
|
||||
expect(d.id).to eq(driver.id)
|
||||
|
||||
d = drivers.find_by(license_number: 123_456)
|
||||
expect(d.id).to eq(driver.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
Reference in New Issue
Block a user