From 15d2122ff727edaf9a377c5fd41be1a2abb2bf2b Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Wed, 12 Nov 2025 16:02:52 +0100 Subject: [PATCH] Fix failing spec There is a unique constraint on `user_preference.user_id`, so it raised an error when trying to create a `UserPreference` for `current_user` as it already has one. --- .../update_service_integration_spec.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/spec/services/user_preferences/update_service_integration_spec.rb b/spec/services/user_preferences/update_service_integration_spec.rb index 1fc1bf3ec1f..4493078cd8d 100644 --- a/spec/services/user_preferences/update_service_integration_spec.rb +++ b/spec/services/user_preferences/update_service_integration_spec.rb @@ -36,24 +36,17 @@ RSpec.describe UserPreferences::UpdateService, "integration", type: :model do u.pref.save end end - shared_let(:preferences) do - create(:user_preference, user: current_user) - end + shared_let(:preferences) { current_user.preference } let(:instance) { described_class.new(user: current_user, model: preferences) } let(:attributes) { {} } - let(:service_result) do - instance - .call(attributes) - end - - let(:updated_pref) do - service_result.result - end describe "notification_settings" do - subject { updated_pref.notification_settings } + subject do + service_result = instance.call(attributes) + service_result.result.notification_settings + end context "with a partial update" do let(:attributes) do @@ -101,7 +94,7 @@ RSpec.describe UserPreferences::UpdateService, "integration", type: :model do expect(subject.first).to eq(default_ian.reload) expect(current_user.notification_settings.count).to eq(1) - expect { default_ian.reload }.not_to raise_error(ActiveRecord::RecordNotFound) + expect { default_ian.reload }.not_to raise_error end end