Adding logic to SearchController#customer_addresses for case when customer is not found

This commit is contained in:
Rob Harrington
2017-01-25 16:09:24 +11:00
parent 6ac49a7694
commit 9137f68a57
2 changed files with 11 additions and 2 deletions

View File

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

View File

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