mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Merge pull request #8926 from mkllnk/8925-invalid-param
Gracefully handle admin UI failure on updating enterprise notifications
This commit is contained in:
@@ -234,8 +234,10 @@ module Admin
|
||||
end
|
||||
|
||||
def update_enterprise_notifications
|
||||
if params.key? :receives_notifications
|
||||
@enterprise.update_contact params[:receives_notifications]
|
||||
user_id = params[:receives_notifications].to_i
|
||||
|
||||
if user_id.positive? && @enterprise.user_ids.include?(user_id)
|
||||
@enterprise.update_contact(user_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -162,6 +162,28 @@ describe Admin::EnterprisesController, type: :controller do
|
||||
expect(distributor.users).to_not include user
|
||||
end
|
||||
|
||||
it "updates the contact for notifications" do
|
||||
allow(controller).to receive_messages spree_current_user: distributor_manager
|
||||
params = {
|
||||
id: distributor,
|
||||
receives_notifications: distributor_manager.id,
|
||||
}
|
||||
|
||||
expect { spree_post :update, params }.
|
||||
to change { distributor.contact }.to(distributor_manager)
|
||||
end
|
||||
|
||||
it "updates the contact for notifications" do
|
||||
allow(controller).to receive_messages spree_current_user: distributor_manager
|
||||
params = {
|
||||
id: distributor,
|
||||
receives_notifications: "? object:null ?",
|
||||
}
|
||||
|
||||
expect { spree_post :update, params }.
|
||||
to_not change { distributor.contact }
|
||||
end
|
||||
|
||||
it "updates enterprise preferences" do
|
||||
allow(controller).to receive_messages spree_current_user: distributor_manager
|
||||
update_params = { id: distributor,
|
||||
|
||||
Reference in New Issue
Block a user