socket is now a controller
This commit is contained in:
parent
58ed75a289
commit
6293f9f585
7 changed files with 26 additions and 40 deletions
|
|
@ -5,7 +5,6 @@ class DashboardController < ApplicationController
|
|||
|
||||
def index
|
||||
@posts = Post.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
puts session.inspect
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,13 +19,8 @@ class SocketController < ApplicationController
|
|||
end
|
||||
|
||||
def outgoing(object)
|
||||
begin
|
||||
@_request = ActionDispatch::Request.new(:socket => true)
|
||||
@_request = ActionDispatch::Request.new({})
|
||||
WebSocket.push_to_clients(action_hash(object))
|
||||
rescue Exception => e
|
||||
puts e.inspect
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
def delete_subscriber(sid)
|
||||
|
|
|
|||
|
|
@ -1,26 +1,23 @@
|
|||
module SocketHelper
|
||||
include ApplicationHelper
|
||||
def obj_id(object)
|
||||
|
||||
def obj_id(object)
|
||||
(object.is_a? Post) ? object.id : object.post_id
|
||||
end
|
||||
|
||||
def url_options
|
||||
{:host => "", :only_path => true}
|
||||
{:host => ""}
|
||||
end
|
||||
|
||||
def action_hash(object)
|
||||
|
||||
begin
|
||||
v = render_to_string(:partial => type_partial(object), :locals => {:post => object}) unless object.is_a? Retraction
|
||||
|
||||
|
||||
rescue Exception => e
|
||||
puts "web socket view rendering failed for some reason." + 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)}.to_json
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ module WebSocket
|
|||
end
|
||||
|
||||
def self.push_to_clients(html)
|
||||
puts html
|
||||
@channel.push(html)
|
||||
end
|
||||
|
||||
|
|
@ -37,7 +36,7 @@ module WebSocket
|
|||
|
||||
|
||||
def self.subscribe
|
||||
@channel.subscribe{ |msg| puts @ws.inspect; puts "ehllo" ; @ws.send msg }
|
||||
@channel.subscribe{ |msg| @ws.send msg }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,23 +1,18 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
#require 'em-spec/rspec'
|
||||
describe SocketController do
|
||||
render_views
|
||||
|
||||
describe 'SocketController' do
|
||||
render_views
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
WebSocket.unstub!(:push_to_clients)
|
||||
WebSocket.unstub!(:unsubscribe)
|
||||
WebSocket.unstub!(:subscribe)
|
||||
SocketController.unstub!(:new)
|
||||
#EventMachine::WebSocket.stub!(:start)
|
||||
@controller = SocketController.new
|
||||
stub_socket_controller
|
||||
end
|
||||
|
||||
it 'should unstub the websocket' do
|
||||
WebSocket.initialize_channel
|
||||
WebSocket.push_to_clients("what").should_not == "stub"
|
||||
WebSocket.unsubscribe(1).should_not == "stub"
|
||||
WebSocket.subscribe.should_not == "stub"
|
||||
@controller.class.should == SocketController
|
||||
end
|
||||
|
||||
it 'should add a new subscriber to the websocket channel' do
|
||||
|
|
@ -30,16 +25,16 @@ describe SocketController do
|
|||
end
|
||||
|
||||
it 'should actionhash posts' do
|
||||
hash = @controller.action_hash(@message)
|
||||
hash[:html].include?(@message.message).should be_true
|
||||
hash[:class].include?('status_message').should be_true
|
||||
json = @controller.action_hash(@message)
|
||||
json.include?(@message.message).should be_true
|
||||
json.include?('status_message').should be_true
|
||||
end
|
||||
|
||||
it 'should actionhash retractions' do
|
||||
retraction = Retraction.for @message
|
||||
hash = @controller.action_hash(retraction)
|
||||
hash[:class].include?('retraction').should be_true
|
||||
hash[:html].should be_nil
|
||||
json = @controller.action_hash(retraction)
|
||||
json.include?('retraction').should be_true
|
||||
json.include?("html\":null").should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ describe MessageHandler do
|
|||
@handler = MessageHandler.new
|
||||
@message_body = "I want to pump you up"
|
||||
@message_urls = ["http://www.google.com/", "http://yahoo.com/", "http://foo.com/"]
|
||||
|
||||
end
|
||||
|
||||
describe 'GET messages' do
|
||||
|
|
|
|||
|
|
@ -24,15 +24,7 @@ RSpec.configure do |config|
|
|||
|
||||
config.before(:each) do
|
||||
DatabaseCleaner.start
|
||||
SocketController.stub!(:incoming).and_return(true)
|
||||
SocketController.stub!(:new_subscriber).and_return(true)
|
||||
SocketController.stub!(:outgoing).and_return(true)
|
||||
SocketController.stub!(:delete_subscriber).and_return(true)
|
||||
|
||||
|
||||
WebSocket.stub!(:push_to_clients).and_return("stub")
|
||||
WebSocket.stub!(:unsubscribe).and_return("stub")
|
||||
WebSocket.stub!(:subscribe).and_return("stub")
|
||||
stub_socket_controller
|
||||
end
|
||||
|
||||
config.after(:each) do
|
||||
|
|
@ -40,3 +32,11 @@ RSpec.configure do |config|
|
|||
end
|
||||
|
||||
end
|
||||
def stub_socket_controller
|
||||
mock_socket_controller = mock('socket mock')
|
||||
mock_socket_controller.stub!(:incoming).and_return(true)
|
||||
mock_socket_controller.stub!(:new_subscriber).and_return(true)
|
||||
mock_socket_controller.stub!(:outgoing).and_return(true)
|
||||
mock_socket_controller.stub!(:delete_subscriber).and_return(true)
|
||||
SocketController.stub!(:new).and_return(mock_socket_controller)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue