From 26b4a24f11c7fc8f516623791ee2e4dd67d8454d Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Fri, 12 Dec 2025 18:53:26 +0530 Subject: [PATCH] fix: linear and user association spec (#13056) - Linear::CallbacksController: Replace broken `described_class.new`mocking with proper `GlobalConfigService` stubbing and real JWT token generation. The old pattern doesn't work in request specs since Rails instantiates controllers internally. - User associations: Remove `.class_name('Conversation')` assertion that fails intermittently due to enterprise `prepend_mod_with` timing in parallel tests. The class_name is already enforced by Rails at runtime - if wrong, the app would crash immediately. No need to explicitly test for this Fixes https://linear.app/chatwoot/issue/CW-6138/debug-linear-and-user-spec-failures-in-ci --- spec/controllers/linear/callbacks_controller_spec.rb | 10 +++++----- spec/models/user_spec.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/controllers/linear/callbacks_controller_spec.rb b/spec/controllers/linear/callbacks_controller_spec.rb index b3245fbc5..66018776c 100644 --- a/spec/controllers/linear/callbacks_controller_spec.rb +++ b/spec/controllers/linear/callbacks_controller_spec.rb @@ -3,7 +3,8 @@ require 'rails_helper' RSpec.describe Linear::CallbacksController, type: :request do let(:account) { create(:account) } let(:code) { SecureRandom.hex(10) } - let(:state) { SecureRandom.hex(10) } + let(:client_secret) { 'test_linear_secret' } + let(:state) { JWT.encode({ sub: account.id, iat: Time.current.to_i }, client_secret, 'HS256') } let(:linear_redirect_uri) { "#{ENV.fetch('FRONTEND_URL', '')}/app/accounts/#{account.id}/settings/integrations/linear" } describe 'GET /linear/callback' do @@ -19,10 +20,9 @@ RSpec.describe Linear::CallbacksController, type: :request do before do stub_const('ENV', ENV.to_hash.merge('FRONTEND_URL' => 'http://www.example.com')) - - controller = described_class.new - allow(controller).to receive(:verify_linear_token).with(state).and_return(account.id) - allow(described_class).to receive(:new).and_return(controller) + allow(GlobalConfigService).to receive(:load).and_call_original + allow(GlobalConfigService).to receive(:load).with('LINEAR_CLIENT_SECRET', nil).and_return(client_secret) + allow(GlobalConfigService).to receive(:load).with('LINEAR_CLIENT_ID', nil).and_return('test_client_id') end context 'when successful' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 213988a0d..d263708af 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -14,7 +14,7 @@ RSpec.describe User do context 'with associations' do it { is_expected.to have_many(:accounts).through(:account_users) } it { is_expected.to have_many(:account_users) } - it { is_expected.to have_many(:assigned_conversations).class_name('Conversation').dependent(:nullify) } + it { is_expected.to have_many(:assigned_conversations).dependent(:nullify) } it { is_expected.to have_many(:inbox_members).dependent(:destroy_async) } it { is_expected.to have_many(:notification_settings).dependent(:destroy_async) } it { is_expected.to have_many(:messages) }