From f02db0e64433cee07cc17473a1dbe42e996446b1 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 16:06:38 +0200 Subject: [PATCH] feat: rename integration_error_detail model to error_detail --- .../{integration_error_detail.rb => error_detail.rb} | 4 ++-- app/models/integrations/base_integration.rb | 2 +- app/models/invoice.rb | 2 +- .../{integration_error_details.rb => error_details.rb} | 4 ++-- spec/models/error_detail_spec.rb | 8 ++++++++ spec/models/integration_error_detail_spec.rb | 8 -------- spec/models/integrations/base_integration_spec.rb | 2 +- spec/models/invoice_spec.rb | 3 +-- 8 files changed, 16 insertions(+), 17 deletions(-) rename app/models/{integration_error_detail.rb => error_detail.rb} (58%) rename spec/factories/{integration_error_details.rb => error_details.rb} (53%) create mode 100644 spec/models/error_detail_spec.rb delete mode 100644 spec/models/integration_error_detail_spec.rb diff --git a/app/models/integration_error_detail.rb b/app/models/error_detail.rb similarity index 58% rename from app/models/integration_error_detail.rb rename to app/models/error_detail.rb index b3c34a956b5f..47d682b29f1b 100644 --- a/app/models/integration_error_detail.rb +++ b/app/models/error_detail.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -class IntegrationErrorDetail < ApplicationRecord +class ErrorDetail < ApplicationRecord include Discard::Model self.discard_column = :deleted_at - belongs_to :error_producer, polymorphic: true + belongs_to :integration, polymorphic: true belongs_to :owner, polymorphic: true end diff --git a/app/models/integrations/base_integration.rb b/app/models/integrations/base_integration.rb index 3a5d4c9c4bc6..15310f5c4ea5 100644 --- a/app/models/integrations/base_integration.rb +++ b/app/models/integrations/base_integration.rb @@ -24,7 +24,7 @@ class BaseIntegration < ApplicationRecord class_name: 'IntegrationCustomers::BaseCustomer', foreign_key: :integration_id, dependent: :destroy - has_many :integration_error_details, as: :error_producer + has_many :error_details, as: :integration validates :code, uniqueness: {scope: :organization_id} validates :name, presence: true diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 64495cf0aef9..1e4467ed9092 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -28,7 +28,7 @@ class Invoice < ApplicationRecord has_many :applied_taxes, class_name: 'Invoice::AppliedTax', dependent: :destroy has_many :taxes, through: :applied_taxes has_many :integration_resources, as: :syncable - has_many :integration_error_details, as: :owner, dependent: :destroy + has_many :error_details, as: :owner, dependent: :destroy has_one_attached :file diff --git a/spec/factories/integration_error_details.rb b/spec/factories/error_details.rb similarity index 53% rename from spec/factories/integration_error_details.rb rename to spec/factories/error_details.rb index 402573b9747f..f41c79d7b266 100644 --- a/spec/factories/integration_error_details.rb +++ b/spec/factories/error_details.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true FactoryBot.define do - factory :integration_error_detail do + factory :error_detail do association :owner, factory: %i[invoice].sample - association :error_producer, factory: :anrok_integration + association :integration, factory: :anrok_integration end end diff --git a/spec/models/error_detail_spec.rb b/spec/models/error_detail_spec.rb new file mode 100644 index 000000000000..210a667f4bfe --- /dev/null +++ b/spec/models/error_detail_spec.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe ErrorDetail, type: :model do + it { is_expected.to belong_to(:owner) } + it { is_expected.to belong_to(:integration).optional } +end diff --git a/spec/models/integration_error_detail_spec.rb b/spec/models/integration_error_detail_spec.rb deleted file mode 100644 index 05f5ae618caa..000000000000 --- a/spec/models/integration_error_detail_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe IntegrationErrorDetail, type: :model do - it { is_expected.to belong_to(:error_producer) } - it { is_expected.to belong_to(:owner) } -end diff --git a/spec/models/integrations/base_integration_spec.rb b/spec/models/integrations/base_integration_spec.rb index f2a655863841..e5c7826a10c7 100644 --- a/spec/models/integrations/base_integration_spec.rb +++ b/spec/models/integrations/base_integration_spec.rb @@ -18,7 +18,7 @@ it { is_expected.to have_many(:integration_customers).dependent(:destroy) } it { is_expected.to have_many(:integration_items).dependent(:destroy) } it { is_expected.to have_many(:integration_resources).dependent(:destroy) } - it { is_expected.to have_many(:integration_error_details) } + it { is_expected.to have_many(:error_details) } describe '.secrets_json' do it { expect(integration.secrets_json).to eq(secrets) } diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index c762ac1f9698..901127028587 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -10,8 +10,7 @@ it_behaves_like 'paper_trail traceable' it { is_expected.to have_many(:integration_resources) } - - it { is_expected.to have_many(:integration_error_details) } + it { is_expected.to have_many(:error_details) } describe 'validation' do describe 'of payment dispute lost absence' do