broken autotest for rafi

This commit is contained in:
maxwell 2010-07-07 15:27:22 -07:00
parent 9c779d64fd
commit 5350b40e3c
8 changed files with 79 additions and 62 deletions

View file

@ -36,6 +36,6 @@ class Comment
def send_to_view
WebSocket.update_clients(self)
WebSocket.push_to_clients(self)
end
end

View file

@ -53,11 +53,11 @@ class Post
end
def send_to_view
WebSocket.update_clients(self)
WebSocket.push_to_clients(self)
end
def remove_from_view
WebSocket.update_clients(Retraction.for(self))
WebSocket.push_to_clients(Retraction.for(self))
end
end

View file

@ -7,5 +7,5 @@
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
inflect.uncountable %w(dashboard)
inflect.uncountable %w(dashboard socket)
end

View file

@ -1,31 +1,44 @@
require 'em-websocket'
require 'eventmachine'
require 'lib/socket_render'
module WebSocket
EM.next_tick {
EM.add_timer(0.1) do
@channel = EM::Channel.new
puts @channel.inspect
include SocketRenderer
SocketRenderer.instantiate_view
end
initialize_channel
EventMachine::WebSocket.start(
:host => "0.0.0.0",
:port => APP_CONFIG[:socket_port],
:debug =>APP_CONFIG[:debug]) do |ws|
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
}
def self.update_clients(object)
@channel.push(SocketRenderer.view_hash(object).to_json) if @channel
def self.initialize_channel
@channel = EM::Channel.new
puts @channel.inspect
end
def self.push_to_clients(html)
@channel.push(html)
end
def self.unsubscribe(sid)
@channel.unsubscribe(sid)
end
def self.subscribe
@channel.subscribe{ |msg| puts "hello #{msg}";@ws.send msg }
end
end

View file

@ -1,40 +1,40 @@
module SocketRenderer
require 'app/helpers/application_helper'
def self.instantiate_view
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << @view
include ApplicationHelper
include Rails.application.routes.url_helpers
include ActionController::RequestForgeryProtection::ClassMethods
def protect_against_forgery?
false
end
end
end
def self.view_hash(object)
begin
v = view_for(object) unless object.is_a? Retraction
rescue Exception => e
puts "in failzord " + v.inspect
puts object.inspect
puts e.message
raise e
end
{:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
end
def self.view_for(object)
@view.render @view.type_partial(object), :post => object
end
def self.obj_id(object)
if object.is_a? Post
object.id
else
object.post_id
end
end
end
# module SocketRenderer
# require 'app/helpers/application_helper'
# def self.instantiate_view
# @view = ActionView::Base.new(ActionController::Base.view_paths, {})
# class << @view
# include ApplicationHelper
# include Rails.application.routes.url_helpers
# include ActionController::RequestForgeryProtection::ClassMethods
# def protect_against_forgery?
# false
# end
# end
# end
#
# def self.view_hash(object)
# begin
# v = view_for(object) unless object.is_a? Retraction
#
# rescue Exception => e
# puts "in failzord " + v.inspect
# puts object.inspect
# puts e.message
# raise e
# end
#
# {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
# end
#
# def self.view_for(object)
# @view.render @view.type_partial(object), :post => object
# end
#
# def self.obj_id(object)
# if object.is_a? Post
# object.id
# else
# object.post_id
# end
# end
# end

View file

@ -105,10 +105,10 @@ describe MessageHandler do
@handler.add_get_request(@message_urls)
@handler.size.should == 6
@handler.process
timer = EventMachine::Timer.new(1) do
#timer = EventMachine::Timer.new(1) do
@handler.size.should == 0
EventMachine.stop
end
#end
}
end

View file

@ -1,3 +1,4 @@
=begin
require File.dirname(__FILE__) + '/../spec_helper'
describe SocketRenderer do
@ -21,3 +22,4 @@ describe SocketRenderer do
end
end
=end

View file

@ -24,7 +24,9 @@ RSpec.configure do |config|
config.before(:each) do
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
config.after(:each) do