mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
Properly handle changes in code attribute when a customer is deleted
Previously, `null` and empty value would be confused when a customer is removed, resulting in incorrect pending changes being added, and thus a "You have unsaved changes" message getting displayed and the save button not getting disabled.
This commit is contained in:
@@ -38,16 +38,13 @@ angular.module("admin.indexUtils").directive "objForUpdate", (switchClass, pendi
|
||||
# To ensure the customer is still updated, we check on the $destroy event to see if
|
||||
# the attribute has changed, if so we queue up the change.
|
||||
scope.$on '$destroy', (value) ->
|
||||
# No update
|
||||
return if scope.object()[scope.attr] is scope.savedValue
|
||||
currentValue = scope.object()[scope.attr] || ""
|
||||
|
||||
# For some reason the code attribute is removed from the object when cleared, so we add
|
||||
# an emptyvalue so it gets updated properly
|
||||
if scope.attr is "code" and scope.object()[scope.attr] is undefined
|
||||
scope.object()["code"] = ""
|
||||
# No update
|
||||
return if currentValue is scope.savedValue
|
||||
|
||||
# Queuing up change
|
||||
addPendingChange(scope.attr, scope.object()[scope.attr])
|
||||
addPendingChange(scope.attr, currentValue)
|
||||
|
||||
# private
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ RSpec.describe 'Customers' do
|
||||
end
|
||||
end
|
||||
expect(page).not_to have_selector "tr#c_#{customer2.id}"
|
||||
expect(page).not_to have_content 'You have unsaved changes'
|
||||
}.to change{ Customer.count }.by(-1)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user