broken autotest for rafi
This commit is contained in:
parent
9c779d64fd
commit
5350b40e3c
8 changed files with 79 additions and 62 deletions
|
|
@ -36,6 +36,6 @@ class Comment
|
||||||
|
|
||||||
|
|
||||||
def send_to_view
|
def send_to_view
|
||||||
WebSocket.update_clients(self)
|
WebSocket.push_to_clients(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -53,11 +53,11 @@ class Post
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_to_view
|
def send_to_view
|
||||||
WebSocket.update_clients(self)
|
WebSocket.push_to_clients(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_from_view
|
def remove_from_view
|
||||||
WebSocket.update_clients(Retraction.for(self))
|
WebSocket.push_to_clients(Retraction.for(self))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,5 @@
|
||||||
# inflect.singular /^(ox)en/i, '\1'
|
# inflect.singular /^(ox)en/i, '\1'
|
||||||
# inflect.irregular 'person', 'people'
|
# inflect.irregular 'person', 'people'
|
||||||
# inflect.uncountable %w( fish sheep )
|
# inflect.uncountable %w( fish sheep )
|
||||||
inflect.uncountable %w(dashboard)
|
inflect.uncountable %w(dashboard socket)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,44 @@
|
||||||
require 'em-websocket'
|
require 'em-websocket'
|
||||||
require 'eventmachine'
|
require 'eventmachine'
|
||||||
require 'lib/socket_render'
|
|
||||||
|
|
||||||
|
|
||||||
module WebSocket
|
module WebSocket
|
||||||
EM.next_tick {
|
EM.next_tick {
|
||||||
EM.add_timer(0.1) do
|
initialize_channel
|
||||||
@channel = EM::Channel.new
|
|
||||||
puts @channel.inspect
|
|
||||||
include SocketRenderer
|
|
||||||
|
|
||||||
SocketRenderer.instantiate_view
|
|
||||||
end
|
|
||||||
|
|
||||||
EventMachine::WebSocket.start(
|
EventMachine::WebSocket.start(
|
||||||
:host => "0.0.0.0",
|
:host => "0.0.0.0",
|
||||||
:port => APP_CONFIG[:socket_port],
|
:port => APP_CONFIG[:socket_port],
|
||||||
:debug =>APP_CONFIG[:debug]) do |ws|
|
:debug =>APP_CONFIG[:debug]) do |ws|
|
||||||
ws.onopen {
|
ws.onopen {
|
||||||
sid = @channel.subscribe { |msg| ws.send msg }
|
@ws = ws
|
||||||
|
sid = SocketController.new.new_subscriber(ws)
|
||||||
|
|
||||||
ws.onmessage { |msg| }#@channel.push msg; puts msg}
|
ws.onmessage { |msg| SocketController.new.incoming(msg) }#@channel.push msg; puts msg}
|
||||||
|
|
||||||
ws.onclose { @channel.unsubscribe(sid) }
|
ws.onclose { SocketController.new.delete_subscriber(sid) }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.update_clients(object)
|
def self.initialize_channel
|
||||||
@channel.push(SocketRenderer.view_hash(object).to_json) if @channel
|
@channel = EM::Channel.new
|
||||||
|
puts @channel.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.push_to_clients(html)
|
||||||
|
@channel.push(html)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.unsubscribe(sid)
|
||||||
|
@channel.unsubscribe(sid)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def self.subscribe
|
||||||
|
@channel.subscribe{ |msg| puts "hello #{msg}";@ws.send msg }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,40 @@
|
||||||
module SocketRenderer
|
# module SocketRenderer
|
||||||
require 'app/helpers/application_helper'
|
# require 'app/helpers/application_helper'
|
||||||
def self.instantiate_view
|
# def self.instantiate_view
|
||||||
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
# @view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
||||||
class << @view
|
# class << @view
|
||||||
include ApplicationHelper
|
# include ApplicationHelper
|
||||||
include Rails.application.routes.url_helpers
|
# include Rails.application.routes.url_helpers
|
||||||
include ActionController::RequestForgeryProtection::ClassMethods
|
# include ActionController::RequestForgeryProtection::ClassMethods
|
||||||
def protect_against_forgery?
|
# def protect_against_forgery?
|
||||||
false
|
# false
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def self.view_hash(object)
|
# def self.view_hash(object)
|
||||||
begin
|
# begin
|
||||||
v = view_for(object) unless object.is_a? Retraction
|
# v = view_for(object) unless object.is_a? Retraction
|
||||||
|
#
|
||||||
rescue Exception => e
|
# rescue Exception => e
|
||||||
puts "in failzord " + v.inspect
|
# puts "in failzord " + v.inspect
|
||||||
puts object.inspect
|
# puts object.inspect
|
||||||
puts e.message
|
# puts e.message
|
||||||
raise e
|
# raise e
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
{:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
|
# {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def self.view_for(object)
|
# def self.view_for(object)
|
||||||
@view.render @view.type_partial(object), :post => object
|
# @view.render @view.type_partial(object), :post => object
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def self.obj_id(object)
|
# def self.obj_id(object)
|
||||||
if object.is_a? Post
|
# if object.is_a? Post
|
||||||
object.id
|
# object.id
|
||||||
else
|
# else
|
||||||
object.post_id
|
# object.post_id
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
|
||||||
|
|
@ -105,10 +105,10 @@ describe MessageHandler do
|
||||||
@handler.add_get_request(@message_urls)
|
@handler.add_get_request(@message_urls)
|
||||||
@handler.size.should == 6
|
@handler.size.should == 6
|
||||||
@handler.process
|
@handler.process
|
||||||
timer = EventMachine::Timer.new(1) do
|
#timer = EventMachine::Timer.new(1) do
|
||||||
@handler.size.should == 0
|
@handler.size.should == 0
|
||||||
EventMachine.stop
|
EventMachine.stop
|
||||||
end
|
#end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
=begin
|
||||||
require File.dirname(__FILE__) + '/../spec_helper'
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
describe SocketRenderer do
|
describe SocketRenderer do
|
||||||
|
|
@ -21,3 +22,4 @@ describe SocketRenderer do
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,9 @@ RSpec.configure do |config|
|
||||||
|
|
||||||
config.before(:each) do
|
config.before(:each) do
|
||||||
DatabaseCleaner.start
|
DatabaseCleaner.start
|
||||||
#WebSocket.stub!(:update_clients)
|
WebSocket.stub!(:push_to_clients).and_return("stub")
|
||||||
|
WebSocket.stub!(:unsubscribe).and_return("stub")
|
||||||
|
WebSocket.stub!(:subscribe).and_return("stub")
|
||||||
end
|
end
|
||||||
|
|
||||||
config.after(:each) do
|
config.after(:each) do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue