mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Link producer enterprise to credit payment method
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user