diff --git a/app/assets/javascripts/admin/index_utils/directives/obj_for_update.js.coffee b/app/assets/javascripts/admin/index_utils/directives/obj_for_update.js.coffee index e9da4c19d5..f170d92437 100644 --- a/app/assets/javascripts/admin/index_utils/directives/obj_for_update.js.coffee +++ b/app/assets/javascripts/admin/index_utils/directives/obj_for_update.js.coffee @@ -30,21 +30,24 @@ angular.module("admin.indexUtils").directive "objForUpdate", (switchClass, pendi scope.clear = -> switchClass( element, "", ["update-pending", "update-error", "update-success"], false ) - # In the particular case of a list of customer filtered by a tag, we want to make sure the - # tag is removed when deleting the tag the list is filtered by. - # As the list is filter by tag, deleting the tag will remove the customer entry, thus + # When a list of customer is filtered and we removed the "filtered value" from a customer, we + # want to make sure the customer is updated. IE. filtering by tag, and removing said tag. + # Deleting the "filtered value" from a customer will remove the customer entry, thus # removing "objForUpdate" directive from the active scope. That means $watch won't pick up - # the tag_list changed. - # To ensure the tag is still deleted, we check on the $destroy event to see if the tag_list has - # changed, if so we queue up deleting the tag. + # the attribute changed. + # 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) -> - return if scope.attr != 'tag_list' + # No update + return if scope.object()[scope.attr] is scope.savedValue - # No tag has been deleted - return if scope.object()['tag_list'] == scope.savedValue + # 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"] = "" - # Queuing up change to delete tag - addPendingChange('tag_list', scope.object()['tag_list']) + # Queuing up change + addPendingChange(scope.attr, scope.object()[scope.attr]) # private diff --git a/spec/system/admin/customers_spec.rb b/spec/system/admin/customers_spec.rb index e50c0c71db..22b6125732 100644 --- a/spec/system/admin/customers_spec.rb +++ b/spec/system/admin/customers_spec.rb @@ -205,7 +205,7 @@ describe 'Customers' do end context "when updating code" do - pending "allows user to save changes" do + it "allows user to save changes" do fill_in "code", with: "" expect(page).not_to have_content("12345")