From 737c812e0808e2ed8a74a3f8ac8d863ae5b6c29b Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Fri, 12 Nov 2010 16:38:02 -0600 Subject: [PATCH 1/5] Specs for AspectEdit.onDeleteRequestSuccess --- spec/javascripts/aspect-edit-spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/javascripts/aspect-edit-spec.js b/spec/javascripts/aspect-edit-spec.js index 94e3460fc..90df6813a 100644 --- a/spec/javascripts/aspect-edit-spec.js +++ b/spec/javascripts/aspect-edit-spec.js @@ -170,6 +170,29 @@ describe("AspectEdit", function() { }); }); }); + + describe("onDeleteRequestSuccess", function() { + beforeEach(function() { + $('#jasmine_content').html( +'
  • ' + +' Alexander Hamiltom' + +'
  • ' + +'' + +'
    Requests (1)
    ' + ); + }); + it("decrements the request counter", function() { + spyOn(AspectEdit, "decrementRequestsCounter"); + AspectEdit.onDeleteRequestSuccess($('li.person')); + expect(AspectEdit.decrementRequestsCounter).toHaveBeenCalled(); + }); + it("takes the request class off the person li", function() { + expect($('li.person')).toHaveClass('request'); + AspectEdit.onDeleteRequestSuccess($('li.person')); + expect($('li.person')).not.toHaveClass('request'); + }); + }); describe("decrementRequestsCounter", function() { describe("when there is one request", function() { From 9586ebb67e7a40472aef5c7cd2287f90ce818c8a Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Fri, 12 Nov 2010 16:44:22 -0600 Subject: [PATCH 2/5] specs for AspectEdit.onMovePersonSuccess --- spec/javascripts/aspect-edit-spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/javascripts/aspect-edit-spec.js b/spec/javascripts/aspect-edit-spec.js index 90df6813a..04ccbe06b 100644 --- a/spec/javascripts/aspect-edit-spec.js +++ b/spec/javascripts/aspect-edit-spec.js @@ -194,6 +194,16 @@ describe("AspectEdit", function() { }); }); + describe("onMovePersonSuccess", function() { + it("updates the data-aspect_id attribute on the person li", function() { + var person = $('li.person'); + var dropzone = $('.dropzone.ui-droppable[data-aspect_id="guid-of-target-aspect"]'); + expect(person.attr("data-aspect_id")).toEqual("guid-of-current-aspect"); + AspectEdit.onMovePersonSuccess(person, dropzone); + expect(person.attr("data-aspect_id")).toEqual("guid-of-target-aspect"); + }); + }); + describe("decrementRequestsCounter", function() { describe("when there is one request", function() { it("removes the counter from the new requests div", function() { From 90474d9acb907b429ce76e5043000afbf942b3ff Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 12 Nov 2010 14:59:04 -0800 Subject: [PATCH 3/5] Attempt to fix websocket bug, default pidfile location --- script/websocket_server.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 518a54872..d72e5ea13 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -43,8 +43,6 @@ end begin EM.run { - - Diaspora::WebSocket.initialize_channels EventMachine::WebSocket.start( @@ -74,7 +72,7 @@ begin Diaspora::WebSocket.unsubscribe(user_id, sid) } } end - PID_FILE = APP_CONFIG[:socket_pidfile] + PID_FILE = APP_CONFIG[:socket_pidfile] ? APP_CONFIG[:socket_pidfile] : 'tmp/diaspora-ws.pid' write_pidfile puts "Websocket server started." process_message From 6c439608f05de4d99a8e2d9745fd9dac5b874538 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Fri, 12 Nov 2010 17:04:15 -0600 Subject: [PATCH 4/5] 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() { From 64cf82a06bc00531bdb8544dca100cafc87b212d Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 12 Nov 2010 16:21:03 -0800 Subject: [PATCH 5/5] Websocket server no longer fails hard on a bad cookie or a db reset --- script/websocket_server.rb | 40 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/script/websocket_server.rb b/script/websocket_server.rb index d72e5ea13..f8ea6d561 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -50,29 +50,39 @@ begin :port => APP_CONFIG[:socket_port], :debug =>APP_CONFIG[:socket_debug]) do |ws| ws.onopen { - debug_pp ws.request + begin + debug_pp ws.request - cookies = ws.request["Cookie"].split(';') - session_key = "_diaspora_session=" - enc_diaspora_cookie = cookies.detect{|c| c.include?(session_key)}.gsub(session_key,'') - cookie = Marshal.load(enc_diaspora_cookie.unpack("m*").first) + cookies = ws.request["Cookie"].split(';') + session_key = "_diaspora_session=" + enc_diaspora_cookie = cookies.detect{|c| c.include?(session_key)}.gsub(session_key,'') + cookie = Marshal.load(enc_diaspora_cookie.unpack("m*").first) - debug_pp cookie + debug_pp cookie - user_id = cookie["warden.user.user.key"].last - - debug_pp "In WSS, suscribing user: #{User.find(user_id).real_name} with id: #{user_id}" + user_id = cookie["warden.user.user.key"].last - sid = Diaspora::WebSocket.subscribe(user_id, ws) + debug_pp "In WSS, suscribing user: #{User.find(user_id).real_name} with id: #{user_id}" + sid = Diaspora::WebSocket.subscribe(user_id, ws) - ws.onmessage { |msg| SocketsController.new.incoming(msg) } + ws.onmessage { |msg| SocketsController.new.incoming(msg) } - ws.onclose { - debug_pp "In WSS, unsuscribing user: #{User.find(user_id).real_name} with id: #{user_id}" - Diaspora::WebSocket.unsubscribe(user_id, sid) } + ws.onclose { + begin + debug_pp "In WSS, unsuscribing user: #{User.find(user_id).real_name} with id: #{user_id}" + Diaspora::WebSocket.unsubscribe(user_id, sid) + rescue + debug_pp "Could not unsubscribe socket for #{user_id}" + end + } + rescue RuntimeError => e + debug_pp "Could not open socket for request with cookie: #{ws.request["Cookie"]}" + debug_pp "Error was: " + debug_pp e + end } end - PID_FILE = APP_CONFIG[:socket_pidfile] ? APP_CONFIG[:socket_pidfile] : 'tmp/diaspora-ws.pid' + PID_FILE = (APP_CONFIG[:socket_pidfile] ? APP_CONFIG[:socket_pidfile] : 'tmp/diaspora-ws.pid') write_pidfile puts "Websocket server started." process_message