mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Adding logic to SearchController#customer_addresses for case when customer is not found
This commit is contained in:
@@ -37,8 +37,8 @@ Spree::Admin::SearchController.class_eval do
|
||||
alias_method_chain :users, :ams
|
||||
|
||||
def customer_addresses
|
||||
customer = Customer.of(spree_current_user.enterprises).find(params[:customer_id])
|
||||
redirect_to :unauthorised unless customer.present?
|
||||
customer = Customer.of(spree_current_user.enterprises).find_by_id(params[:customer_id])
|
||||
return redirect_to :unauthorized unless customer.present?
|
||||
|
||||
finder = OpenFoodNetwork::AddressFinder.new(customer, customer.email)
|
||||
bill_address = Api::AddressSerializer.new(finder.bill_address).serializable_hash
|
||||
|
||||
@@ -100,6 +100,15 @@ describe Spree::Admin::SearchController, type: :controller do
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "when no customer with a matching id exists" do
|
||||
before { params.merge!({customer_id: 1}) }
|
||||
|
||||
it "redirects to unauthorised" do
|
||||
spree_get :customer_addresses, params
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user