From 05c20b581165fb8bbe81825d796d0f3890fb5c97 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 13 Aug 2025 11:06:55 -0400 Subject: [PATCH] Adding a model association test --- spec/models/test_model_spec.rb | 14 ++++++++++++++ spec/spec_helper.rb | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/models/test_model_spec.rb b/spec/models/test_model_spec.rb index 12d9ec9..bb0245d 100644 --- a/spec/models/test_model_spec.rb +++ b/spec/models/test_model_spec.rb @@ -19,4 +19,18 @@ RSpec.describe(Test) do expect(tst.name).to(eq('Test Test')) end end + + describe 'Test one-to-many association with Hardware' do + it 'Test model has Hardware associated with it.' do + hardware = Hardware.create(name: 'Test Hardware', type: 'gpu') + tst = Test.create(name: 'Test Test', hardware_id: hardware.id) + expect(tst.hardware).to(eq(hardware)) + end + + it 'Test model\'s hardware has name set.' do + hardware = Hardware.create(name: 'Test Hardware', type: 'gpu') + tst = Test.create(name: 'Test Test', hardware_id: hardware.id) + expect(tst.hardware.name).to(eq('Test Hardware')) + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7252aa4..5306757 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,8 +24,7 @@ RSpec.configure do |config| config.include(RSpecMixin) config.before(:suite) do - DatabaseCleaner.strategy = :truncation - DatabaseCleaner.clean_with(:truncation) + DatabaseCleaner.strategy = :transaction end config.around(:each) do |suite|