Link producer enterprise to credit payment method

This commit is contained in:
Gaetan Craig-Riou
2026-02-10 10:52:35 +11:00
parent 130401263a
commit cb6b1f2dd0
2 changed files with 21 additions and 0 deletions

View File

@@ -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

View File

@@ -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