Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
zhitomirskiyi 2010-11-12 16:34:23 -08:00
commit 9850783fd7
3 changed files with 77 additions and 20 deletions

View file

@ -83,9 +83,9 @@ var AspectEdit = {
var person_id = person.attr('data-guid'); var person_id = person.attr('data-guid');
if( $(".person[data-guid='"+ person_id +"']").length == 1) { if( $(".person[data-guid='"+ person_id +"']").length == 1) {
alert("You can not remove the person from the last aspect"); AspectEdit.alertUser("You cannot remove the person from the last aspect");
}
} else { else {
if (!person.hasClass('request')) { if (!person.hasClass('request')) {
$.ajax({ $.ajax({
@ -173,6 +173,10 @@ var AspectEdit = {
request_html.replace(/\d+/, old_request_count - 1) request_html.replace(/\d+/, old_request_count - 1)
); );
} }
},
alertUser: function(message) {
alert(message);
} }
}; };

View file

@ -43,8 +43,6 @@ end
begin begin
EM.run { EM.run {
Diaspora::WebSocket.initialize_channels Diaspora::WebSocket.initialize_channels
EventMachine::WebSocket.start( EventMachine::WebSocket.start(
@ -52,6 +50,7 @@ begin
:port => APP_CONFIG[:socket_port], :port => APP_CONFIG[:socket_port],
:debug =>APP_CONFIG[:socket_debug]) do |ws| :debug =>APP_CONFIG[:socket_debug]) do |ws|
ws.onopen { ws.onopen {
begin
debug_pp ws.request debug_pp ws.request
cookies = ws.request["Cookie"].split(';') cookies = ws.request["Cookie"].split(';')
@ -64,17 +63,26 @@ begin
user_id = cookie["warden.user.user.key"].last user_id = cookie["warden.user.user.key"].last
debug_pp "In WSS, suscribing user: #{User.find(user_id).real_name} with id: #{user_id}" debug_pp "In WSS, suscribing user: #{User.find(user_id).real_name} with id: #{user_id}"
sid = Diaspora::WebSocket.subscribe(user_id, ws) sid = Diaspora::WebSocket.subscribe(user_id, ws)
ws.onmessage { |msg| SocketsController.new.incoming(msg) } ws.onmessage { |msg| SocketsController.new.incoming(msg) }
ws.onclose { ws.onclose {
begin
debug_pp "In WSS, unsuscribing user: #{User.find(user_id).real_name} with id: #{user_id}" debug_pp "In WSS, unsuscribing user: #{User.find(user_id).real_name} with id: #{user_id}"
Diaspora::WebSocket.unsubscribe(user_id, sid) } 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 end
PID_FILE = APP_CONFIG[:socket_pidfile] PID_FILE = (APP_CONFIG[:socket_pidfile] ? APP_CONFIG[:socket_pidfile] : 'tmp/diaspora-ws.pid')
write_pidfile write_pidfile
puts "Websocket server started." puts "Websocket server started."
process_message process_message

View file

@ -171,6 +171,51 @@ describe("AspectEdit", function() {
}); });
}); });
describe("onDeleteRequestSuccess", function() {
beforeEach(function() {
$('#jasmine_content').html(
'<li class="person request ui-draggable" data-person_id="guid-of-friendship-requestor" data-guid="guid-of-friendship-requestor">' +
' <img alt="Alexander Hamiltom" class="avatar" data-person_id="guid-of-friendship-requestor" src="/images/user/default.png?1287542906" original-title="Alexander Hamiltom">' +
'</li>' +
'<ul data-aspect_id="guid-of-target-aspect" class="dropzone ui-droppable">' +
'</ul>' +
'<div class="new_requests">Requests (1)</div>'
);
});
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("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("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("decrementRequestsCounter", function() {
describe("when there is one request", function() { describe("when there is one request", function() {
it("removes the counter from the new requests div", function() { it("removes the counter from the new requests div", function() {