From cb6b1f2dd0c3fe2c94f0f7b1cd409c08451ec091 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 10 Feb 2026 10:52:35 +1100 Subject: [PATCH] Link producer enterprise to credit payment method --- app/models/enterprise.rb | 5 +++++ spec/models/enterprise_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index edc872338f..4f5baaf49e 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -148,6 +148,7 @@ class Enterprise < ApplicationRecord after_create :set_default_contact after_create :relate_to_owners_enterprises + after_create :add_credit_payment_method after_rollback :restore_permalink after_touch :touch_distributors @@ -643,4 +644,8 @@ class Enterprise < ApplicationRecord where.not(enterprises: { id: }). update_all(updated_at: Time.zone.now) end + + def add_credit_payment_method + CreditPaymentMethod::LinkerService.link(enterprise: self) if is_distributor + end end diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index f31721c589..947c5be95d 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -490,6 +490,22 @@ RSpec.describe Enterprise do .and change { distributor2.reload.updated_at } end end + + describe "add_credit_payment_method" do + it "links credit payment method to the enterprise" do + expect(CreditPaymentMethod::LinkerService).to receive(:link) + + create(:distributor_enterprise) + end + + context "when not a distributor" do + it "doesn't link credit payment method" do + expect(CreditPaymentMethod::LinkerService).not_to receive(:link) + + create(:supplier_enterprise) + end + end + end end describe "scopes" do