Add missing ability for credit customer

Fix the specs to use a non super admin user, so it should catch missing
ability in the future.
This commit is contained in:
Gaetan Craig-Riou
2026-03-11 15:34:27 +11:00
parent dff9d7ede6
commit c134bbf49b
3 changed files with 10 additions and 6 deletions

View File

@@ -315,7 +315,8 @@ module Spree
can [:create], Spree::Order
can [:read, :update], Spree::Order do |order|
# Spree::Admin::PaymentController need to load the order to credit_customer
can [:read, :update, :credit_customer], Spree::Order do |order|
# We allow editing orders with a nil distributor as this state occurs
# during the order creation process from the admin backend
order.distributor.nil? ||
@@ -367,7 +368,7 @@ module Spree
can_edit_as_producer(shipment.order, user)
end
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Payment
can [:admin, :index, :read, :create, :edit, :update, :fire, :credit_customer], Spree::Payment
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Adjustment
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::ReturnAuthorization
can [:destroy], Spree::Adjustment do |adjustment|

View File

@@ -634,6 +634,11 @@ RSpec.describe Spree::Ability do
for: Spree::Payment)
end
it "is able to credit a customer" do
is_expected.to have_ability([:credit_customer], for: Spree::Order)
is_expected.to have_ability([:credit_customer], for: Spree::Payment)
end
it "should be able to read/write Shipments on a product" do
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
for: Spree::Shipment)

View File

@@ -1,11 +1,11 @@
# frozen_string_literal: true
RSpec.describe Spree::Admin::PaymentsController do
let(:user) { order.user }
let(:order) { create(:completed_order_with_fees) }
let(:user) { create(:enterprise_user, enterprises: [order.distributor]) }
before do
sign_in create(:admin_user)
sign_in user
end
describe "POST /admin/orders/:order_number/payments.json" do
@@ -369,8 +369,6 @@ RSpec.describe Spree::Admin::PaymentsController do
before do
allow(customer_credit_service_mock).to receive(:apply)
# order setup will call Orders::CustomerCreditService once
expect(Orders::CustomerCreditService).to receive(:new).and_call_original
expect(Orders::CustomerCreditService).to receive(:new).and_return(
customer_credit_service_mock
)