From 6c439608f05de4d99a8e2d9745fd9dac5b874538 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Fri, 12 Nov 2010 17:04:15 -0600 Subject: [PATCH] started specs for AspectEdit.deletePersonFromAspect --- public/javascripts/aspect-edit.js | 10 +++++++--- spec/javascripts/aspect-edit-spec.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) 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() {