diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index e4a82a11f..54d8cb028 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -83,9 +83,9 @@ var AspectEdit = { var person_id = person.attr('data-guid'); if( $(".person[data-guid='"+ person_id +"']").length == 1) { - alert("You can not remove the person from the last aspect"); - - } else { + AspectEdit.alertUser("You cannot remove the person from the last aspect"); + } + else { if (!person.hasClass('request')) { $.ajax({ @@ -173,6 +173,10 @@ var AspectEdit = { request_html.replace(/\d+/, old_request_count - 1) ); } + }, + + alertUser: function(message) { + alert(message); } }; diff --git a/spec/javascripts/aspect-edit-spec.js b/spec/javascripts/aspect-edit-spec.js index 04ccbe06b..1ecb5da5f 100644 --- a/spec/javascripts/aspect-edit-spec.js +++ b/spec/javascripts/aspect-edit-spec.js @@ -204,6 +204,18 @@ describe("AspectEdit", function() { }); }); + describe("deletePersonFromAspect", function() { + beforeEach(function() { + spyOn($, 'ajax'); + }); + it("doesn't let you remove the person from the last aspect they're in", function() { + spyOn(AspectEdit, 'alertUser'); + AspectEdit.deletePersonFromAspect($('li.person')); + expect(AspectEdit.alertUser).toHaveBeenCalled(); + expect($.ajax).not.toHaveBeenCalled(); + }); + }); + describe("decrementRequestsCounter", function() { describe("when there is one request", function() { it("removes the counter from the new requests div", function() {