mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Properly track changes in code attribute
If the code was initially nil, some value is added, and then removed, we would not detect that the code has not actually changed.
This commit is contained in:
@@ -4,15 +4,16 @@ angular.module("admin.indexUtils").directive "objForUpdate", (switchClass, pendi
|
||||
type: "@objForUpdate"
|
||||
attr: "@attrForUpdate"
|
||||
link: (scope, element, attrs) ->
|
||||
scope.savedValue = scope.object()[scope.attr]
|
||||
scope.savedValue = scope.object()[scope.attr] || ""
|
||||
|
||||
scope.$watch "object().#{scope.attr}", (value) ->
|
||||
if value == scope.savedValue
|
||||
strValue = value || ""
|
||||
if strValue == scope.savedValue
|
||||
pendingChanges.remove(scope.object().id, scope.attr)
|
||||
scope.clear()
|
||||
else
|
||||
scope.pending()
|
||||
addPendingChange(scope.attr, value ? "")
|
||||
addPendingChange(scope.attr, strValue)
|
||||
|
||||
scope.reset = (value) ->
|
||||
scope.savedValue = value
|
||||
|
||||
@@ -268,6 +268,10 @@ RSpec.describe 'Customers' do
|
||||
expect(page).to have_content 'You have unsaved changes'
|
||||
within("tr#c_#{customer1.id}") { fill_in "first_name", with: "John" }
|
||||
expect(page).not_to have_content 'You have unsaved changes'
|
||||
within("tr#c_#{customer1.id}") { fill_in "code", with: "new-customer-code" }
|
||||
expect(page).to have_content 'You have unsaved changes'
|
||||
within("tr#c_#{customer1.id}") { fill_in "code", with: "" }
|
||||
expect(page).not_to have_content 'You have unsaved changes'
|
||||
|
||||
within "tr#c_#{customer1.id}" do
|
||||
expect(find_field('first_name').value).to eq 'John'
|
||||
|
||||
Reference in New Issue
Block a user